Skip to content

Commit

Permalink
fix version dependant bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
btwonion committed Jul 28, 2024
1 parent eb1cfdf commit 6c038a0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/main/java/dev/nyon/bbm/asm/BoatMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
10 changes: 3 additions & 7 deletions src/main/kotlin/dev/nyon/bbm/config/Config.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
Expand All @@ -23,7 +23,7 @@ data class Config(
companion object {
@Transient
val packetType: PacketType<Config> = PacketType.create(
ResourceLocation("better-boat-movement", "sync")
resourceLocation("better-boat-movement:sync")!!
) { buffer ->
Config(buffer.readFloat(), buffer.readFloat(), buffer.readBoolean(), buffer.readBoolean())
}
Expand All @@ -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(
Expand All @@ -54,10 +53,7 @@ data class Config(
) : CustomPacketPayload {
companion object {
@Transient
private val packetId = "better-boat-movement:sync"
@Transient
val packetType: CustomPacketPayload.Type<Config> =
CustomPacketPayload.Type(/*? if >=1.21 {*/ ResourceLocation.parse(packetId)/*?} else {*//*ResourceLocation(packetId)*//*?}*/)
val packetType: CustomPacketPayload.Type<Config> = CustomPacketPayload.Type(resourceLocation("better-boat-movement:sync")!!)

@Transient
@Suppress("unused")
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/dev/nyon/bbm/extensions/ResourceLocation.kt
Original file line number Diff line number Diff line change
@@ -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)*/
}

0 comments on commit 6c038a0

Please sign in to comment.