From bff1536529f904cb7d2a005c0b67309b53bf757d Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sat, 20 Apr 2024 12:06:39 +0200 Subject: [PATCH] Fall back to keys without namespace in registry data --- .../protocol1_16_2to1_16_1/data/MappingData.java | 3 ++- .../protocol1_17to1_16_4/packets/EntityPackets.java | 5 +++-- .../protocol1_18_2to1_18/Protocol1_18_2To1_18.java | 5 ++--- .../protocol1_19_1to1_19/Protocol1_19_1To1_19.java | 3 ++- .../packets/EntityPackets.java | 4 ++-- .../protocol1_19to1_18_2/packets/EntityPackets.java | 3 ++- .../rewriter/EntityPacketRewriter1_20_5.java | 5 +++-- .../protocol1_20to1_19_4/packets/EntityPackets.java | 4 ++-- .../viaversion/rewriter/EntityRewriter.java | 12 ++++++------ .../java/com/viaversion/viaversion/util/TagUtil.java | 10 ++++++++-- 10 files changed, 32 insertions(+), 22 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/data/MappingData.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/data/MappingData.java index 583ac36ff..ac5593a3b 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/data/MappingData.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/data/MappingData.java @@ -21,6 +21,7 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.viaversion.viaversion.api.data.MappingDataBase; import com.viaversion.viaversion.api.data.MappingDataLoader; +import com.viaversion.viaversion.util.TagUtil; import java.util.HashMap; import java.util.Map; @@ -37,7 +38,7 @@ public class MappingData extends MappingDataBase { dimensionRegistry = MappingDataLoader.INSTANCE.loadNBTFromFile("dimension-registry-1.16.2.nbt"); // Data of each dimension - final ListTag dimensions = dimensionRegistry.getCompoundTag("minecraft:dimension_type").getListTag("value", CompoundTag.class); + final ListTag dimensions = TagUtil.getRegistryEntries(dimensionRegistry, "dimension_type"); for (final CompoundTag dimension : dimensions) { // Copy with an empty name final CompoundTag dimensionData = dimension.getCompoundTag("element").copy(); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/EntityPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/EntityPackets.java index 36ae78f52..13fa06e6f 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/EntityPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/EntityPackets.java @@ -34,6 +34,7 @@ import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPac import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4; import com.viaversion.viaversion.rewriter.EntityRewriter; +import com.viaversion.viaversion.util.TagUtil; public final class EntityPackets extends EntityRewriter { @@ -76,8 +77,8 @@ public final class EntityPackets extends EntityRewriter { // Add new dimension fields - CompoundTag dimensionRegistry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0).getCompoundTag("minecraft:dimension_type"); - ListTag dimensions = dimensionRegistry.getListTag("value", CompoundTag.class); + CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0); + ListTag dimensions = TagUtil.getRegistryEntries(registry, "dimension_type"); for (CompoundTag dimension : dimensions) { CompoundTag dimensionCompound = dimension.getCompoundTag("element"); addNewDimensionData(dimensionCompound); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18_2to1_18/Protocol1_18_2To1_18.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18_2to1_18/Protocol1_18_2To1_18.java index 8d7f61e00..151df0856 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18_2to1_18/Protocol1_18_2To1_18.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18_2to1_18/Protocol1_18_2To1_18.java @@ -28,10 +28,10 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17; import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18; import com.viaversion.viaversion.rewriter.TagRewriter; +import com.viaversion.viaversion.util.TagUtil; public final class Protocol1_18_2To1_18 extends AbstractProtocol { - public Protocol1_18_2To1_18() { super(ClientboundPackets1_18.class, ClientboundPackets1_18.class, ServerboundPackets1_17.class, ServerboundPackets1_17.class); } @@ -70,8 +70,7 @@ public final class Protocol1_18_2To1_18 extends AbstractProtocol { final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0); - final CompoundTag dimensionsHolder = registry.getCompoundTag("minecraft:dimension_type"); - final ListTag dimensions = dimensionsHolder.getListTag("value", CompoundTag.class); + final ListTag dimensions = TagUtil.getRegistryEntries(registry, "dimension_type"); for (final CompoundTag dimension : dimensions) { addTagPrefix(dimension.getCompoundTag("element")); } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_1to1_19/Protocol1_19_1To1_19.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_1to1_19/Protocol1_19_1To1_19.java index 0d61cb445..5ef23ed4d 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_1to1_19/Protocol1_19_1To1_19.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_1to1_19/Protocol1_19_1To1_19.java @@ -45,6 +45,7 @@ import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ClientboundPacke import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ServerboundPackets1_19; import com.viaversion.viaversion.util.CipherUtil; import com.viaversion.viaversion.util.Pair; +import com.viaversion.viaversion.util.TagUtil; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -189,7 +190,7 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol chatTypes = registry.getCompoundTag("minecraft:chat_type").getListTag("value", CompoundTag.class); + final ListTag chatTypes = TagUtil.getRegistryEntries(registry, "chat_type"); for (final CompoundTag chatType : chatTypes) { final NumberTag idTag = chatType.getNumberTag("id"); chatTypeStorage.addChatType(idTag.asInt(), chatType); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/packets/EntityPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/packets/EntityPackets.java index 71cabf5c7..6826fcdb7 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/packets/EntityPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/packets/EntityPackets.java @@ -33,6 +33,7 @@ import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPac import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.Protocol1_19_4To1_19_3; import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.storage.PlayerVehicleTracker; import com.viaversion.viaversion.rewriter.EntityRewriter; +import com.viaversion.viaversion.util.TagUtil; public final class EntityPackets extends EntityRewriter { @@ -62,8 +63,7 @@ public final class EntityPackets extends EntityRewriter biomes = biomeRegistry.getListTag("value", CompoundTag.class); + final ListTag biomes = TagUtil.getRegistryEntries(registry, "worldgen/biome"); for (final CompoundTag biomeTag : biomes) { final CompoundTag biomeData = biomeTag.getCompoundTag("element"); final StringTag precipitation = biomeData.getStringTag("precipitation"); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java index 6ad9ab3bb..216175f30 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java @@ -44,6 +44,7 @@ import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.storage.Dimensio import com.viaversion.viaversion.rewriter.EntityRewriter; import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.Pair; +import com.viaversion.viaversion.util.TagUtil; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; @@ -178,7 +179,7 @@ public final class EntityPackets extends EntityRewriter dimensions = tag.getCompoundTag("minecraft:dimension_type").getListTag("value", CompoundTag.class); + final ListTag dimensions = TagUtil.getRegistryEntries(tag, "dimension_type"); final Map dimensionDataMap = new HashMap<>(dimensions.size()); final Map dimensionsMap = new HashMap<>(dimensions.size()); for (final CompoundTag dimension : dimensions) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java index f7e6592df..a7fbc05c0 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java @@ -44,6 +44,7 @@ import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.Clientb import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.storage.AcknowledgedMessagesStorage; import com.viaversion.viaversion.rewriter.EntityRewriter; import com.viaversion.viaversion.util.Key; +import com.viaversion.viaversion.util.TagUtil; import java.util.Arrays; import java.util.Map; import java.util.UUID; @@ -75,7 +76,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter dimensionTypes = registryData.getCompoundTag("minecraft:dimension_type").getListTag("value", CompoundTag.class); + final ListTag dimensionTypes = TagUtil.getRegistryEntries(registryData, "dimension_type"); for (final CompoundTag dimensionType : dimensionTypes) { final CompoundTag elementTag = dimensionType.getCompoundTag("element"); final CompoundTag monsterSpawnLightLevel = elementTag.getCompoundTag("monster_spawn_light_level"); @@ -87,7 +88,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter biomes = registryData.getCompoundTag("minecraft:worldgen/biome").getListTag("value", CompoundTag.class); + final ListTag biomes = TagUtil.getRegistryEntries(registryData, "worldgen/biome"); for (final CompoundTag biome : biomes) { final CompoundTag effects = biome.getCompoundTag("element").getCompoundTag("effects"); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20to1_19_4/packets/EntityPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20to1_19_4/packets/EntityPackets.java index 557991906..f100b3b03 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20to1_19_4/packets/EntityPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20to1_19_4/packets/EntityPackets.java @@ -33,6 +33,7 @@ import com.viaversion.viaversion.api.type.types.version.Types1_20; import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4; import com.viaversion.viaversion.protocols.protocol1_20to1_19_4.Protocol1_20To1_19_4; import com.viaversion.viaversion.rewriter.EntityRewriter; +import com.viaversion.viaversion.util.TagUtil; public final class EntityPackets extends EntityRewriter { @@ -75,8 +76,7 @@ public final class EntityPackets extends EntityRewriter { final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0); - final CompoundTag damageTypeRegistry = registry.getCompoundTag("minecraft:damage_type"); - final ListTag damageTypes = damageTypeRegistry.getListTag("value", CompoundTag.class); + final ListTag damageTypes = TagUtil.getRegistryEntries(registry, "damage_type"); int highestId = -1; for (final CompoundTag damageType : damageTypes) { final IntTag id = damageType.getUnchecked("id"); diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java index 6ab90d9e8..f22c28326 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java @@ -48,6 +48,7 @@ import com.viaversion.viaversion.rewriter.meta.MetaFilter; import com.viaversion.viaversion.rewriter.meta.MetaHandlerEvent; import com.viaversion.viaversion.rewriter.meta.MetaHandlerEventImpl; import com.viaversion.viaversion.util.Key; +import com.viaversion.viaversion.util.TagUtil; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; @@ -205,9 +206,9 @@ public abstract class EntityRewriter biomes = biomeRegistry.getListTag("value"); + final ListTag biomes = TagUtil.getRegistryEntries(registry, "worldgen/biome"); tracker(connection).setBiomesSent(biomes.size()); } @@ -508,7 +508,7 @@ public abstract class EntityRewriter dimensions = registry.getCompoundTag("minecraft:dimension_type").getListTag("value", CompoundTag.class); + final ListTag dimensions = TagUtil.getRegistryEntries(registry, "dimension_type"); final Map dimensionDataMap = new HashMap<>(dimensions.size()); for (final CompoundTag dimension : dimensions) { final NumberTag idTag = dimension.getNumberTag("id"); diff --git a/common/src/main/java/com/viaversion/viaversion/util/TagUtil.java b/common/src/main/java/com/viaversion/viaversion/util/TagUtil.java index 2bfd4ed54..4da146dda 100644 --- a/common/src/main/java/com/viaversion/viaversion/util/TagUtil.java +++ b/common/src/main/java/com/viaversion/viaversion/util/TagUtil.java @@ -21,12 +21,18 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.Tag; import java.util.Map; -import net.lenni0451.mcstructs.snbt.exceptions.SNbtDeserializeException; -import net.lenni0451.mcstructs.snbt.exceptions.SNbtSerializeException; import org.checkerframework.checker.nullness.qual.Nullable; public final class TagUtil { + public static ListTag getRegistryEntries(final CompoundTag tag, final String key) { + CompoundTag registry = tag.getCompoundTag(Key.namespaced(key)); + if (registry == null) { + registry = tag.getCompoundTag(Key.stripMinecraftNamespace(key)); + } + return registry.getListTag("value", CompoundTag.class); + } + public static Tag handleDeep(final Tag tag, final TagUpdater consumer) { return handleDeep(null, tag, consumer); }