From 11286b216224970d6649186f21da8ac8c4a9db67 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sat, 20 Apr 2024 12:12:35 +0200 Subject: [PATCH] Fall back to keys without namespace in registry data --- .../packets/EntityPackets1_16_2.java | 5 ++--- .../protocol1_16_4to1_17/packets/EntityPackets1_17.java | 7 +++---- .../protocol1_17_1to1_18/packets/EntityPackets1_18.java | 4 ++-- .../protocol1_18_2to1_19/Protocol1_18_2To1_19.java | 4 +--- .../protocol1_18_2to1_19/packets/EntityPackets1_19.java | 6 +++--- .../protocol1_18to1_18_2/Protocol1_18To1_18_2.java | 5 ++--- .../packets/EntityPackets1_19_3.java | 4 ++-- .../packets/EntityPackets1_19_4.java | 5 ++--- .../protocol1_19_4to1_20/packets/EntityPackets1_20.java | 4 ++-- .../protocol1_19to1_19_1/Protocol1_19To1_19_1.java | 3 ++- 10 files changed, 21 insertions(+), 26 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/EntityPackets1_16_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/EntityPackets1_16_2.java index 50a56a95..cc941c3a 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/EntityPackets1_16_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/EntityPackets1_16_2.java @@ -33,9 +33,9 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; -import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.EntityPackets; +import com.viaversion.viaversion.util.TagUtil; import java.util.Set; public class EntityPackets1_16_2 extends EntityRewriter { @@ -75,8 +75,7 @@ public class EntityPackets1_16_2 extends EntityRewriter biomes = biomeRegistry.getListTag("value", CompoundTag.class); + ListTag biomes = TagUtil.getRegistryEntries(registry, "worldgen/biome"); BiomeStorage biomeStorage = wrapper.user().get(BiomeStorage.class); biomeStorage.clear(); for (CompoundTag biome : biomes) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java index f5c76ea9..1fd22c0a 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java @@ -32,6 +32,7 @@ import com.viaversion.viaversion.api.type.types.version.Types1_17; import com.viaversion.viaversion.libs.opennbt.tag.builtin.*; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17; +import com.viaversion.viaversion.util.TagUtil; public final class EntityPackets1_17 extends EntityRewriter { @@ -80,8 +81,7 @@ public final class EntityPackets1_17 extends EntityRewriter { CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0); - CompoundTag biomeRegistry = registry.getCompoundTag("minecraft:worldgen/biome"); - ListTag biomes = biomeRegistry.getListTag("value", CompoundTag.class); + ListTag biomes = TagUtil.getRegistryEntries(registry, "worldgen/biome"); for (CompoundTag biome : biomes) { CompoundTag biomeCompound = biome.getCompoundTag("element"); StringTag category = biomeCompound.getStringTag("category"); @@ -90,8 +90,7 @@ public final class EntityPackets1_17 extends EntityRewriter dimensions = dimensionRegistry.getListTag("value", CompoundTag.class); + ListTag dimensions = TagUtil.getRegistryEntries(registry, "dimension_type"); for (CompoundTag dimension : dimensions) { CompoundTag dimensionCompound = dimension.getCompoundTag("element"); reduceExtendedHeight(dimensionCompound, false); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_17_1to1_18/packets/EntityPackets1_18.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_17_1to1_18/packets/EntityPackets1_18.java index f5207b10..c97f6113 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_17_1to1_18/packets/EntityPackets1_18.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_17_1to1_18/packets/EntityPackets1_18.java @@ -32,6 +32,7 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18; +import com.viaversion.viaversion.util.TagUtil; public final class EntityPackets1_18 extends EntityRewriter { @@ -61,8 +62,7 @@ public final class EntityPackets1_18 extends EntityRewriter { final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0); - final CompoundTag biomeRegistry = registry.getCompoundTag("minecraft:worldgen/biome"); - final ListTag biomes = biomeRegistry.getListTag("value", CompoundTag.class); + final ListTag biomes = TagUtil.getRegistryEntries(registry, "worldgen/biome"); for (final CompoundTag biome : biomes) { final CompoundTag biomeCompound = biome.getCompoundTag("element"); final StringTag category = biomeCompound.getStringTag("category"); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/Protocol1_18_2To1_19.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/Protocol1_18_2To1_19.java index 67990a89..f688332a 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/Protocol1_18_2To1_19.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/Protocol1_18_2To1_19.java @@ -290,9 +290,7 @@ public final class Protocol1_18_2To1_19 extends BackwardsProtocol { @@ -131,7 +132,7 @@ public final class EntityPackets1_19 extends EntityRewriter dimensions = registry.getCompoundTag("minecraft:dimension_type").getListTag("value", CompoundTag.class); + final ListTag dimensions = TagUtil.getRegistryEntries(registry, "dimension_type"); boolean found = false; for (final CompoundTag dimension : dimensions) { final StringTag nameTag = dimension.getStringTag("name"); @@ -148,8 +149,7 @@ public final class EntityPackets1_19 extends EntityRewriter biomes = biomeRegistry.getListTag("value", CompoundTag.class); + final ListTag biomes = TagUtil.getRegistryEntries(registry, "worldgen/biome"); for (final CompoundTag biome : biomes) { final CompoundTag biomeCompound = biome.getCompoundTag("element"); biomeCompound.putString("category", "none"); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18to1_18_2/Protocol1_18To1_18_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18to1_18_2/Protocol1_18To1_18_2.java index 8a0713d6..bdbc8671 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18to1_18_2/Protocol1_18To1_18_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18to1_18_2/Protocol1_18To1_18_2.java @@ -27,9 +27,9 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; -import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; 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.util.TagUtil; public final class Protocol1_18To1_18_2 extends BackwardsProtocol { @@ -81,8 +81,7 @@ public final class Protocol1_18To1_18_2 extends BackwardsProtocol { 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) { removeTagPrefix(dimension.getCompoundTag("element")); } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/packets/EntityPackets1_19_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/packets/EntityPackets1_19_3.java index ac5d63e2..0f05e0e4 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/packets/EntityPackets1_19_3.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/packets/EntityPackets1_19_3.java @@ -35,10 +35,10 @@ import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; -import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ClientboundPackets1_19_1; import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3; import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ServerboundPackets1_19_3; +import com.viaversion.viaversion.util.TagUtil; import java.util.BitSet; import java.util.UUID; import org.checkerframework.checker.nullness.qual.Nullable; @@ -82,7 +82,7 @@ public final class EntityPackets1_19_3 extends EntityRewriter 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/viabackwards/protocol/protocol1_19_3to1_19_4/packets/EntityPackets1_19_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/packets/EntityPackets1_19_4.java index 3e1c4bdf..a7e89351 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/packets/EntityPackets1_19_4.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/packets/EntityPackets1_19_4.java @@ -31,9 +31,9 @@ import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; -import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3; import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4; +import com.viaversion.viaversion.util.TagUtil; public final class EntityPackets1_19_4 extends EntityRewriter { @@ -67,8 +67,7 @@ public final class EntityPackets1_19_4 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 NumberTag hasPrecipitation = biomeData.getNumberTag("has_precipitation"); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/packets/EntityPackets1_20.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/packets/EntityPackets1_20.java index 2268382a..d02a30ba 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/packets/EntityPackets1_20.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/packets/EntityPackets1_20.java @@ -83,8 +83,8 @@ public final class EntityPackets1_20 extends EntityRewriter values; // A 1.20 server can't send this element, and the 1.20 client still works, if the element is missing // on a 1.19.4 client there is an exception, so in case the 1.20 server doesn't send the element we put in an original 1.20 element - final CompoundTag trimPatternTag = registry.getCompoundTag("minecraft:trim_pattern"); - if (trimPatternTag != null) { + CompoundTag trimPatternTag = registry.getCompoundTag("minecraft:trim_pattern"); + if (trimPatternTag != null || (trimPatternTag = registry.getCompoundTag("trim_pattern")) != null) { values = trimPatternTag.getListTag("value", CompoundTag.class); } else { final CompoundTag trimPatternRegistry = Protocol1_19_4To1_20.MAPPINGS.getTrimPatternRegistry().copy(); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/Protocol1_19To1_19_1.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/Protocol1_19To1_19_1.java index ef1fb750..181cbc6c 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/Protocol1_19To1_19_1.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/Protocol1_19To1_19_1.java @@ -55,6 +55,7 @@ import com.viaversion.viaversion.rewriter.ComponentRewriter; import com.viaversion.viaversion.util.CipherUtil; import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.Pair; +import com.viaversion.viaversion.util.TagUtil; import java.util.List; import java.util.UUID; import org.checkerframework.checker.nullness.qual.Nullable; @@ -102,7 +103,7 @@ public final class Protocol1_19To1_19_1 extends BackwardsProtocol 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);