From ba2e50cc880258533294f36117255f00f137e058 Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Mon, 8 Apr 2024 13:31:13 +0200 Subject: [PATCH] Fix StructuredDataConverter#removeItemBackupTag --- .../BlockItemPacketRewriter1_20_5.java | 6 +++--- .../rewriter/StructuredDataConverter.java | 18 +++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) 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 1b75e8ec9..060e115b6 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 @@ -851,7 +851,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter, DataConverter> rewriters = new Reference2ObjectOpenHashMap<>(); @@ -461,7 +461,7 @@ public final class StructuredDataConverter { final String ingredientName = toMappedItemName(material.itemId()); if (ingredientName.isEmpty()) { - getBackupTag(materialTag).putInt(ITEM_TAG_KEY, material.itemId()); + getBackupTag(materialTag).putInt(ITEM_BACKUP_TAG_KEY, material.itemId()); } materialTag.putString("ingredient", ingredientName); materialTag.put("item_model_index", new FloatTag(material.itemModelIndex())); @@ -487,7 +487,7 @@ public final class StructuredDataConverter { patternTag.putString("assetId", pattern.assetName()); final String itemName = toMappedItemName(pattern.itemId()); if (itemName.isEmpty()) { - getBackupTag(patternTag).putInt(ITEM_TAG_KEY, pattern.itemId()); + getBackupTag(patternTag).putInt(ITEM_BACKUP_TAG_KEY, pattern.itemId()); } patternTag.putString("templateItem", itemName); patternTag.put("description", pattern.description()); @@ -642,12 +642,16 @@ public final class StructuredDataConverter { return backupTag; } - static int getBackupItemId(final CompoundTag tag, final int unmappedId) { + static int removeItemBackupTag(final CompoundTag tag, final int unmappedId) { if (unmappedId != -1) { return unmappedId; } - final IntTag itemIdTag = tag.getIntTag(ITEM_TAG_KEY); - return itemIdTag != null ? itemIdTag.getTagId() : -1; + final IntTag itemBackupTag = tag.getIntTag(ITEM_BACKUP_TAG_KEY); + if (itemBackupTag != null) { + tag.remove(ITEM_BACKUP_TAG_KEY); + return itemBackupTag.asInt(); + } + return -1; } private void convertBlockPredicates(final CompoundTag tag, final AdventureModePredicate data, final String key, final int hideFlag) { @@ -727,7 +731,7 @@ public final class StructuredDataConverter { final String name = toMappedItemName(item.identifier()); savedItem.putString("id", name); if (name.isEmpty()) { - savedItem.putInt(ITEM_TAG_KEY, item.identifier()); + savedItem.putInt(ITEM_BACKUP_TAG_KEY, item.identifier()); } savedItem.putByte("Count", (byte) item.amount());