From 67ae00faeb920e3273a87fd105fd2af4080a9563 Mon Sep 17 00:00:00 2001 From: EnZaXD <60033407+FlorianMichael@users.noreply.github.com> Date: Tue, 30 Apr 2024 18:29:45 +0200 Subject: [PATCH] Add support for different mapping types with same id (#731) --- .../api/data/MappedLegacyBlockItem.java | 6 --- .../rewriters/LegacyBlockItemRewriter.java | 45 ++++++++++++------- .../packets/BlockItemPackets1_11.java | 2 +- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/data/MappedLegacyBlockItem.java b/common/src/main/java/com/viaversion/viabackwards/api/data/MappedLegacyBlockItem.java index b5027e2e..fc4f4545 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/data/MappedLegacyBlockItem.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/data/MappedLegacyBlockItem.java @@ -27,7 +27,6 @@ public class MappedLegacyBlockItem { private final short data; private final String name; private final IdAndData block; - private final Type type; private BlockEntityHandler blockEntityHandler; public MappedLegacyBlockItem(int id) { @@ -39,7 +38,6 @@ public class MappedLegacyBlockItem { this.data = data; this.name = name != null ? "§f" + name : null; this.block = type != Type.ITEM ? data != -1 ? new IdAndData(id, data) : new IdAndData(id) : null; - this.type = type; } public int getId() { @@ -54,10 +52,6 @@ public class MappedLegacyBlockItem { return name; } - public Type getType() { - return type; - } - public IdAndData getBlock() { return block; } diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java index b4240e0e..047cd438 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java @@ -57,14 +57,20 @@ import org.checkerframework.checker.nullness.qual.Nullable; public abstract class LegacyBlockItemRewriter> extends BackwardsItemRewriterBase { - protected final Int2ObjectMap replacementData = new Int2ObjectOpenHashMap<>(8); // Raw id -> mapped data + protected final Int2ObjectMap itemReplacements = new Int2ObjectOpenHashMap<>(8); // Raw id -> mapped data + protected final Int2ObjectMap blockReplacements = new Int2ObjectOpenHashMap<>(8); // Raw id -> mapped data protected LegacyBlockItemRewriter(T protocol, String name, Type itemType, Type itemArrayType, Type mappedItemType, Type mappedItemArrayType) { super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType, false); + + Int2ObjectMap blockItemReplacements = new Int2ObjectOpenHashMap<>(8); final JsonObject jsonObject = readMappingsFile("item-mappings-" + name + ".json"); - for (final MappedLegacyBlockItem.Type value : MappedLegacyBlockItem.Type.values()) { - addMappings(value, jsonObject, replacementData); - } + addMappings(MappedLegacyBlockItem.Type.ITEM, jsonObject, itemReplacements); + addMappings(MappedLegacyBlockItem.Type.BLOCK_ITEM, jsonObject, blockItemReplacements); + addMappings(MappedLegacyBlockItem.Type.BLOCK, jsonObject, blockReplacements); + + blockReplacements.putAll(blockItemReplacements); + itemReplacements.putAll(blockItemReplacements); } protected LegacyBlockItemRewriter(T protocol, String name, Type itemType, Type itemArrayType) { @@ -160,8 +166,8 @@ public abstract class LegacyBlockItemRewriter new MappedLegacyBlockItem(52)); + MappedLegacyBlockItem data = itemReplacements.computeIfAbsent(IdAndData.toRawData(52), s -> new MappedLegacyBlockItem(52)); data.setBlockEntityHandler((b, tag) -> { EntityIdRewriter.toClientSpawner(tag, true); return tag;