From a4b1d7f1ba24b8894dec55f630044d615eaca5cd Mon Sep 17 00:00:00 2001 From: btwonion Date: Mon, 15 Apr 2024 20:28:37 +0200 Subject: [PATCH 1/6] update to 1.20.5 (networking still pending) --- build.gradle.kts | 19 +++---- src/main/java/dev/nyon/bbm/asm/BoatMixin.java | 25 +++++++--- .../kotlin/dev/nyon/bbm/BetterBoatMovement.kt | 6 +-- src/main/kotlin/dev/nyon/bbm/config/Config.kt | 49 ++++++++++++------- 4 files changed, 63 insertions(+), 36 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 3b3f55f..c763a04 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,7 +16,7 @@ plugins { group = "dev.nyon" val majorVersion = "1.1.2" -val mcVersion = "1.20.4" +val mcVersion = "1.20.5-pre2" version = "$majorVersion-$mcVersion" val authors = listOf("btwonion") val githubRepo = "btwonion/better-boat-movement" @@ -28,26 +28,27 @@ repositories { maven("https://repo.nyon.dev/releases") maven("https://maven.isxander.dev/releases") maven("https://oss.sonatype.org/content/repositories/snapshots/") + maven("https://maven.isxander.dev/snapshots") // remove in stable release } dependencies { minecraft("com.mojang:minecraft:$mcVersion") mappings( loom.layered { - parchment("org.parchmentmc.data:parchment-1.20.4:2024.02.25@zip") + parchment("org.parchmentmc.data:parchment-1.20.4:2024.04.14@zip") officialMojangMappings() } ) implementation("org.vineflower:vineflower:1.9.3") - modImplementation("net.fabricmc:fabric-loader:0.15.7") - modImplementation("net.fabricmc.fabric-api:fabric-api:0.96.11+$mcVersion") + modImplementation("net.fabricmc:fabric-loader:0.15.10") + modImplementation("net.fabricmc.fabric-api:fabric-api:0.97.1+1.20.5") modImplementation("net.fabricmc:fabric-language-kotlin:1.10.19+kotlin.1.9.23") - modImplementation("dev.isxander.yacl:yet-another-config-lib-fabric:3.3.2+1.20.4") - modImplementation("com.terraformersmc:modmenu:9.0.0") + modImplementation("dev.isxander.yacl:yet-another-config-lib-fabric:3.3.2+1.20.4+update.1.20.5-SNAPSHOT+update.1.20.5-SNAPSHOT") + modImplementation("com.terraformersmc:modmenu:10.0.0-alpha.3") - include(modImplementation("dev.nyon:konfig:1.1.0-1.20.4")!!) + include(modImplementation("dev.nyon:konfig:2.0.1-1.20.4")!!) } tasks { @@ -83,11 +84,11 @@ tasks { } withType { - options.release.set(17) + options.release.set(21) } withType { - kotlinOptions.jvmTarget = "17" + kotlinOptions.jvmTarget = "21" } } diff --git a/src/main/java/dev/nyon/bbm/asm/BoatMixin.java b/src/main/java/dev/nyon/bbm/asm/BoatMixin.java index abf2059..6cd27fe 100644 --- a/src/main/java/dev/nyon/bbm/asm/BoatMixin.java +++ b/src/main/java/dev/nyon/bbm/asm/BoatMixin.java @@ -2,8 +2,10 @@ import dev.nyon.bbm.config.Config; import dev.nyon.bbm.config.ConfigKt; +import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.vehicle.Boat; +import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; @@ -14,23 +16,34 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(Boat.class) -class BoatMixin { +abstract class BoatMixin extends Entity { @Unique - private Boat instance = (Boat) (Object) this; + private final Boat instance = (Boat) (Object) this; @Unique private int wallHitCooldown; + public BoatMixin( + EntityType entityType, + Level level + ) { + super(entityType, level); + } + + @Override + public float maxUpStep() { + Config config = ConfigKt.getActiveConfig(); + if (config == null) return 0f; + return config.getStepHeight(); + } + @Inject( method = "tick", at = @At("HEAD") ) private void checkWall(CallbackInfo ci) { Config config = ConfigKt.getActiveConfig(); - if (config == null) { - instance.setMaxUpStep(0); - return; - } + if (config == null) return; if (failsPlayerCondition()) return; if (wallHitCooldown > 0) wallHitCooldown--; diff --git a/src/main/kotlin/dev/nyon/bbm/BetterBoatMovement.kt b/src/main/kotlin/dev/nyon/bbm/BetterBoatMovement.kt index cab0319..c09dc60 100644 --- a/src/main/kotlin/dev/nyon/bbm/BetterBoatMovement.kt +++ b/src/main/kotlin/dev/nyon/bbm/BetterBoatMovement.kt @@ -20,8 +20,8 @@ object BetterBoatMovement : ModInitializer { instantiateConfig() when (FabricLoader.getInstance().environmentType) { EnvType.CLIENT -> { - ClientPlayNetworking.registerGlobalReceiver(Config.packetType.id) { _, _, buf, _ -> - serverConfig = Config.packetType.read(buf) + ClientPlayNetworking.registerGlobalReceiver(Config.packetType) { packet, _ -> + serverConfig = packet } ClientPlayConnectionEvents.DISCONNECT.register { _, _ -> @@ -40,7 +40,7 @@ object BetterBoatMovement : ModInitializer { private fun instantiateConfig() { config(FabricLoader.getInstance().configDir.resolve("better-boat-movement.json"), 1, Config()) { _, _ -> null } - internalConfig = loadConfig() ?: error("No config settings set!") + internalConfig = loadConfig() } fun saveConfig() { diff --git a/src/main/kotlin/dev/nyon/bbm/config/Config.kt b/src/main/kotlin/dev/nyon/bbm/config/Config.kt index 6182a57..663ba7a 100644 --- a/src/main/kotlin/dev/nyon/bbm/config/Config.kt +++ b/src/main/kotlin/dev/nyon/bbm/config/Config.kt @@ -4,12 +4,11 @@ import dev.nyon.bbm.serverConfig import kotlinx.serialization.Serializable import kotlinx.serialization.Transient import net.fabricmc.api.EnvType -import net.fabricmc.fabric.api.networking.v1.FabricPacket -import net.fabricmc.fabric.api.networking.v1.PacketType import net.fabricmc.loader.api.FabricLoader import net.minecraft.client.Minecraft import net.minecraft.network.FriendlyByteBuf -import net.minecraft.resources.ResourceLocation +import net.minecraft.network.codec.StreamCodec +import net.minecraft.network.protocol.common.custom.CustomPacketPayload lateinit var config: Config @@ -20,26 +19,40 @@ data class Config( var boostUnderwater: Boolean = true, var wallHitCooldownTicks: Int = 5, var onlyForPlayers: Boolean = true -) : - FabricPacket { +) : CustomPacketPayload { companion object { @Transient - val packetType: PacketType = - PacketType.create( - ResourceLocation("better-boat-movement", "sync") - ) { buffer -> - Config(buffer.readFloat(), buffer.readFloat(), buffer.readBoolean(), buffer.readInt()) - } - } + val packetType: CustomPacketPayload.Type = + CustomPacketPayload.createType("better-boat-movement:sync") - override fun write(buffer: FriendlyByteBuf) { - buffer.writeFloat(stepHeight) - buffer.writeFloat(playerEjectTicks) - buffer.writeBoolean(boostUnderwater) - buffer.writeInt(wallHitCooldownTicks) + @Transient + @Suppress("unused") + val codec = + object : StreamCodec { + override fun decode(buf: FriendlyByteBuf): Config { + return Config( + buf.readFloat(), + buf.readFloat(), + buf.readBoolean(), + buf.readInt(), + buf.readBoolean() + ) + } + + override fun encode( + buf: FriendlyByteBuf, + config: Config + ) { + buf.writeFloat(config.stepHeight) + buf.writeFloat(config.playerEjectTicks) + buf.writeBoolean(config.boostUnderwater) + buf.writeInt(config.wallHitCooldownTicks) + buf.writeBoolean(config.onlyForPlayers) + } + } } - override fun getType(): PacketType<*> { + override fun type(): CustomPacketPayload.Type { return packetType } } From 93ff4f7aa23820cbc5f96e1fafa0e0e459206607 Mon Sep 17 00:00:00 2001 From: btwonion Date: Thu, 18 Apr 2024 15:09:44 +0200 Subject: [PATCH 2/6] update versions --- build.gradle.kts | 6 +++--- src/main/resources/fabric.mod.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index c763a04..2c0992d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,7 +16,7 @@ plugins { group = "dev.nyon" val majorVersion = "1.1.2" -val mcVersion = "1.20.5-pre2" +val mcVersion = "1.20.5-pre4" version = "$majorVersion-$mcVersion" val authors = listOf("btwonion") val githubRepo = "btwonion/better-boat-movement" @@ -42,10 +42,10 @@ dependencies { implementation("org.vineflower:vineflower:1.9.3") modImplementation("net.fabricmc:fabric-loader:0.15.10") - modImplementation("net.fabricmc.fabric-api:fabric-api:0.97.1+1.20.5") + modImplementation("net.fabricmc.fabric-api:fabric-api:0.97.3+1.20.5") modImplementation("net.fabricmc:fabric-language-kotlin:1.10.19+kotlin.1.9.23") - modImplementation("dev.isxander.yacl:yet-another-config-lib-fabric:3.3.2+1.20.4+update.1.20.5-SNAPSHOT+update.1.20.5-SNAPSHOT") + modImplementation("dev.isxander.yacl:yet-another-config-lib-fabric:3.3.3+1.20.4+update.1.20.5-SNAPSHOT+update.1.20.5-SNAPSHOT") modImplementation("com.terraformersmc:modmenu:10.0.0-alpha.3") include(modImplementation("dev.nyon:konfig:2.0.1-1.20.4")!!) diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index c58d751..42f89a4 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -23,7 +23,7 @@ "fabric-language-kotlin": ">=1.10.19+kotlin.1.9.23", "fabric-api": ">=0.92.0+1.20.1", "yet_another_config_lib_v3": ">=3.2.2+1.20", - "minecraft": ">=1.20.1" + "minecraft": ">1.20.4" }, "suggests": { "modmenu": "7.2.2" From 7e3d5091fa9bee5560e3a5ce585fb2fd379c8e13 Mon Sep 17 00:00:00 2001 From: btwonion Date: Thu, 18 Apr 2024 15:09:48 +0200 Subject: [PATCH 3/6] fix networking --- src/main/kotlin/dev/nyon/bbm/BetterBoatMovement.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/dev/nyon/bbm/BetterBoatMovement.kt b/src/main/kotlin/dev/nyon/bbm/BetterBoatMovement.kt index c09dc60..8240bab 100644 --- a/src/main/kotlin/dev/nyon/bbm/BetterBoatMovement.kt +++ b/src/main/kotlin/dev/nyon/bbm/BetterBoatMovement.kt @@ -7,6 +7,7 @@ import net.fabricmc.api.EnvType import net.fabricmc.api.ModInitializer import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking +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 @@ -20,8 +21,11 @@ object BetterBoatMovement : ModInitializer { instantiateConfig() when (FabricLoader.getInstance().environmentType) { EnvType.CLIENT -> { - ClientPlayNetworking.registerGlobalReceiver(Config.packetType) { packet, _ -> - serverConfig = packet + ClientPlayConnectionEvents.INIT.register { _, _ -> + PayloadTypeRegistry.playS2C().register(Config.packetType, Config.codec) + ClientPlayNetworking.registerGlobalReceiver(Config.packetType) { packet, _ -> + serverConfig = packet + } } ClientPlayConnectionEvents.DISCONNECT.register { _, _ -> From 55900b532d3a1b6e40028645f86338a1949dc25b Mon Sep 17 00:00:00 2001 From: btwonion Date: Thu, 18 Apr 2024 15:09:50 +0200 Subject: [PATCH 4/6] add changelog --- changelog.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 4ede5be..d77e15d 100644 --- a/changelog.md +++ b/changelog.md @@ -1 +1,2 @@ -- fix bug causing crash on server +- update to 1.20.5 +- fix bug where `onlyForPlayers` config option did not sync with the client From 7d7adec89f67bfeef7d08032cf00a3cdbbd7daaf Mon Sep 17 00:00:00 2001 From: btwonion Date: Thu, 18 Apr 2024 15:10:08 +0200 Subject: [PATCH 5/6] bump minor version --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 2c0992d..20afdc1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,7 +15,7 @@ plugins { } group = "dev.nyon" -val majorVersion = "1.1.2" +val majorVersion = "1.1.3" val mcVersion = "1.20.5-pre4" version = "$majorVersion-$mcVersion" val authors = listOf("btwonion") From e42074f6ffcd26a5f47e7393d1ae60e6f26fe47f Mon Sep 17 00:00:00 2001 From: btwonion Date: Thu, 18 Apr 2024 15:11:26 +0200 Subject: [PATCH 6/6] bump build java version to 21 --- .github/workflows/build-commit.yml | 4 ++-- .github/workflows/build-pull-request.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-commit.yml b/.github/workflows/build-commit.yml index 39a1eb4..6c38bce 100644 --- a/.github/workflows/build-commit.yml +++ b/.github/workflows/build-commit.yml @@ -19,7 +19,7 @@ jobs: uses: actions/setup-java@v4 with: distribution: 'temurin' - java-version: 17 + java-version: 21 - name: Initialize caches uses: actions/cache@v4 with: @@ -36,4 +36,4 @@ jobs: uses: actions/upload-artifact@v4 with: name: better-boat-movement-artifacts-${{ steps.ref.outputs.branch }} - path: build/libs/*.jar \ No newline at end of file + path: build/libs/*.jar diff --git a/.github/workflows/build-pull-request.yml b/.github/workflows/build-pull-request.yml index 1a9cb5d..451643a 100644 --- a/.github/workflows/build-pull-request.yml +++ b/.github/workflows/build-pull-request.yml @@ -24,6 +24,6 @@ jobs: uses: actions/setup-java@v4 with: distribution: 'temurin' - java-version: 17 + java-version: 21 - name: Build artifacts - run: ./gradlew build \ No newline at end of file + run: ./gradlew build