From ced1a65230647c20e3ca40fccfe108399685ccc3 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sat, 9 Mar 2024 13:08:36 +0100 Subject: [PATCH] Replace some generic CompoundTag get usages --- .../viabackwards/api/data/BackwardsMappings.java | 12 ++++++------ .../viabackwards/api/data/VBMappingDataLoader.java | 2 +- .../packets/EntityPackets1_16_2.java | 8 ++++---- .../packets/EntityPackets1_17.java | 10 +++++----- .../packets/EntityPackets1_18.java | 6 +++--- .../data/BackwardsMappings.java | 2 +- .../packets/EntityPackets1_19.java | 14 +++++++------- .../protocol1_18to1_18_2/Protocol1_18To1_18_2.java | 11 +++++------ .../packets/EntityPackets1_19_3.java | 2 +- .../packets/EntityPackets1_19_4.java | 6 +++--- .../packets/EntityPackets1_20.java | 6 +++--- .../protocol1_19to1_19_1/Protocol1_19To1_19_1.java | 2 +- 12 files changed, 40 insertions(+), 41 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/data/BackwardsMappings.java b/common/src/main/java/com/viaversion/viabackwards/api/data/BackwardsMappings.java index 7467bbaf..ca2bb569 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/data/BackwardsMappings.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/data/BackwardsMappings.java @@ -57,19 +57,19 @@ public class BackwardsMappings extends MappingDataBase { @Override protected void loadExtras(final CompoundTag data) { - final CompoundTag itemNames = data.get("itemnames"); + final CompoundTag itemNames = data.getCompoundTag("itemnames"); if (itemNames != null) { Preconditions.checkNotNull(itemMappings); backwardsItemMappings = new Int2ObjectOpenHashMap<>(itemNames.size()); - final CompoundTag extraItemData = data.get("itemdata"); + final CompoundTag extraItemData = data.getCompoundTag("itemdata"); for (final Map.Entry entry : itemNames.entrySet()) { final StringTag name = (StringTag) entry.getValue(); final int id = Integer.parseInt(entry.getKey()); Integer customModelData = null; if (extraItemData != null && extraItemData.contains(entry.getKey())) { - final CompoundTag entryTag = extraItemData.get(entry.getKey()); - final NumberTag customModelDataTag = entryTag.get("custom_model_data"); + final CompoundTag entryTag = extraItemData.getCompoundTag(entry.getKey()); + final NumberTag customModelDataTag = entryTag.getNumberTag("custom_model_data"); customModelData = customModelDataTag != null ? customModelDataTag.asInt() : null; } @@ -77,7 +77,7 @@ public class BackwardsMappings extends MappingDataBase { } } - final CompoundTag entityNames = data.get("entitynames"); + final CompoundTag entityNames = data.getCompoundTag("entitynames"); if (entityNames != null) { this.entityNames = new HashMap<>(entityNames.size()); for (final Map.Entry entry : entityNames.entrySet()) { @@ -86,7 +86,7 @@ public class BackwardsMappings extends MappingDataBase { } } - final CompoundTag soundNames = data.get("soundnames"); + final CompoundTag soundNames = data.getCompoundTag("soundnames"); if (soundNames != null) { backwardsSoundMappings = new HashMap<>(soundNames.size()); for (final Map.Entry entry : soundNames.entrySet()) { diff --git a/common/src/main/java/com/viaversion/viabackwards/api/data/VBMappingDataLoader.java b/common/src/main/java/com/viaversion/viabackwards/api/data/VBMappingDataLoader.java index eac81733..2c89b3a5 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/data/VBMappingDataLoader.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/data/VBMappingDataLoader.java @@ -79,7 +79,7 @@ public final class VBMappingDataLoader { for (final Map.Entry entry : extra.entrySet()) { if (entry.getValue() instanceof CompoundTag) { // For compound tags, don't replace the entire tag - final CompoundTag originalEntry = original.get(entry.getKey()); + final CompoundTag originalEntry = original.getCompoundTag(entry.getKey()); if (originalEntry != null) { mergeTags(originalEntry, (CompoundTag) entry.getValue()); continue; 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 06035e09..c4e09052 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 @@ -75,13 +75,13 @@ public class EntityPackets1_16_2 extends EntityRewriter biomes = biomeRegistry.getListTag("value", CompoundTag.class); BiomeStorage biomeStorage = wrapper.user().get(BiomeStorage.class); biomeStorage.clear(); for (CompoundTag biome : biomes) { - StringTag name = biome.get("name"); - NumberTag id = biome.get("id"); + StringTag name = biome.getStringTag("name"); + NumberTag id = biome.getNumberTag("id"); biomeStorage.addBiome(name.getValue(), id.asInt()); } } else if (!warned) { @@ -114,7 +114,7 @@ public class EntityPackets1_16_2 extends EntityRewriter { CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0); - CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome"); + CompoundTag biomeRegistry = registry.getCompoundTag("minecraft:worldgen/biome"); ListTag biomes = biomeRegistry.getListTag("value", CompoundTag.class); for (CompoundTag biome : biomes) { - CompoundTag biomeCompound = biome.get("element"); - StringTag category = biomeCompound.get("category"); + CompoundTag biomeCompound = biome.getCompoundTag("element"); + StringTag category = biomeCompound.getStringTag("category"); if (category.getValue().equalsIgnoreCase("underground")) { category.setValue("none"); } } - CompoundTag dimensionRegistry = registry.get("minecraft:dimension_type"); + CompoundTag dimensionRegistry = registry.getCompoundTag("minecraft:dimension_type"); ListTag dimensions = dimensionRegistry.getListTag("value", CompoundTag.class); for (CompoundTag dimension : dimensions) { - CompoundTag dimensionCompound = dimension.get("element"); + 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 b2880d01..f5207b10 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 @@ -61,11 +61,11 @@ public final class EntityPackets1_18 extends EntityRewriter { final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0); - final CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome"); + final CompoundTag biomeRegistry = registry.getCompoundTag("minecraft:worldgen/biome"); final ListTag biomes = biomeRegistry.getListTag("value", CompoundTag.class); for (final CompoundTag biome : biomes) { - final CompoundTag biomeCompound = biome.get("element"); - final StringTag category = biomeCompound.get("category"); + final CompoundTag biomeCompound = biome.getCompoundTag("element"); + final StringTag category = biomeCompound.getStringTag("category"); if (category.getValue().equals("mountain")) { category.setValue("extreme_hills"); } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/data/BackwardsMappings.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/data/BackwardsMappings.java index f6a90d14..929a234b 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/data/BackwardsMappings.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/data/BackwardsMappings.java @@ -40,7 +40,7 @@ public final class BackwardsMappings extends com.viaversion.viabackwards.api.dat final ListTag chatTypes = VBMappingDataLoader.loadNBT("chat-types-1.19.1.nbt").getListTag("values", CompoundTag.class); for (final CompoundTag chatType : chatTypes) { - final NumberTag idTag = chatType.get("id"); + final NumberTag idTag = chatType.getNumberTag("id"); defaultChatTypes.put(idTag.asInt(), chatType); } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/packets/EntityPackets1_19.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/packets/EntityPackets1_19.java index 1d580f04..af770d46 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/packets/EntityPackets1_19.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/packets/EntityPackets1_19.java @@ -131,11 +131,11 @@ public final class EntityPackets1_19 extends EntityRewriter dimensions = ((CompoundTag) registry.get("minecraft:dimension_type")).getListTag("value", CompoundTag.class); + final ListTag dimensions = registry.getCompoundTag("minecraft:dimension_type").getListTag("value", CompoundTag.class); boolean found = false; for (final CompoundTag dimension : dimensions) { - final StringTag nameTag = dimension.get("name"); - final CompoundTag dimensionData = dimension.get("element"); + final StringTag nameTag = dimension.getStringTag("name"); + final CompoundTag dimensionData = dimension.getCompoundTag("element"); dimensionRegistryStorage.addDimension(nameTag.getValue(), dimensionData.copy()); if (!found && nameTag.getValue().equals(dimensionKey)) { @@ -148,10 +148,10 @@ public final class EntityPackets1_19 extends EntityRewriter biomes = biomeRegistry.getListTag("value", CompoundTag.class); - for (final CompoundTag biome : biomes.getValue()) { - final CompoundTag biomeCompound = biome.get("element"); + for (final CompoundTag biome : biomes) { + final CompoundTag biomeCompound = biome.getCompoundTag("element"); biomeCompound.putString("category", "none"); } tracker(wrapper.user()).setBiomesSent(biomes.size()); @@ -159,7 +159,7 @@ public final class EntityPackets1_19 extends EntityRewriter chatTypes = ((CompoundTag) registry.remove("minecraft:chat_type")).getListTag("value", CompoundTag.class); for (final CompoundTag chatType : chatTypes) { - final NumberTag idTag = chatType.get("id"); + final NumberTag idTag = chatType.getNumberTag("id"); dimensionRegistryStorage.addChatType(idTag.asInt(), chatType); } }); 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 ac77ff83..8a0713d6 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 @@ -81,10 +81,10 @@ public final class Protocol1_18To1_18_2 extends BackwardsProtocol { final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0); - final CompoundTag dimensionsHolder = registry.get("minecraft:dimension_type"); + final CompoundTag dimensionsHolder = registry.getCompoundTag("minecraft:dimension_type"); final ListTag dimensions = dimensionsHolder.getListTag("value", CompoundTag.class); for (final CompoundTag dimension : dimensions) { - removeTagPrefix(dimension.get("element")); + removeTagPrefix(dimension.getCompoundTag("element")); } removeTagPrefix(wrapper.get(Type.NAMED_COMPOUND_TAG, 1)); @@ -96,10 +96,9 @@ public final class Protocol1_18To1_18_2 extends BackwardsProtocol chatTypes = registry.getCompoundTag("minecraft:chat_type").getListTag("value", CompoundTag.class); for (final CompoundTag chatType : chatTypes) { - final NumberTag idTag = chatType.get("id"); + 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 cc307660..3e1c4bdf 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 @@ -67,11 +67,11 @@ public final class EntityPackets1_19_4 extends EntityRewriter biomes = biomeRegistry.getListTag("value", CompoundTag.class); for (final CompoundTag biomeTag : biomes) { - final CompoundTag biomeData = biomeTag.get("element"); - final NumberTag hasPrecipitation = biomeData.get("has_precipitation"); + final CompoundTag biomeData = biomeTag.getCompoundTag("element"); + final NumberTag hasPrecipitation = biomeData.getNumberTag("has_precipitation"); biomeData.putString("precipitation", hasPrecipitation.asByte() == 1 ? "rain" : "none"); } }); 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 ba45edf5..2268382a 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 @@ -89,12 +89,12 @@ public final class EntityPackets1_20 extends EntityRewriter chatTypes = registry.getCompoundTag("minecraft:chat_type").getListTag("value", CompoundTag.class); for (final CompoundTag chatType : chatTypes) { - final NumberTag idTag = chatType.get("id"); + final NumberTag idTag = chatType.getNumberTag("id"); chatTypeStorage.addChatType(idTag.asInt(), chatType); }