diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_6to1_21_5/Protocol1_21_6To1_21_5.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_6to1_21_5/Protocol1_21_6To1_21_5.java index 88eb5517a..78695fcab 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_6to1_21_5/Protocol1_21_6To1_21_5.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_6to1_21_5/Protocol1_21_6To1_21_5.java @@ -93,6 +93,9 @@ public Protocol1_21_6To1_21_5() { protected void registerPackets() { super.registerPackets(); + replaceClientbound(ClientboundPackets1_21_6.UPDATE_TAGS, this::updateTags); + replaceClientbound(ClientboundConfigurationPackets1_21_6.UPDATE_TAGS, this::updateTags); + appendClientbound(ClientboundPackets1_21_6.SOUND, wrapper -> { wrapper.passthrough(Types.VAR_INT); // Source fixSoundSource(wrapper); @@ -238,34 +241,24 @@ private void fixSoundSource(final PacketWrapper wrapper) { } private void updateTags(final PacketWrapper wrapper) { - tagRewriter.handleGeneric(wrapper); - wrapper.resetReader(); - + // Store dialog tags; then call the normal rewriter which will remove them before sending to the client final RegistryAndTags registryAndTags = wrapper.user().get(RegistryAndTags.class); final int length = wrapper.passthrough(Types.VAR_INT); for (int i = 0; i < length; i++) { - final String registryKey = wrapper.read(Types.STRING); + final String registryKey = wrapper.passthrough(Types.STRING); final boolean dialog = "dialog".equals(Key.stripMinecraftNamespace(registryKey)); - if (dialog) { - final int tagsSize = wrapper.read(Types.VAR_INT); - for (int j = 0; j < tagsSize; j++) { - final String key = wrapper.read(Types.STRING); - final int[] ids = wrapper.read(Types.VAR_INT_ARRAY_PRIMITIVE); + final int tagsSize = wrapper.passthrough(Types.VAR_INT); + for (int j = 0; j < tagsSize; j++) { + final String key = wrapper.passthrough(Types.STRING); + final int[] ids = wrapper.passthrough(Types.VAR_INT_ARRAY_PRIMITIVE); + if (dialog) { registryAndTags.storeTags(key, ids); } - } else { - wrapper.write(Types.STRING, registryKey); // Write back - final int tagsSize = wrapper.passthrough(Types.VAR_INT); - for (int j = 0; j < tagsSize; j++) { - wrapper.passthrough(Types.STRING); - wrapper.passthrough(Types.VAR_INT_ARRAY_PRIMITIVE); - } } } - if (registryAndTags.tagsSent()) { - wrapper.set(Types.VAR_INT, 0, length - 1); // Dialog tags have been read, remove from size - } + wrapper.resetReader(); + tagRewriter.handleGeneric(wrapper); } private void clearDialog(final PacketWrapper wrapper) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_6to1_21_5/storage/RegistryAndTags.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_6to1_21_5/storage/RegistryAndTags.java index d6bb384c7..8b04997ac 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_6to1_21_5/storage/RegistryAndTags.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_6to1_21_5/storage/RegistryAndTags.java @@ -44,10 +44,6 @@ public CompoundTag fromRegistry(final String key) { return dialogs.get(Key.stripMinecraftNamespace(key)); } - public boolean tagsSent() { - return dialogTags != null && !dialogTags.isEmpty(); - } - public void storeTags(final String key, final int[] ids) { if (dialogTags == null) { dialogTags = new Object2ObjectArrayMap<>(); @@ -55,12 +51,8 @@ public void storeTags(final String key, final int[] ids) { dialogTags.put(Key.stripMinecraftNamespace(key), ids); } - public int[] fromKey(final String key) { - return dialogTags.get(Key.stripMinecraftNamespace(key)); - } - public CompoundTag[] fromRegistryKey(final String key) { - final int[] ids = fromKey(key); + final int[] ids = dialogTags.get(Key.stripMinecraftNamespace(key)); if (ids == null) { return null; }