Skip to content

Commit

Permalink
Merge pull request #2 from btwonion/1.20.5
Browse files Browse the repository at this point in the history
1.20.5
  • Loading branch information
btwonion authored Apr 18, 2024
2 parents 5a18efa + e42074f commit 4ec39a3
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -36,4 +36,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: better-boat-movement-artifacts-${{ steps.ref.outputs.branch }}
path: build/libs/*.jar
path: build/libs/*.jar
4 changes: 2 additions & 2 deletions .github/workflows/build-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
run: ./gradlew build
21 changes: 11 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ plugins {
}

group = "dev.nyon"
val majorVersion = "1.1.2"
val mcVersion = "1.20.4"
val majorVersion = "1.1.3"
val mcVersion = "1.20.5-pre4"
version = "$majorVersion-$mcVersion"
val authors = listOf("btwonion")
val githubRepo = "btwonion/better-boat-movement"
Expand All @@ -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.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")
modImplementation("com.terraformersmc:modmenu:9.0.0")
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:1.1.0-1.20.4")!!)
include(modImplementation("dev.nyon:konfig:2.0.1-1.20.4")!!)
}

tasks {
Expand Down Expand Up @@ -83,11 +84,11 @@ tasks {
}

withType<JavaCompile> {
options.release.set(17)
options.release.set(21)
}

withType<KotlinCompile> {
kotlinOptions.jvmTarget = "17"
kotlinOptions.jvmTarget = "21"
}
}

Expand Down
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -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
25 changes: 19 additions & 6 deletions src/main/java/dev/nyon/bbm/asm/BoatMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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--;
Expand Down
10 changes: 7 additions & 3 deletions src/main/kotlin/dev/nyon/bbm/BetterBoatMovement.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,8 +21,11 @@ object BetterBoatMovement : ModInitializer {
instantiateConfig()
when (FabricLoader.getInstance().environmentType) {
EnvType.CLIENT -> {
ClientPlayNetworking.registerGlobalReceiver(Config.packetType.id) { _, _, buf, _ ->
serverConfig = Config.packetType.read(buf)
ClientPlayConnectionEvents.INIT.register { _, _ ->
PayloadTypeRegistry.playS2C().register(Config.packetType, Config.codec)
ClientPlayNetworking.registerGlobalReceiver(Config.packetType) { packet, _ ->
serverConfig = packet
}
}

ClientPlayConnectionEvents.DISCONNECT.register { _, _ ->
Expand All @@ -40,7 +44,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() {
Expand Down
49 changes: 31 additions & 18 deletions src/main/kotlin/dev/nyon/bbm/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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<Config> =
PacketType.create(
ResourceLocation("better-boat-movement", "sync")
) { buffer ->
Config(buffer.readFloat(), buffer.readFloat(), buffer.readBoolean(), buffer.readInt())
}
}
val packetType: CustomPacketPayload.Type<Config> =
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<FriendlyByteBuf, Config> {
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<out CustomPacketPayload> {
return packetType
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4ec39a3

Please sign in to comment.