diff --git a/build.gradle.kts b/build.gradle.kts index a4e68b9..148b5af 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,28 +1,28 @@ -@file:Suppress("SpellCheckingInspection", "UnstableApiUsage") +@file:Suppress("SpellCheckingInspection", "UnstableApiUsage", "RedundantNullableReturnType") +import net.fabricmc.loom.util.ModPlatform import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - kotlin("jvm") version "2.0.0" - kotlin("plugin.serialization") version "2.0.0" - id("fabric-loom") version "1.7-SNAPSHOT" - - id("me.modmuss50.mod-publish-plugin") version "0.5.+" + alias(libs.plugins.kotlin) + alias(libs.plugins.kotlinx.serialization) + alias(libs.plugins.architectury.loom) + alias(libs.plugins.mod.publish) `maven-publish` - signing } -val beta: Int? = null // Pattern is '1.0.0-beta1-1.20.6-pre.2' -val featureVersion = "2.2.0${if (beta != null) "-beta$beta" else ""}" -val mcVersion = property("mcVersion")!!.toString() -val mcVersionRange = property("mcVersionRange")!!.toString() -version = "$featureVersion-$mcVersion" +val loader = loom.platform.get() +val isFabric = loader == ModPlatform.FABRIC + +val beta: Int = property("mod.beta").toString().toInt() +val majorVersion: String = property("mod.major-version").toString() +val mcVersion = property("vers.mcVersion").toString() // Pattern is '1.0.0-beta1-1.20.6-pre.2+fabric' +version = "$majorVersion${if (beta != 0) "-beta$beta" else ""}-$mcVersion+${loader.name.lowercase()}" -group = "dev.nyon" -val authors = listOf("btwonion") -val githubRepo = "btwonion/better-boat-movement" +group = property("mod.group").toString() +val githubRepo = property("mod.repo").toString() base { archivesName.set(rootProject.name) @@ -37,57 +37,92 @@ loom { } mixin { useLegacyMixinAp = false } + silentMojangMappingsLicense() } repositories { mavenCentral() maven("https://maven.terraformersmc.com") - maven("https://maven.parchmentmc.org") + maven("https://maven.quiltmc.org/repository/release/") maven("https://repo.nyon.dev/releases") maven("https://maven.isxander.dev/releases") - maven("https://oss.sonatype.org/content/repositories/snapshots/") + maven("https://thedarkcolour.github.io/KotlinForForge/") + maven("https://maven.neoforged.net/releases/") } +val yaclVersion = property("vers.deps.yacl").toString() +val flk: String = "${libs.versions.fabric.language.kotlin.orNull}${libs.versions.kotlin.orNull}" +val fapi: String by lazy { property("vers.deps.fapi").toString() } +val modmenu: String by lazy { property("vers.deps.modMenu").toString() } dependencies { minecraft("com.mojang:minecraft:$mcVersion") mappings(loom.layered { - val parchment: String = property("deps.parchment").toString() - if (parchment.isNotEmpty()) parchment("org.parchmentmc.data:parchment-$parchment@zip") + val quiltMappings: String = property("vers.deps.quiltmappings").toString() + if (quiltMappings.isNotEmpty()) mappings("org.quiltmc:quilt-mappings:$quiltMappings:intermediary-v2") officialMojangMappings() }) - implementation("org.vineflower:vineflower:1.10.1") - modImplementation("net.fabricmc:fabric-loader:0.16.0") - modImplementation("net.fabricmc.fabric-api:fabric-api:${property("deps.fapi")!!}") - modImplementation("net.fabricmc:fabric-language-kotlin:1.11.0+kotlin.2.0.0") + implementation(libs.vineflower) + + if (isFabric) { + implementation(libs.fabric.loader) + modImplementation("net.fabricmc.fabric-api:fabric-api:$fapi") + modImplementation("net.fabricmc:fabric-language-kotlin:$flk") + modImplementation("com.terraformersmc:modmenu:$modmenu") + } else { + if (loader == ModPlatform.FORGE) { + "forge"("net.minecraftforge:forge:$mcVersion-${property("vers.deps.fml")}") + compileOnly(libs.mixinextras.common) + annotationProcessor(libs.mixinextras.common) + include(libs.mixinextras.forge) + implementation(libs.mixinextras.forge) + } else + "neoForge"("net.neoforged:neoforge:${property("vers.deps.fml")}") + implementation("thedarkcolour:kotlinforforge${if (loader == ModPlatform.NEOFORGE) "-neoforge" else ""}:${property("vers.deps.kff")}") + } - modImplementation("dev.isxander:yet-another-config-lib:${property("deps.yacl")!!}") - modImplementation("com.terraformersmc:modmenu:${property("deps.modMenu")!!}") + modImplementation("dev.isxander:yet-another-config-lib:$yaclVersion") - include(modImplementation("dev.nyon:konfig:2.0.1-1.20.4")!!) + modImplementation(libs.konfig) + include(libs.konfig) } -val javaVersion = property("javaVer")!!.toString() +val javaVersion = property("vers.javaVer").toString() +val modId = property("mod.id").toString() +val modName = property("mod.name").toString() +val modDescription = property("mod.description").toString() +val mcVersionRange = property("vers.mcVersionRange").toString() +val icon = property("mod.icon").toString() +val mixinsFile = property("mod.mixins").toString() +val slug = property("mod.slug").toString() tasks { processResources { - val modId = "better-boat-movement" - val modName = "BetterBoatMovement" - val modDescription = "Increases boat step height to move up water and blocks" - - val props = - mapOf( - "id" to modId, - "name" to modName, - "description" to modDescription, - "version" to project.version, - "github" to githubRepo, - "mc" to mcVersionRange - ) + val props: Map = mapOf( + "id" to modId, + "name" to modName, + "description" to modDescription, + "version" to project.version.toString(), + "github" to githubRepo, + "mc" to mcVersionRange, + "flk" to if (!isFabric) null else flk, + "fapi" to if (!isFabric) null else fapi, + "yacl" to yaclVersion, + "modmenu" to if (!isFabric) null else modmenu, + "repo" to githubRepo, + "icon" to icon, + "mixins" to mixinsFile, + "slug" to slug + ).filterNot { it.value == null } props.forEach(inputs::property) - filesMatching("fabric.mod.json") { - expand(props) + (if (isFabric) listOf("fabric.mod.json") else listOf( + "META-INF/mods.toml", + "META-INF/neoforge.mods.toml" + )).forEach { filesMatching(it) { expand(props) } } + + filesMatching("pack.mcmeta") { + if (isFabric) exclude() } } @@ -111,33 +146,45 @@ tasks { val changelogText = buildString { append("# v${project.version}\n") - rootProject.file("changelog.md").readText().also(::append) + if (beta != 0) appendLine("### As this is still a beta version, this version can contain bugs. Feel free to report ANY misbehaviours and errors!") + rootDir.resolve("changelog.md").readText().also(::append) } -val supportedMcVersions: List = property("supportedMcVersions")!!.toString().split(',').map(String::trim).filter(String::isNotEmpty) +val supportedMcVersions: List = + property("vers.supportedMcVersions")!!.toString().split(',').map(String::trim).filter(String::isNotEmpty) publishMods { displayName = "v${project.version}" file = tasks.remapJar.get().archiveFile changelog = changelogText - type = if (beta != null) BETA else STABLE - modLoaders.addAll("fabric", "quilt") + type = if (beta != 0) BETA else STABLE + when (loader) { + ModPlatform.FABRIC -> modLoaders.addAll("fabric", "quilt") + ModPlatform.FORGE -> modLoaders.addAll("forge") + ModPlatform.NEOFORGE -> modLoaders.addAll("neoforge") + else -> {} + } modrinth { projectId = "wTfH1dkt" accessToken = providers.environmentVariable("MODRINTH_API_KEY") minecraftVersions.addAll(supportedMcVersions) - requires { slug = "fabric-api" } + if (isFabric) { + requires { slug = "fabric-api" } + requires { slug = "fabric-language-kotlin" } + optional { slug = "modmenu" } + } else { + requires { slug = "kotlin-for-forge" } + } + requires { slug = "yacl" } - requires { slug = "fabric-language-kotlin" } - optional { slug = "modmenu" } } github { repository = githubRepo accessToken = providers.environmentVariable("GITHUB_TOKEN") - commitish = "master" + commitish = property("mod.main-branch").toString() } } @@ -155,7 +202,7 @@ publishing { publications { create("maven") { groupId = "dev.nyon" - artifactId = "better-boat-movement" + artifactId = modName version = project.version.toString() from(components["java"]) } @@ -170,15 +217,3 @@ java { targetCompatibility = it } } - -/* -signing { - val signingKey: String? by project - val signingPassword: String? by project - useGpgCmd() - if (signingKey != null && signingPassword != null) { - useInMemoryPgpKeys(signingKey, signingPassword) - } - sign(publishing.publications) -} - */ diff --git a/changelog.md b/changelog.md index 77e37e8..8a8f5e8 100644 --- a/changelog.md +++ b/changelog.md @@ -1 +1,2 @@ -- add traditional chinese translation +- add forge and neoforge support +- change modid from better-boat-movement to bbm \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index bf86fb7..52debea 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1,17 @@ -org.gradle.jvmargs=-Xmx2G \ No newline at end of file +kotlin.code.style=official +org.gradle.jvmargs=-Xmx4096M + +mod.main-branch=master +mod.color=109249364 +mod.icon=assets/bbm/icon/icon.png +mod.icon-url=https://github.com/btwonion/better-boat-movement/blob/master/src/main/resources/assets/bbm/icon/icon.png +mod.group=dev.nyon +mod.repo=btwonion/better-boat-movement +mod.slug=better-boat-movement +mod.id=bbm +mod.name=BetterBoatMovement +mod.description=Increases boat step height to move up water and blocks +mod.beta=0 +mod.major-version=2.2.1 +mod.mixins=bbm.mixins.json +mod.supported-loaders=fabric,quilt,neoforge,forge \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..4d4f57c --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,22 @@ +[versions] +kotlin = "2.0.20" +mod-publish = "0.5.+" +architectury-loom = "1.7-SNAPSHOT" +fabric-loader = "0.16.4" +fabric-language-kotlin = "1.12.1+kotlin." +vineflower = "1.10.1" +konfig = "2.0.2-1.20.4" +mixinextras = "0.4.1" + +[libraries] +vineflower = { module = "org.vineflower:vineflower", version.ref = "vineflower" } +konfig = { module = "dev.nyon:konfig", version.ref = "konfig" } +fabric-loader = { module = "net.fabricmc:fabric-loader", version.ref = "fabric-loader" } +mixinextras-common = { module = "io.github.llamalad7:mixinextras-common", version.ref = "mixinextras" } +mixinextras-forge = { module = "io.github.llamalad7:mixinextras-forge", version.ref = "mixinextras" } + +[plugins] +kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } +architectury-loom = { id = "dev.architectury.loom", version.ref = "architectury-loom" } +mod-publish = { id = "me.modmuss50.mod-publish-plugin", version.ref = "mod-publish" } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a441313..0aaefbc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/settings.gradle.kts b/settings.gradle.kts index 68e9ab4..f75b869 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -7,19 +7,21 @@ pluginManagement { mavenCentral() gradlePluginPortal() maven("https://maven.fabricmc.net/") - maven("https://server.bbkr.space/artifactory/libs-release/") + maven("https://maven.architectury.dev") + maven("https://maven.minecraftforge.net") + maven("https://maven.neoforged.net/releases/") maven("https://maven.kikugie.dev/releases") } } plugins { - id("dev.kikugie.stonecutter") version "0.4" + id("dev.kikugie.stonecutter") version "0.4.+" } buildscript { repositories { mavenCentral() } dependencies { - classpath("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0-RC") + classpath("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1") } } @@ -27,8 +29,15 @@ extensions.configure { kotlinController = true centralScript = "build.gradle.kts" shared { - versions("1.20.1", "1.20.4", "1.20.6", "1.21") - vcsVersion = "1.21" + vers("1.20.1-forge", "1.20.1") + vers("1.20.1-fabric", "1.20.1") + vers("1.20.4-neoforge", "1.20.4") + vers("1.20.4-fabric", "1.20.4") + vers("1.20.6-neoforge", "1.20.6") + vers("1.20.6-fabric", "1.20.6") + vers("1.21-neoforge", "1.21") + vers("1.21-fabric", "1.21") + vcsVersion = "1.21-fabric" } create(rootProject) } diff --git a/src/main/java/dev/nyon/bbm/asm/MinecraftMixin.java b/src/main/java/dev/nyon/bbm/asm/MinecraftMixin.java index 659b14a..ee25cb4 100644 --- a/src/main/java/dev/nyon/bbm/asm/MinecraftMixin.java +++ b/src/main/java/dev/nyon/bbm/asm/MinecraftMixin.java @@ -1,6 +1,6 @@ package dev.nyon.bbm.asm; -import dev.nyon.bbm.BetterBoatMovement; +import dev.nyon.bbm.config.ConfigKt; import net.minecraft.client.Minecraft; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -15,6 +15,6 @@ public class MinecraftMixin { at = @At("TAIL") ) private void saveConfig(CallbackInfo ci) { - BetterBoatMovement.INSTANCE.saveConfig(); + ConfigKt.saveConfig(); } } diff --git a/src/main/kotlin/dev/nyon/bbm/BetterBoatMovementEntrypoint.kt b/src/main/kotlin/dev/nyon/bbm/BetterBoatMovementEntrypoint.kt new file mode 100644 index 0000000..1fa47e8 --- /dev/null +++ b/src/main/kotlin/dev/nyon/bbm/BetterBoatMovementEntrypoint.kt @@ -0,0 +1,194 @@ +package dev.nyon.bbm + +import dev.nyon.bbm.config.Config +import dev.nyon.bbm.config.migrate +import dev.nyon.bbm.config.serverConfig +import dev.nyon.konfig.config.config +import dev.nyon.konfig.config.loadConfig +import java.nio.file.Path + +/*? if fabric {*/ +import net.fabricmc.api.ModInitializer +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking +//? if >=1.20.5 +import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry +import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking +import net.fabricmc.loader.api.FabricLoader +import net.fabricmc.api.EnvType + +object BetterBoatMovementEntrypoint : ModInitializer { + override fun onInitialize() { + instantiateConfig(FabricLoader.getInstance().configDir.resolve("better-boat-movement.json")) + //? if >=1.20.5 + PayloadTypeRegistry.playS2C().register(Config.packetType, Config.codec) + when (FabricLoader.getInstance().environmentType) { + EnvType.CLIENT -> { + /*? if <1.20.5 {*//*ClientPlayNetworking.registerGlobalReceiver(Config.packetType.id) { _, _, buf, _ -> + serverConfig = Config.packetType.read(buf) + } + *//*?} else {*/ + ClientPlayConnectionEvents.INIT.register { _, _ -> + ClientPlayNetworking.registerReceiver(Config.packetType) { packet, _ -> + serverConfig = packet + } + }/*?}*/ + + ClientPlayConnectionEvents.DISCONNECT.register { _, _ -> + serverConfig = null + } + } + EnvType.SERVER -> { + serverConfig = dev.nyon.bbm.config.config + + ServerPlayConnectionEvents.INIT.register { handler, _ -> + ServerPlayNetworking.send(handler.player, dev.nyon.bbm.config.config) + } + } + else -> {} + } + } +} + +/*?} else if neoforge {*/ +/*import dev.nyon.bbm.config.generateYaclScreen +import net.minecraft.server.level.ServerPlayer +import net.neoforged.api.distmarker.Dist +import net.neoforged.fml.ModLoadingContext +import net.neoforged.fml.common.Mod +import net.neoforged.fml.loading.FMLLoader +import net.neoforged.neoforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent +import net.neoforged.neoforge.event.entity.player.PlayerEvent.PlayerLoggedOutEvent +import net.neoforged.neoforge.network.PacketDistributor +import thedarkcolour.kotlinforforge.neoforge.forge.DIST +import thedarkcolour.kotlinforforge.neoforge.forge.FORGE_BUS + +/^? if >=1.20.5 {^/ +/^import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent +import net.neoforged.neoforge.network.handling.DirectionalPayloadHandler^/ +/^?} else {^/ +import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent +import net.minecraft.network.FriendlyByteBuf +/^?}^/ +import thedarkcolour.kotlinforforge.neoforge.forge.MOD_BUS + +typealias CSF = /^? if <1.20.5 {^/ net.neoforged.neoforge.client.ConfigScreenHandler.ConfigScreenFactory /^?} else {^/ /^net.neoforged.neoforge.client.gui.IConfigScreenFactory ^//^?}^/ + +@Mod("bbm") +object BetterBoatMovementEntrypoint { + init { + instantiateConfig(FMLLoader.getGamePath().resolve("config/better-boat-movement.json")) + + /^? if >=1.20.5 {^/ + /^MOD_BUS.addListener { event -> + val registrar = event.registrar("3") + registrar.playToClient(Config.packetType, Config.codec, DirectionalPayloadHandler( + { config, _ -> + serverConfig = config + }, { _, _ -> } + )) + } + ^//^?} else {^/ + MOD_BUS.addListener { event -> + val registrar = event.registrar("3") + registrar.play(Config.identifier, FriendlyByteBuf.Reader{ buf -> Config(buf) }) { handler -> + handler.client { config, _ -> serverConfig = config }.server { _, _ -> } + } + } + /^?}^/ + + + when (DIST) { + Dist.DEDICATED_SERVER -> { + serverConfig = dev.nyon.bbm.config.config + FORGE_BUS.addListener { event -> + val player = event.entity + if (player !is ServerPlayer) return@addListener + /^? if >=1.20.5 {^/ /^PacketDistributor.sendToPlayer(player, serverConfig!!) + ^//^?} else {^/ PacketDistributor.PLAYER.with(player).send(serverConfig) /^?}^/ + } + } + + Dist.CLIENT -> { + FORGE_BUS.addListener { + serverConfig = null + } + } + else -> {} + } + + ModLoadingContext.get().registerExtensionPoint(CSF::class.java) { + CSF { _, parent -> generateYaclScreen(parent) } + } + } +} +*//*?} else {*/ +/*import dev.nyon.bbm.config.generateYaclScreen +import dev.nyon.bbm.extensions.resourceLocation +import net.minecraft.server.level.ServerPlayer +import net.minecraftforge.api.distmarker.Dist +import net.minecraftforge.client.ConfigScreenHandler.ConfigScreenFactory +import net.minecraftforge.event.entity.player.PlayerEvent +import net.minecraftforge.fml.ModLoadingContext +import net.minecraftforge.fml.common.Mod +import net.minecraftforge.fml.loading.FMLLoader +import net.minecraftforge.network.NetworkDirection +import net.minecraftforge.network.NetworkRegistry +import net.minecraftforge.network.PacketDistributor +import thedarkcolour.kotlinforforge.forge.DIST +import thedarkcolour.kotlinforforge.forge.FORGE_BUS +import java.util.* + +@Mod("bbm") +object BetterBoatMovementEntrypoint { + init { + instantiateConfig(FMLLoader.getGamePath().resolve("config/better-boat-movement.json")) + + val channel = NetworkRegistry.newSimpleChannel(resourceLocation("better-boat-movement:channel"), { "1" }, { true }, { true }) + channel.registerMessage( + 0, + Config::class.java, + { config, buf -> config.write(buf) }, + { buf -> Config(buf) }, + { config, context -> + serverConfig = config + context.get().packetHandled = true + }, + Optional.of(NetworkDirection.PLAY_TO_CLIENT) + ) + + when (DIST) { + Dist.DEDICATED_SERVER -> { + serverConfig = dev.nyon.bbm.config.config + FORGE_BUS.addListener { event -> + val player = event.entity + if (player !is ServerPlayer) return@addListener + channel.send(PacketDistributor.PLAYER.with { player }, serverConfig) + } + } + + Dist.CLIENT -> { + FORGE_BUS.addListener { + serverConfig = null + } + } + + else -> {} + } + + ModLoadingContext.get().registerExtensionPoint(ConfigScreenFactory::class.java) { + ConfigScreenFactory { _, parent -> generateYaclScreen(parent) } + } + } +} +*//*?}*/ + +private fun instantiateConfig(path: Path) { + config( + path, + 3, + Config() + ) { element, version -> migrate(element, version) } + dev.nyon.bbm.config.config = loadConfig() +} \ No newline at end of file diff --git a/src/main/kotlin/dev/nyon/bbm/config/Config.kt b/src/main/kotlin/dev/nyon/bbm/config/Config.kt index 206f34c..b03396b 100644 --- a/src/main/kotlin/dev/nyon/bbm/config/Config.kt +++ b/src/main/kotlin/dev/nyon/bbm/config/Config.kt @@ -1,17 +1,67 @@ package dev.nyon.bbm.config import dev.nyon.bbm.extensions.resourceLocation -import dev.nyon.bbm.serverConfig import kotlinx.serialization.Serializable import kotlinx.serialization.Transient import kotlinx.serialization.json.* -import net.fabricmc.api.EnvType -import net.fabricmc.loader.api.FabricLoader import net.minecraft.client.Minecraft import net.minecraft.network.FriendlyByteBuf -/*? if <1.20.6 {*/ -/*import net.fabricmc.fabric.api.networking.v1.FabricPacket +/*? if >=1.20.5 {*/ +import net.minecraft.network.codec.StreamCodec +import net.minecraft.network.protocol.common.custom.CustomPacketPayload + +@Serializable +data class Config( + var stepHeight: Float = 0.35f, + var playerEjectTicks: Float = 20f * 10f, + var boostUnderwater: Boolean = true, + var boostOnBlocks: Boolean = true, + var boostOnIce: Boolean = true, + var boostOnWater: Boolean = true, + var onlyForPlayers: Boolean = true +) : CustomPacketPayload { + companion object { + @Transient + val packetType: CustomPacketPayload.Type = CustomPacketPayload.Type(resourceLocation("better-boat-movement:sync")!!) + + @Transient + @Suppress("unused") + val codec = + object : StreamCodec { + override fun decode(buf: FriendlyByteBuf): Config { + return Config( + buf.readFloat(), + buf.readFloat(), + buf.readBoolean(), + buf.readBoolean(), + buf.readBoolean(), + buf.readBoolean(), + buf.readBoolean() + ) + } + + override fun encode( + buf: FriendlyByteBuf, + config: Config + ) { + buf.writeFloat(config.stepHeight) + buf.writeFloat(config.playerEjectTicks) + buf.writeBoolean(config.boostUnderwater) + buf.writeBoolean(config.boostOnBlocks) + buf.writeBoolean(config.boostOnIce) + buf.writeBoolean(config.boostOnWater) + buf.writeBoolean(config.onlyForPlayers) + } + } + } + + override fun type(): CustomPacketPayload.Type { + return packetType + } +} +/*?} else if fabric {*//* +import net.fabricmc.fabric.api.networking.v1.FabricPacket import net.fabricmc.fabric.api.networking.v1.PacketType @Serializable @@ -55,9 +105,9 @@ data class Config( return packetType } } -*//*?} else {*/ -import net.minecraft.network.codec.StreamCodec -import net.minecraft.network.protocol.common.custom.CustomPacketPayload +*//*?} else if neoforge {*/ +/*import net.minecraft.network.protocol.common.custom.CustomPacketPayload +import net.minecraft.resources.ResourceLocation @Serializable data class Config( @@ -71,49 +121,75 @@ data class Config( ) : CustomPacketPayload { companion object { @Transient - val packetType: CustomPacketPayload.Type = CustomPacketPayload.Type(resourceLocation("better-boat-movement:sync")!!) + val identifier = resourceLocation("better-boat-movement:sync")!! + } - @Transient - @Suppress("unused") - val codec = - object : StreamCodec { - override fun decode(buf: FriendlyByteBuf): Config { - return Config( - buf.readFloat(), - buf.readFloat(), - buf.readBoolean(), - buf.readBoolean(), - buf.readBoolean(), - buf.readBoolean(), - buf.readBoolean() - ) - } + constructor(buf: FriendlyByteBuf) : this( + buf.readFloat(), + buf.readFloat(), + buf.readBoolean(), + buf.readBoolean(), + buf.readBoolean(), + buf.readBoolean(), + buf.readBoolean() + ) - override fun encode( - buf: FriendlyByteBuf, - config: Config - ) { - buf.writeFloat(config.stepHeight) - buf.writeFloat(config.playerEjectTicks) - buf.writeBoolean(config.boostUnderwater) - buf.writeBoolean(config.boostOnBlocks) - buf.writeBoolean(config.boostOnIce) - buf.writeBoolean(config.boostOnWater) - buf.writeBoolean(config.onlyForPlayers) - } - } + override fun write(buf: FriendlyByteBuf) { + buf.writeFloat(config.stepHeight) + buf.writeFloat(config.playerEjectTicks) + buf.writeBoolean(config.boostUnderwater) + buf.writeBoolean(config.boostOnBlocks) + buf.writeBoolean(config.boostOnIce) + buf.writeBoolean(config.boostOnWater) + buf.writeBoolean(config.onlyForPlayers) } - override fun type(): CustomPacketPayload.Type { - return packetType + override fun id(): ResourceLocation { + return identifier + } +}*//*?} else {*/ +/*@Serializable +data class Config( + var stepHeight: Float = 0.35f, + var playerEjectTicks: Float = 20f * 10f, + var boostUnderwater: Boolean = true, + var boostOnBlocks: Boolean = true, + var boostOnIce: Boolean = true, + var boostOnWater: Boolean = true, + var onlyForPlayers: Boolean = true +) { + constructor(buf: FriendlyByteBuf) : this( + buf.readFloat(), + buf.readFloat(), + buf.readBoolean(), + buf.readBoolean(), + buf.readBoolean(), + buf.readBoolean(), + buf.readBoolean() + ) + + fun write(buf: FriendlyByteBuf) { + buf.writeFloat(config.stepHeight) + buf.writeFloat(config.playerEjectTicks) + buf.writeBoolean(config.boostUnderwater) + buf.writeBoolean(config.boostOnBlocks) + buf.writeBoolean(config.boostOnIce) + buf.writeBoolean(config.boostOnWater) + buf.writeBoolean(config.onlyForPlayers) } } -/*?}*/ + +*//*?}*/ lateinit var config: Config +val platform = /*? if fabric {*/ + net.fabricmc.loader.api.FabricLoader.getInstance().environmentType.toString().lowercase() /*?} else if forge {*/ + /*net.minecraftforge.fml.loading.FMLLoader.getDist().toString().lowercase() *//*?} else {*/ + /*net.neoforged.fml.loading.FMLLoader.getDist().toString().lowercase() *//*?}*/ + fun getActiveConfig(): Config? { - if (FabricLoader.getInstance().environmentType == EnvType.SERVER) return config + if (platform.contains("server")) return config if (Minecraft.getInstance().isSingleplayer) return config return serverConfig } @@ -129,4 +205,10 @@ fun migrate(tree: JsonElement, version: Int?): Config? { ) else -> null } -} \ No newline at end of file +} + +fun saveConfig() { + dev.nyon.konfig.config.saveConfig(config) +} + +var serverConfig: Config? = null \ No newline at end of file diff --git a/src/main/kotlin/dev/nyon/bbm/config/ModMenuImpl.kt b/src/main/kotlin/dev/nyon/bbm/config/ModMenuImpl.kt index 6e6c580..de50f0e 100644 --- a/src/main/kotlin/dev/nyon/bbm/config/ModMenuImpl.kt +++ b/src/main/kotlin/dev/nyon/bbm/config/ModMenuImpl.kt @@ -1,5 +1,6 @@ package dev.nyon.bbm.config +/*? if fabric {*/ import com.terraformersmc.modmenu.api.ConfigScreenFactory import com.terraformersmc.modmenu.api.ModMenuApi @@ -11,3 +12,4 @@ class ModMenuImpl : ModMenuApi { } } } +/*?}*/ \ No newline at end of file diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml new file mode 100644 index 0000000..4bf0ca3 --- /dev/null +++ b/src/main/resources/META-INF/mods.toml @@ -0,0 +1,26 @@ +modLoader = "kotlinforforge" +loaderVersion = "[1,)" +license = "LGPLv3" + +issueTrackerURL = "https://github.com/${repo}/issues" + +[[mods]] +modId = "${id}" +version = "${version}" +displayName = "${name}" +displayURL = "https://modrinth.com/mod/${slug}" +authors = "btwonion" +description = ''' +${description} +''' +logoFile = "${icon}" + +[[mixins]] +config = "${mixins}" + +[[dependencies.${id}]] +modId = "minecraft" +versionRange = "${mc}" +ordering = "NONE" +mandatory = true +side = "BOTH" \ No newline at end of file diff --git a/src/main/resources/META-INF/neoforge.mods.toml b/src/main/resources/META-INF/neoforge.mods.toml new file mode 100644 index 0000000..b35c348 --- /dev/null +++ b/src/main/resources/META-INF/neoforge.mods.toml @@ -0,0 +1,25 @@ +modLoader = "kotlinforforge" +loaderVersion = "[1,)" +license = "GNU General Public License v3.0" + +issueTrackerURL = "https://github.com/${repo}/issues" + +[[mods]] +modId = "${id}" +version = "${version}" +displayName = "${name}" +displayURL = "https://modrinth.com/mod/${slug}" +authors = "btwonion" +description = ''' +${description} +''' +logoFile = "${icon}" + +[[mixins]] +config = "${mixins}" + +[[dependencies.${id}]] +modId = "minecraft" +versionRange = "${mc}" +ordering = "NONE" +side = "BOTH" \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index d511ecf..aa7dcad 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -3,14 +3,14 @@ "id": "${id}", "name": "${name}", "description": "${description}", - "icon": "assets/bbm/icon/icon.png", "contact": { - "issues": "https://github.com/btwonion/better-boat-movement/issues", - "sources": "https://github.com/btwonion/better-boat-movement" + "issues": "https://github.com/${repo}/issues", + "sources": "https://github.com/${repo}" }, "authors": [ "btwonion" ], + "icon": "${icon}", "contributors": [], "license": [ "GNU General Public License v3.0" @@ -18,19 +18,19 @@ "version": "${version}", "environment": "*", "depends": { - "fabric-language-kotlin": ">=1.11.0+kotlin.2.0.0", - "fabric-api": "*", - "yet_another_config_lib_v3": "*", + "fabric-language-kotlin": ">=${flk}", + "fabric-api": ">=${fapi}", + "yet_another_config_lib_v3": ">=${yacl}", "minecraft": "${mc}" }, "suggests": { - "modmenu": "*" + "modmenu": "${modmenu}" }, "entrypoints": { - "main": [ + "client": [ { "adapter": "kotlin", - "value": "dev.nyon.bbm.BetterBoatMovement" + "value": "dev.nyon.bbm.BetterBoatMovementEntrypoint" } ], "modmenu": [ @@ -41,7 +41,7 @@ ] }, "mixins": [ - "bbm.mixins.json" + "${mixins}" ], "custom": { "modmenu": { diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta new file mode 100644 index 0000000..f8c7bc3 --- /dev/null +++ b/src/main/resources/pack.mcmeta @@ -0,0 +1,6 @@ +{ + "pack": { + "description": "Better Boat Movement", + "pack_format": 6 + } +} \ No newline at end of file diff --git a/stonecutter.gradle.kts b/stonecutter.gradle.kts index ab40edc..e28661d 100644 --- a/stonecutter.gradle.kts +++ b/stonecutter.gradle.kts @@ -1,6 +1,7 @@ import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.encodeToString import kotlinx.serialization.json.* +import org.gradle.configurationcache.extensions.capitalized import java.net.URI import java.net.http.HttpClient import java.net.http.HttpRequest @@ -10,7 +11,13 @@ import java.time.Instant plugins { id("dev.kikugie.stonecutter") } -stonecutter active "1.21" /* [SC] DO NOT EDIT */ +stonecutter active "1.21-fabric" /* [SC] DO NOT EDIT */ + +stonecutter configureEach { + val currentPlatform = current.project.split('-')[1] + val platforms = listOf("fabric", "neoforge", "forge").map { it to (currentPlatform == it) } + consts(platforms) +} stonecutter registerChiseled tasks.register("buildAllVersions", stonecutter.chiseled) { group = "mod" @@ -32,43 +39,38 @@ private data class DiscordWebhook( val username: String, val avatarUrl: String, val embeds: List ) +val majorVersion = property("mod.major-version").toString() +val betaVersion = property("mod.beta").toString().toInt() +val slug = property("mod.slug").toString() +val repo = property("mod.repo").toString() +val avatar = property("mod.icon-url").toString() +val color = property("mod.color").toString().toInt() +val supportedLoaders = property("mod.supported-loaders").toString().split(',').map { it.capitalized() } tasks.register("postUpdate") { group = "mod" - val version = project(stonecutter.versions.first().project).version.toString() - val hyphenCount = version.count { it == '-' } - val featureVersion = when (hyphenCount) { - 1 -> version.split("-").first() - 2 -> { - val split = version.split("-") - if (split.last().contains("rc") || split.last().contains("pre")) split.first() - else "${split.first()}-${split[1]}" - } - 3 -> { - val split = version.split("-") - "${split.first()}-${split[1]}" - } - else -> return@register - } + val featureVersion = "$majorVersion${if (betaVersion != 0) "-beta$betaVersion" else ""}" val url = providers.environmentVariable("DISCORD_WEBHOOK").orNull ?: return@register val roleId = providers.environmentVariable("DISCORD_ROLE_ID").orNull ?: return@register val changelogText = rootProject.file("changelog.md").readText() + val webhook = DiscordWebhook( - username = "${rootProject.name} Release Notifier", - avatarUrl = "https://raw.githubusercontent.com/btwonion/better-boat-movement/master/src/main/resources/assets/bbm/icon/icon.png", - embeds = listOf( + username = "${rootProject.name} Release Notifier", avatarUrl = avatar, embeds = listOf( Embed( title = "v$featureVersion of ${rootProject.name} released!", description = "# Changelog\n$changelogText", timestamp = Instant.now().toString(), - color = 0x683912, + color = color, fields = listOf( Field( - "Supported versions", stonecutter.versions.joinToString { it.version }, false + "Supported versions", stonecutter.versions.map { it.version }.toSet().joinToString(), false + ), + Field( + "Supported loaders", supportedLoaders.joinToString(), false ), - Field("Modrinth", "https://modrinth.com/mod/better-boat-movement", true), - Field("GitHub", "https://github.com/btwonion/better-boat-movement", true) + Field("Modrinth", "https://modrinth.com/mod/$slug", true), + Field("GitHub", "https://github.com/$repo", true) ) ) ) diff --git a/versions/1.20.1-fabric/gradle.properties b/versions/1.20.1-fabric/gradle.properties new file mode 100644 index 0000000..1542cf5 --- /dev/null +++ b/versions/1.20.1-fabric/gradle.properties @@ -0,0 +1,10 @@ +vers.mcVersion=1.20.1 +vers.mcVersionRange=>=1.20 <=1.20.3 +vers.supportedMcVersions=1.20,1.20.1,1.20.2 +vers.deps.quiltmappings=1.20.1+build.9 +vers.deps.fapi=0.92.2+1.20.1 +vers.deps.yacl=3.5.0+1.20.1-fabric +vers.deps.modMenu=7.2.2 +vers.javaVer=17 + +loom.platform=fabric \ No newline at end of file diff --git a/versions/1.20.1-forge/gradle.properties b/versions/1.20.1-forge/gradle.properties new file mode 100644 index 0000000..5a308aa --- /dev/null +++ b/versions/1.20.1-forge/gradle.properties @@ -0,0 +1,10 @@ +vers.mcVersion=1.20.1 +vers.mcVersionRange=>=1.20 <=1.20.3 +vers.supportedMcVersions=1.20,1.20.1,1.20.2 +vers.deps.quiltmappings=1.20.1+build.9 +vers.deps.fml=47.2.16 +vers.deps.yacl=3.5.0+1.20.1-forge +vers.deps.kff=4.11.0 +vers.javaVer=17 + +loom.platform=forge \ No newline at end of file diff --git a/versions/1.20.4-fabric/gradle.properties b/versions/1.20.4-fabric/gradle.properties new file mode 100644 index 0000000..e8b1220 --- /dev/null +++ b/versions/1.20.4-fabric/gradle.properties @@ -0,0 +1,10 @@ +vers.mcVersion=1.20.4 +vers.mcVersionRange=>=1.20.3 <=1.20.4 +vers.supportedMcVersions=1.20.4 +vers.deps.quiltmappings=1.20.4+build.3 +vers.deps.fapi=0.97.1+1.20.4 +vers.deps.yacl=3.5.0+1.20.4-fabric +vers.deps.modMenu=9.2.0-beta.2 +vers.javaVer=17 + +loom.platform=fabric \ No newline at end of file diff --git a/versions/1.20.4-neoforge/gradle.properties b/versions/1.20.4-neoforge/gradle.properties new file mode 100644 index 0000000..57228f7 --- /dev/null +++ b/versions/1.20.4-neoforge/gradle.properties @@ -0,0 +1,10 @@ +vers.mcVersion=1.20.4 +vers.mcVersionRange=>=1.20.3 <=1.20.4 +vers.supportedMcVersions=1.20.4 +vers.deps.quiltmappings=1.20.4+build.3 +vers.deps.fml=20.4.237 +vers.deps.yacl=3.5.0+1.20.4-neoforge +vers.deps.kff=4.11.0 +vers.javaVer=17 + +loom.platform=neoforge \ No newline at end of file diff --git a/versions/1.20.6-fabric/gradle.properties b/versions/1.20.6-fabric/gradle.properties new file mode 100644 index 0000000..02ebee2 --- /dev/null +++ b/versions/1.20.6-fabric/gradle.properties @@ -0,0 +1,11 @@ +vers.mcVersion=1.20.6 +vers.mcVersionRange=>=1.20.5 <=1.20.6 +vers.supportedMcVersions=1.20.5,1.20.6 + +vers.deps.quiltmappings=1.20.6+build.6 +vers.deps.fapi=0.100.8+1.20.6 +vers.deps.yacl=3.5.0+1.20.6-fabric +vers.deps.modMenu=10.0.0-beta.1 +vers.javaVer=21 + +loom.platform=fabric \ No newline at end of file diff --git a/versions/1.20.6-neoforge/gradle.properties b/versions/1.20.6-neoforge/gradle.properties new file mode 100644 index 0000000..6278b31 --- /dev/null +++ b/versions/1.20.6-neoforge/gradle.properties @@ -0,0 +1,12 @@ +vers.mcVersion=1.20.6 +vers.mcVersionRange=>=1.20.5 <=1.20.6 +vers.supportedMcVersions=1.20.5,1.20.6 + +vers.deps.quiltmappings=1.20.6+build.6 +vers.deps.fml=20.6.121 +vers.deps.yacl=3.5.0+1.20.6-neoforge +vers.deps.kff=5.4.0 + +vers.javaVer=21 + +loom.platform=neoforge \ No newline at end of file diff --git a/versions/1.21-fabric/gradle.properties b/versions/1.21-fabric/gradle.properties new file mode 100644 index 0000000..2289a67 --- /dev/null +++ b/versions/1.21-fabric/gradle.properties @@ -0,0 +1,12 @@ +vers.mcVersion=1.21 +vers.mcVersionRange=>1.20.6 <=1.21 +vers.supportedMcVersions=1.21 + +vers.deps.quiltmappings=1.21+build.9 +vers.deps.fapi=0.100.8+1.21 +vers.deps.yacl=3.5.0+1.21-fabric +vers.deps.modMenu=11.0.0-beta.1 + +vers.javaVer=21 + +loom.platform=fabric \ No newline at end of file diff --git a/versions/1.21-neoforge/gradle.properties b/versions/1.21-neoforge/gradle.properties new file mode 100644 index 0000000..b6033ef --- /dev/null +++ b/versions/1.21-neoforge/gradle.properties @@ -0,0 +1,12 @@ +vers.mcVersion=1.21 +vers.mcVersionRange=>1.20.6 <=1.21 +vers.supportedMcVersions=1.21 + +vers.deps.quiltmappings=1.21+build.9 +vers.deps.fml=21.0.167 +vers.deps.yacl=3.5.0+1.21-neoforge +vers.deps.kff=5.4.0 + +vers.javaVer=21 + +loom.platform=neoforge \ No newline at end of file