Skip to content

Commit ced1a65

Browse files
committed
Replace some generic CompoundTag get usages
1 parent c6ea04f commit ced1a65

File tree

12 files changed

+40
-41
lines changed

12 files changed

+40
-41
lines changed

common/src/main/java/com/viaversion/viabackwards/api/data/BackwardsMappings.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,27 @@ public BackwardsMappings(final String unmappedVersion, final String mappedVersio
5757

5858
@Override
5959
protected void loadExtras(final CompoundTag data) {
60-
final CompoundTag itemNames = data.get("itemnames");
60+
final CompoundTag itemNames = data.getCompoundTag("itemnames");
6161
if (itemNames != null) {
6262
Preconditions.checkNotNull(itemMappings);
6363
backwardsItemMappings = new Int2ObjectOpenHashMap<>(itemNames.size());
6464

65-
final CompoundTag extraItemData = data.get("itemdata");
65+
final CompoundTag extraItemData = data.getCompoundTag("itemdata");
6666
for (final Map.Entry<String, Tag> entry : itemNames.entrySet()) {
6767
final StringTag name = (StringTag) entry.getValue();
6868
final int id = Integer.parseInt(entry.getKey());
6969
Integer customModelData = null;
7070
if (extraItemData != null && extraItemData.contains(entry.getKey())) {
71-
final CompoundTag entryTag = extraItemData.get(entry.getKey());
72-
final NumberTag customModelDataTag = entryTag.get("custom_model_data");
71+
final CompoundTag entryTag = extraItemData.getCompoundTag(entry.getKey());
72+
final NumberTag customModelDataTag = entryTag.getNumberTag("custom_model_data");
7373
customModelData = customModelDataTag != null ? customModelDataTag.asInt() : null;
7474
}
7575

7676
backwardsItemMappings.put(id, new MappedItem(getNewItemId(id), name.getValue(), customModelData));
7777
}
7878
}
7979

80-
final CompoundTag entityNames = data.get("entitynames");
80+
final CompoundTag entityNames = data.getCompoundTag("entitynames");
8181
if (entityNames != null) {
8282
this.entityNames = new HashMap<>(entityNames.size());
8383
for (final Map.Entry<String, Tag> entry : entityNames.entrySet()) {
@@ -86,7 +86,7 @@ protected void loadExtras(final CompoundTag data) {
8686
}
8787
}
8888

89-
final CompoundTag soundNames = data.get("soundnames");
89+
final CompoundTag soundNames = data.getCompoundTag("soundnames");
9090
if (soundNames != null) {
9191
backwardsSoundMappings = new HashMap<>(soundNames.size());
9292
for (final Map.Entry<String, Tag> entry : soundNames.entrySet()) {

common/src/main/java/com/viaversion/viabackwards/api/data/VBMappingDataLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private static CompoundTag mergeTags(final CompoundTag original, final CompoundT
7979
for (final Map.Entry<String, Tag> entry : extra.entrySet()) {
8080
if (entry.getValue() instanceof CompoundTag) {
8181
// For compound tags, don't replace the entire tag
82-
final CompoundTag originalEntry = original.get(entry.getKey());
82+
final CompoundTag originalEntry = original.getCompoundTag(entry.getKey());
8383
if (originalEntry != null) {
8484
mergeTags(originalEntry, (CompoundTag) entry.getValue());
8585
continue;

common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/EntityPackets1_16_2.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ public void register() {
7575
CompoundTag registry = wrapper.read(Type.NAMED_COMPOUND_TAG);
7676
if (wrapper.user().getProtocolInfo().getProtocolVersion() <= ProtocolVersion.v1_15_2.getVersion()) {
7777
// Store biomes for <1.16 client handling
78-
CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
78+
CompoundTag biomeRegistry = registry.getCompoundTag("minecraft:worldgen/biome");
7979
ListTag<CompoundTag> biomes = biomeRegistry.getListTag("value", CompoundTag.class);
8080
BiomeStorage biomeStorage = wrapper.user().get(BiomeStorage.class);
8181
biomeStorage.clear();
8282
for (CompoundTag biome : biomes) {
83-
StringTag name = biome.get("name");
84-
NumberTag id = biome.get("id");
83+
StringTag name = biome.getStringTag("name");
84+
NumberTag id = biome.getNumberTag("id");
8585
biomeStorage.addBiome(name.getValue(), id.asInt());
8686
}
8787
} else if (!warned) {
@@ -114,7 +114,7 @@ public void register() {
114114

115115
private String getDimensionFromData(CompoundTag dimensionData) {
116116
// This may technically break other custom dimension settings for 1.16/1.16.1 clients, so those cases are considered semi "unsupported" here
117-
StringTag effectsLocation = dimensionData.get("effects");
117+
StringTag effectsLocation = dimensionData.getStringTag("effects");
118118
return effectsLocation != null && oldDimensions.contains(effectsLocation.getValue()) ?
119119
effectsLocation.getValue() : "minecraft:overworld";
120120
}

common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,20 @@ public void register() {
8484
handler(worldDataTrackerHandler(1));
8585
handler(wrapper -> {
8686
CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
87-
CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
87+
CompoundTag biomeRegistry = registry.getCompoundTag("minecraft:worldgen/biome");
8888
ListTag<CompoundTag> biomes = biomeRegistry.getListTag("value", CompoundTag.class);
8989
for (CompoundTag biome : biomes) {
90-
CompoundTag biomeCompound = biome.get("element");
91-
StringTag category = biomeCompound.get("category");
90+
CompoundTag biomeCompound = biome.getCompoundTag("element");
91+
StringTag category = biomeCompound.getStringTag("category");
9292
if (category.getValue().equalsIgnoreCase("underground")) {
9393
category.setValue("none");
9494
}
9595
}
9696

97-
CompoundTag dimensionRegistry = registry.get("minecraft:dimension_type");
97+
CompoundTag dimensionRegistry = registry.getCompoundTag("minecraft:dimension_type");
9898
ListTag<CompoundTag> dimensions = dimensionRegistry.getListTag("value", CompoundTag.class);
9999
for (CompoundTag dimension : dimensions) {
100-
CompoundTag dimensionCompound = dimension.get("element");
100+
CompoundTag dimensionCompound = dimension.getCompoundTag("element");
101101
reduceExtendedHeight(dimensionCompound, false);
102102
}
103103

common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_17_1to1_18/packets/EntityPackets1_18.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ public void register() {
6161
handler(worldDataTrackerHandler(1));
6262
handler(wrapper -> {
6363
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
64-
final CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
64+
final CompoundTag biomeRegistry = registry.getCompoundTag("minecraft:worldgen/biome");
6565
final ListTag<CompoundTag> biomes = biomeRegistry.getListTag("value", CompoundTag.class);
6666
for (final CompoundTag biome : biomes) {
67-
final CompoundTag biomeCompound = biome.get("element");
68-
final StringTag category = biomeCompound.get("category");
67+
final CompoundTag biomeCompound = biome.getCompoundTag("element");
68+
final StringTag category = biomeCompound.getStringTag("category");
6969
if (category.getValue().equals("mountain")) {
7070
category.setValue("extreme_hills");
7171
}

common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/data/BackwardsMappings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected void loadExtras(final CompoundTag data) {
4040

4141
final ListTag<CompoundTag> chatTypes = VBMappingDataLoader.loadNBT("chat-types-1.19.1.nbt").getListTag("values", CompoundTag.class);
4242
for (final CompoundTag chatType : chatTypes) {
43-
final NumberTag idTag = chatType.get("id");
43+
final NumberTag idTag = chatType.getNumberTag("id");
4444
defaultChatTypes.put(idTag.asInt(), chatType);
4545
}
4646
}

common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/packets/EntityPackets1_19.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ public void register() {
131131
// Cache dimensions and find current dimension
132132
final String dimensionKey = wrapper.read(Type.STRING);
133133
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
134-
final ListTag<CompoundTag> dimensions = ((CompoundTag) registry.get("minecraft:dimension_type")).getListTag("value", CompoundTag.class);
134+
final ListTag<CompoundTag> dimensions = registry.getCompoundTag("minecraft:dimension_type").getListTag("value", CompoundTag.class);
135135
boolean found = false;
136136
for (final CompoundTag dimension : dimensions) {
137-
final StringTag nameTag = dimension.get("name");
138-
final CompoundTag dimensionData = dimension.get("element");
137+
final StringTag nameTag = dimension.getStringTag("name");
138+
final CompoundTag dimensionData = dimension.getCompoundTag("element");
139139
dimensionRegistryStorage.addDimension(nameTag.getValue(), dimensionData.copy());
140140

141141
if (!found && nameTag.getValue().equals(dimensionKey)) {
@@ -148,18 +148,18 @@ public void register() {
148148
}
149149

150150
// Add biome category and track biomes
151-
final CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
151+
final CompoundTag biomeRegistry = registry.getCompoundTag("minecraft:worldgen/biome");
152152
final ListTag<CompoundTag> biomes = biomeRegistry.getListTag("value", CompoundTag.class);
153-
for (final CompoundTag biome : biomes.getValue()) {
154-
final CompoundTag biomeCompound = biome.get("element");
153+
for (final CompoundTag biome : biomes) {
154+
final CompoundTag biomeCompound = biome.getCompoundTag("element");
155155
biomeCompound.putString("category", "none");
156156
}
157157
tracker(wrapper.user()).setBiomesSent(biomes.size());
158158

159159
// Cache and remove chat types
160160
final ListTag<CompoundTag> chatTypes = ((CompoundTag) registry.remove("minecraft:chat_type")).getListTag("value", CompoundTag.class);
161161
for (final CompoundTag chatType : chatTypes) {
162-
final NumberTag idTag = chatType.get("id");
162+
final NumberTag idTag = chatType.getNumberTag("id");
163163
dimensionRegistryStorage.addChatType(idTag.asInt(), chatType);
164164
}
165165
});

common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18to1_18_2/Protocol1_18To1_18_2.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ public void register() {
8181
map(Type.NAMED_COMPOUND_TAG); // Current dimension data
8282
handler(wrapper -> {
8383
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
84-
final CompoundTag dimensionsHolder = registry.get("minecraft:dimension_type");
84+
final CompoundTag dimensionsHolder = registry.getCompoundTag("minecraft:dimension_type");
8585
final ListTag<CompoundTag> dimensions = dimensionsHolder.getListTag("value", CompoundTag.class);
8686
for (final CompoundTag dimension : dimensions) {
87-
removeTagPrefix(dimension.get("element"));
87+
removeTagPrefix(dimension.getCompoundTag("element"));
8888
}
8989

9090
removeTagPrefix(wrapper.get(Type.NAMED_COMPOUND_TAG, 1));
@@ -96,10 +96,9 @@ public void register() {
9696
}
9797

9898
private void removeTagPrefix(CompoundTag tag) {
99-
final Tag infiniburnTag = tag.get("infiniburn");
100-
if (infiniburnTag instanceof StringTag) {
101-
final StringTag infiniburn = (StringTag) infiniburnTag;
102-
infiniburn.setValue(infiniburn.getValue().substring(1));
99+
final StringTag infiniburnTag = tag.getStringTag("infiniburn");
100+
if (infiniburnTag != null) {
101+
infiniburnTag.setValue(infiniburnTag.getValue().substring(1));
103102
}
104103
}
105104
}

common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/packets/EntityPackets1_19_3.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void register() {
8484
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
8585
final ListTag<CompoundTag> chatTypes = registry.getCompoundTag("minecraft:chat_type").getListTag("value", CompoundTag.class);
8686
for (final CompoundTag chatType : chatTypes) {
87-
final NumberTag idTag = chatType.get("id");
87+
final NumberTag idTag = chatType.getNumberTag("id");
8888
chatTypeStorage.addChatType(idTag.asInt(), chatType);
8989
}
9090
});

common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/packets/EntityPackets1_19_4.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ public void register() {
6767
registry.remove("minecraft:trim_material");
6868
registry.remove("minecraft:damage_type");
6969

70-
final CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
70+
final CompoundTag biomeRegistry = registry.getCompoundTag("minecraft:worldgen/biome");
7171
final ListTag<CompoundTag> biomes = biomeRegistry.getListTag("value", CompoundTag.class);
7272
for (final CompoundTag biomeTag : biomes) {
73-
final CompoundTag biomeData = biomeTag.get("element");
74-
final NumberTag hasPrecipitation = biomeData.get("has_precipitation");
73+
final CompoundTag biomeData = biomeTag.getCompoundTag("element");
74+
final NumberTag hasPrecipitation = biomeData.getNumberTag("has_precipitation");
7575
biomeData.putString("precipitation", hasPrecipitation.asByte() == 1 ? "rain" : "none");
7676
}
7777
});

0 commit comments

Comments
 (0)