From 83636ecf517f2e5e2d5e51f05552238dba3cc3a1 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 27 Aug 2023 18:52:08 +1000 Subject: [PATCH] Fix 1.16->1.15 hover components in books Fixes #572 --- .../packets/BlockItemPackets1_16.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java index b6021b3b..54a33196 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java @@ -33,8 +33,10 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.UUIDIntArrayType; +import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.LongArrayTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; @@ -302,6 +304,22 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit } } + // Handle hover event changes in book pages + if ((item.identifier() == 758 || item.identifier() == 759) && tag != null) { + Tag pagesTag = tag.get("pages"); + if (pagesTag instanceof ListTag) { + for (Tag page : ((ListTag) pagesTag)) { + if (!(page instanceof StringTag)) { + continue; + } + + StringTag pageTag = (StringTag) page; + JsonElement jsonElement = protocol.getTranslatableRewriter().processText(pageTag.getValue()); + pageTag.setValue(jsonElement.toString()); + } + } + } + InventoryPackets.newToOldAttributes(item); enchantmentRewriter.handleToClient(item); return item;