From 5aae4ab10a801b4de07e5bff09952a60dc667881 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Sat, 21 Dec 2024 10:19:56 +0100 Subject: [PATCH] Reuse sound rewriter instance in 1.21->1.21.2 (#4323) --- .../rewriter/BlockItemPacketRewriter1_20_5.java | 4 ++-- .../protocols/v1_21to1_21_2/Protocol1_21To1_21_2.java | 6 +++++- .../rewriter/BlockItemPacketRewriter1_21_2.java | 3 +-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java index 05570efb8..c11d0aad8 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java @@ -81,7 +81,6 @@ import com.viaversion.viaversion.api.type.types.version.Types1_20_3; import com.viaversion.viaversion.api.type.types.version.Types1_20_5; import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundPacket1_20_3; import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundPackets1_20_3; -import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.rewriter.RecipeRewriter1_20_3; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.Protocol1_20_3To1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.Attributes1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.BannerPatterns1_20_5; @@ -603,9 +602,10 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter tagRewriter = new TagRewriter<>(this); private final ComponentRewriter1_21_2 componentRewriter = new ComponentRewriter1_21_2(this); + private final SoundRewriter soundRewriter = new SoundRewriter<>(this); public Protocol1_21To1_21_2() { super(ClientboundPacket1_21.class, ClientboundPacket1_21_2.class, ServerboundPacket1_20_5.class, ServerboundPacket1_21_2.class); @@ -94,7 +95,6 @@ public final class Protocol1_21To1_21_2 extends AbstractProtocol soundRewriter = new SoundRewriter<>(this); soundRewriter.registerSound1_19_3(ClientboundPackets1_21.SOUND); soundRewriter.registerSound1_19_3(ClientboundPackets1_21.SOUND_ENTITY); @@ -280,6 +280,10 @@ public final class Protocol1_21To1_21_2 extends AbstractProtocol getSoundRewriter() { + return soundRewriter; + } + @Override protected PacketTypesProvider createPacketTypesProvider() { return new SimplePacketTypesProvider<>( diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/BlockItemPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/BlockItemPacketRewriter1_21_2.java index a545720f6..f4049bc0d 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/BlockItemPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/BlockItemPacketRewriter1_21_2.java @@ -60,7 +60,6 @@ import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPacke import com.viaversion.viaversion.protocols.v1_21to1_21_2.storage.BundleStateTracker; import com.viaversion.viaversion.protocols.v1_21to1_21_2.storage.ChunkLoadTracker; import com.viaversion.viaversion.rewriter.BlockRewriter; -import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.rewriter.StructuredItemRewriter; import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.Key; @@ -238,7 +237,7 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter< wrapper.write(Types1_21_2.PARTICLE, smallExplosionParticle); } - new SoundRewriter<>(protocol).soundHolderHandler().handle(wrapper); + protocol.getSoundRewriter().soundHolderHandler().handle(wrapper); }); protocol.registerClientbound(ClientboundPackets1_21.UPDATE_RECIPES, wrapper -> {