diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java index 7cfd9096..d68e1d2e 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java @@ -781,7 +781,7 @@ public class BlockItemPackets1_13 extends BlockItemRewriter { - private static String NBT_TAG_NAME = "ViaBackwards|" + Protocol1_13_2To1_14.class.getSimpleName(); + + private static final String NBT_TAG_NAME = "ViaBackwards|" + Protocol1_13_2To1_14.class.getSimpleName(); + private final Map enchantmentMappings = new HashMap<>(); @Override protected void registerPackets(Protocol1_13_2To1_14 protocol) { @@ -736,6 +734,10 @@ public class BlockItemPackets1_14 extends BlockItemRewriter lore = new ArrayList<>(); + for (Tag enchantmentEntry : enchantments.clone()) { + String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue(); + String enchantmentName = enchantmentMappings.get(newId); + if (enchantmentName != null) { + enchantments.remove(enchantmentEntry); + lore.add(new StringTag("", enchantmentMappings.get(newId) + " " + BlockItemPackets1_13.getRomanNumber((Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue()))); + noMapped.add(enchantmentEntry); + } + } + if (!lore.isEmpty()) { + if (!storedEnchant && enchantments.size() == 0) { + CompoundTag dummyEnchantment = new CompoundTag(""); + dummyEnchantment.put(new StringTag("id", "")); + dummyEnchantment.put(new ShortTag("lvl", (short) 0)); + enchantments.add(dummyEnchantment); + + tag.put(new ByteTag(NBT_TAG_NAME + "|dummyEnchant")); + } + + tag.put(noMapped); + + CompoundTag display = tag.get("display"); + if (display == null) { + tag.put(display = new CompoundTag("display")); + } + ListTag loreTag = display.get("Lore"); + if (loreTag == null) { + display.put(loreTag = new ListTag("Lore", StringTag.class)); + } + + lore.addAll(loreTag.getValue()); + loreTag.setValue(lore); + } + } + @Override public Item handleItemToServer(Item item) { if (item == null) return null; @@ -797,10 +846,47 @@ public class BlockItemPackets1_14 extends BlockItemRewriter