From d2b65d4f7e55daae7cd1f6b55dafa05bdd836173 Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Wed, 9 Apr 2025 18:11:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(network):=20=E6=94=B9=E8=BF=9B=E5=A3=B0?= =?UTF-8?q?=E9=9F=B3=E4=BA=8B=E4=BB=B6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/network/PacketConsumers.java | 100 ++++++++++++------ gradle.properties | 2 +- 2 files changed, 70 insertions(+), 32 deletions(-) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java index d29f03bea..a9889b6f4 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java @@ -1555,38 +1555,76 @@ public class PacketConsumers { try { FriendlyByteBuf buf = event.getBuffer(); int id = buf.readVarInt(); - Key soundId = buf.readKey(); - Float range = null; - if (buf.readBoolean()) { - range = buf.readFloat(); - } - int source = buf.readVarInt(); - int x = buf.readInt(); - int y = buf.readInt(); - int z = buf.readInt(); - float volume = buf.readFloat(); - float pitch = buf.readFloat(); - long seed = buf.readLong(); - Key mapped = BukkitBlockManager.instance().replaceSoundIfExist(soundId); - if (mapped != null) { - event.setChanged(true); - buf.clear(); - buf.writeVarInt(event.packetID()); - buf.writeVarInt(id); - buf.writeKey(mapped); - if (range != null) { - buf.writeBoolean(true); - buf.writeFloat(range); - } else { - buf.writeBoolean(false); + if (id == 0) { + Key soundId = buf.readKey(); + Float range = null; + if (buf.readBoolean()) { + range = buf.readFloat(); + } + int source = buf.readVarInt(); + int x = buf.readInt(); + int y = buf.readInt(); + int z = buf.readInt(); + float volume = buf.readFloat(); + float pitch = buf.readFloat(); + long seed = buf.readLong(); + Key mapped = BukkitBlockManager.instance().replaceSoundIfExist(soundId); + if (mapped != null) { + event.setChanged(true); + buf.clear(); + buf.writeVarInt(event.packetID()); + buf.writeVarInt(id); + buf.writeKey(mapped); + if (range != null) { + buf.writeBoolean(true); + buf.writeFloat(range); + } else { + buf.writeBoolean(false); + } + buf.writeVarInt(source); + buf.writeInt(x); + buf.writeInt(y); + buf.writeInt(z); + buf.writeFloat(volume); + buf.writeFloat(pitch); + buf.writeLong(seed); + } + } else { + Optional optionalSound = FastNMS.INSTANCE.method$BuiltInRegistries$byId(Reflections.instance$BuiltInRegistries$SOUND_EVENT, id - 1); + if (optionalSound.isEmpty()) return; + Object sound = optionalSound.get(); + Key soundId = Key.of(FastNMS.INSTANCE.method$SoundEvent$location(sound)); + int source = buf.readVarInt(); + int x = buf.readInt(); + int y = buf.readInt(); + int z = buf.readInt(); + float volume = buf.readFloat(); + float pitch = buf.readFloat(); + long seed = buf.readLong(); + Key mapped = BukkitBlockManager.instance().replaceSoundIfExist(soundId); + if (mapped != null) { + Optional mappedId = FastNMS.INSTANCE.method$BuiltInRegistries$getId( + Reflections.instance$BuiltInRegistries$SOUND_EVENT, + FastNMS.INSTANCE.method$SoundEvent$createVariableRangeEvent(KeyUtils.toResourceLocation(mapped)) + ); + event.setChanged(true); + buf.clear(); + buf.writeVarInt(event.packetID()); + if (mappedId.isPresent()) { + buf.writeVarInt(mappedId.get() + 1); + } else { + buf.writeVarInt(0); + buf.writeKey(mapped); + buf.writeBoolean(false); + } + buf.writeVarInt(source); + buf.writeInt(x); + buf.writeInt(y); + buf.writeInt(z); + buf.writeFloat(volume); + buf.writeFloat(pitch); + buf.writeLong(seed); } - buf.writeVarInt(source); - buf.writeInt(x); - buf.writeInt(y); - buf.writeInt(z); - buf.writeFloat(volume); - buf.writeFloat(pitch); - buf.writeLong(seed); } } catch (Exception e) { CraftEngine.instance().logger().warn("Failed to handle ClientboundSoundPacket", e); diff --git a/gradle.properties b/gradle.properties index 88b5b7aaf..a0e502d0a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -51,7 +51,7 @@ byte_buddy_version=1.17.5 ahocorasick_version=0.6.3 snake_yaml_version=2.4 anti_grief_version=0.13 -nms_helper_version=0.50 +nms_helper_version=0.51 # Ignite Dependencies mixinextras_version=0.4.1 mixin_version=0.15.2+mixin.0.8.7