From 8357fd01aa13fb180d107830b1ba60c9ec78cf28 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sat, 21 Sep 2024 11:40:46 +0200 Subject: [PATCH] Update attributes in item hover events --- .../rewriter/ComponentRewriter1_21_2.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/ComponentRewriter1_21_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/ComponentRewriter1_21_2.java index b11a246b0..e1c04429f 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/ComponentRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/ComponentRewriter1_21_2.java @@ -18,12 +18,16 @@ package com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter; import com.viaversion.nbt.tag.CompoundTag; +import com.viaversion.nbt.tag.ListTag; +import com.viaversion.nbt.tag.StringTag; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.data.FullMappings; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21; import com.viaversion.viaversion.protocols.v1_21to1_21_2.Protocol1_21To1_21_2; import com.viaversion.viaversion.rewriter.ComponentRewriter; import com.viaversion.viaversion.util.SerializerVersion; import com.viaversion.viaversion.util.TagUtil; +import java.util.Iterator; public final class ComponentRewriter1_21_2 extends ComponentRewriter { @@ -38,6 +42,8 @@ public final class ComponentRewriter1_21_2 extends ComponentRewriter modifiers = attributeModifiers.getListTag("modifiers", CompoundTag.class); + final Iterator iterator = modifiers.iterator(); + while (iterator.hasNext()) { + final CompoundTag modifier = iterator.next(); + final StringTag attribute = modifier.getStringTag("type"); + final String mappedAttribute = mappings.mappedIdentifier(attribute.getValue()); + if (mappedAttribute != null) { + attribute.setValue(mappedAttribute); + } else { + iterator.remove(); + } + } + } + @Override protected SerializerVersion inputSerializerVersion() { return SerializerVersion.V1_20_5;