From a5d0e4baff02aad696cd5ee724d3d042263df073 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Fri, 30 Aug 2024 11:05:07 +0200 Subject: [PATCH] Strip new attributes in 1.21->1.20.5 item hover events --- .../rewriter/ComponentRewriter1_21.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/ComponentRewriter1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/ComponentRewriter1_21.java index e08c1338..834c463e 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/ComponentRewriter1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/ComponentRewriter1_21.java @@ -23,9 +23,11 @@ import com.viaversion.nbt.tag.ListTag; import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; import com.viaversion.viabackwards.protocol.v1_21to1_20_5.Protocol1_21To1_20_5; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.Attributes1_20_5; import com.viaversion.viaversion.protocols.v1_20_5to1_21.Protocol1_20_5To1_21; import com.viaversion.viaversion.protocols.v1_20_5to1_21.data.AttributeModifierMappings1_21; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21; +import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.SerializerVersion; import com.viaversion.viaversion.util.TagUtil; import com.viaversion.viaversion.util.UUIDUtil; @@ -43,7 +45,17 @@ public final class ComponentRewriter1_21 extends TranslatableRewriter modifiers = attributeModifiers.getListTag("modifiers", CompoundTag.class); - for (final CompoundTag modifier : modifiers) { + int size = modifiers.size(); + for (int i = 0; i < size; i++) { + final CompoundTag modifier = modifiers.get(i); + final String type = Key.stripMinecraftNamespace(modifier.getString("type")); + if (Attributes1_20_5.keyToId(type) == -1) { + // Ignore new attributes + modifiers.remove(i--); + size--; + continue; + } + final String id = modifier.getString("id"); final UUID uuid = Protocol1_20_5To1_21.mapAttributeId(id); final String name = AttributeModifierMappings1_21.idToName(id);