diff --git a/api/src/main/java/com/viaversion/viaversion/api/rewriter/ItemRewriter.java b/api/src/main/java/com/viaversion/viaversion/api/rewriter/ItemRewriter.java index 7fb84a34c..71f98081a 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/rewriter/ItemRewriter.java +++ b/api/src/main/java/com/viaversion/viaversion/api/rewriter/ItemRewriter.java @@ -47,33 +47,60 @@ public interface ItemRewriter extends Rewriter { /** * Returns the item type of the current protocol. + * * @return item type */ - @Nullable default Type itemType() { + @Nullable + default Type itemType() { return null; } /** * Returns the item array type of the current protocol. + * * @return item array type */ - @Nullable default Type itemArrayType() { + @Nullable + default Type itemArrayType() { return null; } /** * Returns the mapped item type of the target protocol. + * * @return mapped item type */ - @Nullable default Type mappedItemType() { + @Nullable + default Type mappedItemType() { return itemType(); } /** * Returns the mapped item array type of the target protocol. + * * @return mapped item array type */ - @Nullable default Type mappedItemArrayType() { + @Nullable + default Type mappedItemArrayType() { return itemArrayType(); } + + /** + * Returns the NBT tag name used for storing original item data. + * + * @return NBT tag name + */ + default String nbtTagName() { + return "VV|" + protocol().getClass().getSimpleName(); + } + + /** + * Prefixes the NBT tag name with the current protocol's {@link #nbtTagName()}. + * + * @param nbt NBT tag name + * @return prefixed NBT tag name + */ + default String nbtTagName(final String nbt) { + return nbtTagName() + "|" + nbt; + } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java index 0717c2efe..79fb39273 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java @@ -47,7 +47,6 @@ import java.util.Locale; import java.util.Optional; public class InventoryPackets extends ItemRewriter { - private static final String NBT_TAG_NAME = "ViaVersion|" + Protocol1_13To1_12_2.class.getSimpleName(); public InventoryPackets(Protocol1_13To1_12_2 protocol) { super(protocol, null, null); @@ -319,7 +318,7 @@ public class InventoryPackets extends ItemRewriter canPlaceOnTag = tag.getListTag("CanPlaceOn"); if (canPlaceOnTag != null) { ListTag newCanPlaceOn = new ListTag<>(StringTag.class); - tag.put(NBT_TAG_NAME + "|CanPlaceOn", canPlaceOnTag.copy()); + tag.put(nbtTagName("CanPlaceOn"), canPlaceOnTag.copy()); for (Tag oldTag : canPlaceOnTag) { Object value = oldTag.getValue(); String oldId = Key.stripMinecraftNamespace(value.toString()); @@ -405,7 +404,7 @@ public class InventoryPackets extends ItemRewriter canDestroyTag = tag.getListTag("CanDestroy"); if (canDestroyTag != null) { ListTag newCanDestroy = new ListTag<>(StringTag.class); - tag.put(NBT_TAG_NAME + "|CanDestroy", canDestroyTag.copy()); + tag.put(nbtTagName("CanDestroy"), canDestroyTag.copy()); for (Tag oldTag : canDestroyTag) { Object value = oldTag.getValue(); String oldId = Key.stripMinecraftNamespace(value.toString()); @@ -456,7 +455,7 @@ public class InventoryPackets extends ItemRewriter old = tag.getListTag("CanPlaceOn"); ListTag newCanPlaceOn = new ListTag<>(StringTag.class); @@ -682,8 +681,8 @@ public class InventoryPackets extends ItemRewriter old = tag.getListTag("CanDestroy"); ListTag newCanDestroy = new ListTag<>(StringTag.class); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java index ecb706e63..1de848520 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java @@ -46,7 +46,6 @@ import java.util.Set; import java.util.concurrent.ThreadLocalRandom; public class InventoryPackets extends ItemRewriter { - private static final String NBT_TAG_NAME = "ViaVersion|" + Protocol1_14To1_13_2.class.getSimpleName(); private static final Set REMOVED_RECIPE_TYPES = Sets.newHashSet("crafting_special_banneraddpattern", "crafting_special_repairitem"); private static final ComponentRewriter COMPONENT_REWRITER = new ComponentRewriter(null, ComponentRewriter.ReadType.JSON) { @Override @@ -246,7 +245,7 @@ public class InventoryPackets extends ItemRewriter lore = display.getListTag("Lore", StringTag.class); if (lore != null) { - display.put(NBT_TAG_NAME + "|Lore", new ListTag<>(lore.copy().getValue())); // Save old lore + display.put(nbtTagName("Lore"), new ListTag<>(lore.copy().getValue())); // Save old lore for (StringTag loreEntry : lore) { String jsonText = ComponentUtil.legacyToJsonString(loreEntry.getValue(), true); loreEntry.setValue(jsonText); @@ -268,7 +267,7 @@ public class InventoryPackets extends ItemRewriter lore = display.getListTag("Lore", StringTag.class); if (lore != null) { - Tag savedLore = display.remove(NBT_TAG_NAME + "|Lore"); + Tag savedLore = display.remove(nbtTagName("Lore")); if (savedLore instanceof ListTag) { display.put("Lore", new ListTag<>(((ListTag) savedLore).getValue())); } else { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java index 877dacf58..2ec3147df 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java @@ -60,8 +60,6 @@ import org.checkerframework.checker.nullness.qual.Nullable; public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter { - private final String tagMarker = "VV|" + protocol.getClass().getSimpleName(); - public BlockItemPacketRewriter1_20_5(final Protocol1_20_5To1_20_3 protocol) { super(protocol, Type.ITEM1_20_2, Type.ITEM1_20_2_ARRAY, Types1_20_5.ITEM, Types1_20_5.ITEM_ARRAY); } @@ -318,7 +316,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter