From 6c038a0fa3b25480d0df8f242a43f45a2f0d047a Mon Sep 17 00:00:00 2001 From: btwonion Date: Sun, 28 Jul 2024 18:30:47 +0200 Subject: [PATCH] fix version dependant bugs --- src/main/java/dev/nyon/bbm/asm/BoatMixin.java | 4 +++- src/main/kotlin/dev/nyon/bbm/config/Config.kt | 10 +++------- .../dev/nyon/bbm/extensions/ResourceLocation.kt | 11 +++++++++++ 3 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 src/main/kotlin/dev/nyon/bbm/extensions/ResourceLocation.kt diff --git a/src/main/java/dev/nyon/bbm/asm/BoatMixin.java b/src/main/java/dev/nyon/bbm/asm/BoatMixin.java index 4cc859f..67ce332 100644 --- a/src/main/java/dev/nyon/bbm/asm/BoatMixin.java +++ b/src/main/java/dev/nyon/bbm/asm/BoatMixin.java @@ -5,6 +5,7 @@ import dev.nyon.bbm.config.ConfigKt; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.vehicle.Boat; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; @@ -69,6 +70,7 @@ private boolean failsPlayerCondition() { if (config == null) return true; if (!config.getOnlyForPlayers()) return false; - return countPlayerPassengers() > 0; + return getPassengers().stream() + .anyMatch(entity -> entity instanceof Player); } } diff --git a/src/main/kotlin/dev/nyon/bbm/config/Config.kt b/src/main/kotlin/dev/nyon/bbm/config/Config.kt index e0ab124..ce77334 100644 --- a/src/main/kotlin/dev/nyon/bbm/config/Config.kt +++ b/src/main/kotlin/dev/nyon/bbm/config/Config.kt @@ -1,5 +1,6 @@ package dev.nyon.bbm.config +import dev.nyon.bbm.extensions.resourceLocation import dev.nyon.bbm.serverConfig import kotlinx.serialization.Serializable import kotlinx.serialization.Transient @@ -11,7 +12,6 @@ import net.minecraft.network.FriendlyByteBuf /*? if <1.20.5 {*/ /*import net.fabricmc.fabric.api.networking.v1.FabricPacket import net.fabricmc.fabric.api.networking.v1.PacketType -import net.minecraft.resources.ResourceLocation @Serializable data class Config( @@ -23,7 +23,7 @@ data class Config( companion object { @Transient val packetType: PacketType = PacketType.create( - ResourceLocation("better-boat-movement", "sync") + resourceLocation("better-boat-movement:sync")!! ) { buffer -> Config(buffer.readFloat(), buffer.readFloat(), buffer.readBoolean(), buffer.readBoolean()) } @@ -43,7 +43,6 @@ data class Config( *//*?} else {*/ import net.minecraft.network.codec.StreamCodec import net.minecraft.network.protocol.common.custom.CustomPacketPayload -import net.minecraft.resources.ResourceLocation @Serializable data class Config( @@ -54,10 +53,7 @@ data class Config( ) : CustomPacketPayload { companion object { @Transient - private val packetId = "better-boat-movement:sync" - @Transient - val packetType: CustomPacketPayload.Type = - CustomPacketPayload.Type(/*? if >=1.21 {*/ ResourceLocation.parse(packetId)/*?} else {*//*ResourceLocation(packetId)*//*?}*/) + val packetType: CustomPacketPayload.Type = CustomPacketPayload.Type(resourceLocation("better-boat-movement:sync")!!) @Transient @Suppress("unused") diff --git a/src/main/kotlin/dev/nyon/bbm/extensions/ResourceLocation.kt b/src/main/kotlin/dev/nyon/bbm/extensions/ResourceLocation.kt new file mode 100644 index 0000000..bdc5406 --- /dev/null +++ b/src/main/kotlin/dev/nyon/bbm/extensions/ResourceLocation.kt @@ -0,0 +1,11 @@ +package dev.nyon.bbm.extensions + +import net.minecraft.resources.ResourceLocation + +fun resourceLocation(location: String): ResourceLocation? { + //? if >=1.20.6 + return ResourceLocation.tryParse(location) + + //? if <1.20.6 + /*return ResourceLocation(location)*/ +} \ No newline at end of file