3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 16:40:10 +01:00

Handle legacy item hover events

Co-authored-by: RaphiMC <50594595+raphimc@users.noreply.github.com>
Dieser Commit ist enthalten in:
FlorianMichael 2024-04-13 21:01:34 +02:00
Ursprung 287678c12a
Commit 4e25549682
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: C2FB87E71C425126
2 geänderte Dateien mit 17 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -78,6 +78,7 @@ import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Enchantme
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.PotionEffects1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Potions1_20_5;
import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Either;
import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.util.SerializerVersion;
@ -163,6 +164,18 @@ public class ComponentRewriter1_20_5 extends ComponentRewriter<ClientboundPacket
return;
}
final Tag valueTag = hoverEventTag.remove("value");
if (valueTag != null) { // Convert legacy hover event to new format for rewriting
final CompoundTag tag = ComponentUtil.deserializeShowItem(valueTag, SerializerVersion.V1_20_3);
final CompoundTag contentsTag = new CompoundTag();
contentsTag.put("id", tag.getStringTag("id"));
contentsTag.put("count", new IntTag(tag.getByte("Count")));
if (tag.get("tag") instanceof CompoundTag) {
contentsTag.put("tag", new StringTag(SerializerVersion.V1_20_3.toSNBT(tag.getCompoundTag("tag"))));
}
hoverEventTag.put("contents", contentsTag);
}
final CompoundTag contentsTag = hoverEventTag.getCompoundTag("contents");
if (contentsTag == null) {
return;

Datei anzeigen

@ -163,4 +163,8 @@ public final class ComponentUtil {
public static CompoundTag deserializeLegacyShowItem(final JsonElement element, final SerializerVersion version) {
return (CompoundTag) version.toTag(version.toComponent(element).asUnformattedString());
}
public static CompoundTag deserializeShowItem(final Tag value, final SerializerVersion version) {
return (CompoundTag) version.toTag(version.toComponent(value).asUnformattedString());
}
}