From 7abff77c511f4b7b58931f0052b96633925764b9 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Sun, 15 Nov 2020 12:01:01 +0100 Subject: [PATCH] Add method to get handler in sound rewriter --- .../api/rewriters/SoundRewriter.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/SoundRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/SoundRewriter.java index 768b53fcb..d877e10e7 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/SoundRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/SoundRewriter.java @@ -2,6 +2,7 @@ package us.myles.ViaVersion.api.rewriters; import us.myles.ViaVersion.api.protocol.ClientboundPacketType; import us.myles.ViaVersion.api.protocol.Protocol; +import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; @@ -25,16 +26,20 @@ public class SoundRewriter { @Override public void registerMap() { map(Type.VAR_INT); // Sound Id - handler(wrapper -> { - int soundId = wrapper.get(Type.VAR_INT, 0); - int mappedId = idRewriter.rewrite(soundId); - if (mappedId == -1) { - wrapper.cancel(); - } else if (soundId != mappedId) { - wrapper.set(Type.VAR_INT, 0, mappedId); - } - }); + handler(getSoundHandler()); } }); } + + public PacketHandler getSoundHandler() { + return wrapper -> { + int soundId = wrapper.get(Type.VAR_INT, 0); + int mappedId = idRewriter.rewrite(soundId); + if (mappedId == -1) { + wrapper.cancel(); + } else if (soundId != mappedId) { + wrapper.set(Type.VAR_INT, 0, mappedId); + } + }; + } }