Update ViaNBT

This commit is contained in:
Nassim Jahnke 2024-03-07 12:08:27 +01:00
parent cad78ea68f
commit f868dfa125
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
27 changed files with 147 additions and 205 deletions

View File

@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.data;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.RegistryType;
@ -83,8 +84,8 @@ public class MappingDataBase implements MappingData {
entityMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "entities");
argumentTypeMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "argumenttypes");
final ListTag unmappedParticles = unmappedIdentifierData.get("particles");
final ListTag mappedParticles = mappedIdentifierData.get("particles");
final ListTag<StringTag> unmappedParticles = unmappedIdentifierData.getListTag("particles", StringTag.class);
final ListTag<StringTag> mappedParticles = mappedIdentifierData.getListTag("particles", StringTag.class);
if (unmappedParticles != null && mappedParticles != null) {
Mappings particleMappings = loadMappings(data, "particles");
if (particleMappings == null) {

View File

@ -27,6 +27,7 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.io.NBTIO;
import com.github.steveice10.opennbt.tag.io.TagReader;
import com.google.common.annotations.Beta;
@ -227,8 +228,8 @@ public final class MappingDataLoader {
}
public static FullMappings loadFullMappings(final CompoundTag mappingsTag, final CompoundTag unmappedIdentifiers, final CompoundTag mappedIdentifiers, final String key) {
final ListTag unmappedElements = unmappedIdentifiers.get(key);
final ListTag mappedElements = mappedIdentifiers.get(key);
final ListTag<StringTag> unmappedElements = unmappedIdentifiers.getListTag(key, StringTag.class);
final ListTag<StringTag> mappedElements = mappedIdentifiers.getListTag(key, StringTag.class);
if (unmappedElements == null || mappedElements == null) {
return null;
}
@ -239,8 +240,8 @@ public final class MappingDataLoader {
}
return new FullMappingsBase(
unmappedElements.getValue().stream().map(t -> (String) t.getValue()).collect(Collectors.toList()),
mappedElements.getValue().stream().map(t -> (String) t.getValue()).collect(Collectors.toList()),
unmappedElements.getValue().stream().map(StringTag::getValue).collect(Collectors.toList()),
mappedElements.getValue().stream().map(StringTag::getValue).collect(Collectors.toList()),
mappings
);
}

View File

@ -22,6 +22,7 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
@ -166,9 +167,9 @@ public final class ConnectionData {
}
Via.getPlatform().getLogger().info("Loading block connection mappings ...");
ListTag blockStates = MappingDataLoader.loadNBT("blockstates-1.13.nbt").getListTag("blockstates");
ListTag<StringTag> blockStates = MappingDataLoader.loadNBT("blockstates-1.13.nbt").getListTag("blockstates", StringTag.class);
for (int id = 0; id < blockStates.size(); id++) {
String key = (String) blockStates.get(id).getValue();
String key = blockStates.get(id).getValue();
KEY_TO_ID.put(key, id);
}
@ -177,11 +178,10 @@ public final class ConnectionData {
if (!Via.getConfig().isReduceBlockStorageMemory()) {
blockConnectionData = new Int2ObjectOpenHashMap<>(2048);
ListTag blockConnectionMappings = MappingDataLoader.loadNBT("blockConnections.nbt").getListTag("data");
for (Tag blockTag : blockConnectionMappings) {
CompoundTag blockCompoundTag = (CompoundTag) blockTag;
ListTag<CompoundTag> blockConnectionMappings = MappingDataLoader.loadNBT("blockConnections.nbt").getListTag("data", CompoundTag.class);
for (CompoundTag blockTag : blockConnectionMappings) {
BlockData blockData = new BlockData();
for (Entry<String, Tag> entry : blockCompoundTag.entrySet()) {
for (Entry<String, Tag> entry : blockTag.entrySet()) {
String key = entry.getKey();
if (key.equals("id") || key.equals("ids")) {
continue;
@ -198,11 +198,11 @@ public final class ConnectionData {
blockData.put(connectionTypeId, attachingFaces);
}
NumberTag idTag = blockCompoundTag.getNumberTag("id");
NumberTag idTag = blockTag.getNumberTag("id");
if (idTag != null) {
blockConnectionData.put(idTag.asInt(), blockData);
} else {
IntArrayTag idsTag = blockCompoundTag.getIntArrayTag("ids");
IntArrayTag idsTag = blockTag.getIntArrayTag("ids");
for (int id : idsTag.getValue()) {
blockConnectionData.put(id, blockData);
}

View File

@ -295,21 +295,16 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
blockEntityTag.putInt("Base", 15 - baseTag.asInt());
}
ListTag patternsTag = blockEntityTag.getListTag("Patterns");
ListTag<CompoundTag> patternsTag = blockEntityTag.getListTag("Patterns", CompoundTag.class);
if (patternsTag != null) {
for (Tag pattern : patternsTag) {
if (!(pattern instanceof CompoundTag)) {
continue;
}
CompoundTag patternTag = (CompoundTag) pattern;
NumberTag colorTag = patternTag.getNumberTag("Color");
for (CompoundTag pattern : patternsTag) {
NumberTag colorTag = pattern.getNumberTag("Color");
if (colorTag == null) {
continue;
}
// Invert color id
patternTag.putInt("Color", 15 - colorTag.asInt());
pattern.putInt("Color", 15 - colorTag.asInt());
}
}
}
@ -324,16 +319,11 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
}
}
// ench is now Enchantments and now uses identifiers
ListTag ench = tag.getListTag("ench");
ListTag<CompoundTag> ench = tag.getListTag("ench", CompoundTag.class);
if (ench != null) {
ListTag enchantments = new ListTag(CompoundTag.class);
for (Tag enchEntry : ench) {
if (!(enchEntry instanceof CompoundTag)) {
continue;
}
CompoundTag entryTag = (CompoundTag) enchEntry;
NumberTag idTag = entryTag.getNumberTag("id");
ListTag<CompoundTag> enchantments = new ListTag<>(CompoundTag.class);
for (CompoundTag enchEntry : ench) {
NumberTag idTag = enchEntry.getNumberTag("id");
if (idTag == null) {
continue;
}
@ -346,7 +336,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
}
enchantmentEntry.putString("id", newId);
NumberTag levelTag = entryTag.getNumberTag("lvl");
NumberTag levelTag = enchEntry.getNumberTag("lvl");
if (levelTag != null) {
enchantmentEntry.putShort("lvl", levelTag.asShort());
}
@ -357,16 +347,11 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
tag.put("Enchantments", enchantments);
}
ListTag storedEnch = tag.getListTag("StoredEnchantments");
ListTag<CompoundTag> storedEnch = tag.getListTag("StoredEnchantments", CompoundTag.class);
if (storedEnch != null) {
ListTag newStoredEnch = new ListTag(CompoundTag.class);
for (Tag enchEntry : storedEnch) {
if (!(enchEntry instanceof CompoundTag)) {
continue;
}
CompoundTag entryTag = (CompoundTag) enchEntry;
NumberTag idTag = entryTag.getNumberTag("id");
ListTag<CompoundTag> newStoredEnch = new ListTag<>(CompoundTag.class);
for (CompoundTag enchEntry : storedEnch) {
NumberTag idTag = enchEntry.getNumberTag("id");
if (idTag == null) {
continue;
}
@ -379,7 +364,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
}
enchantmentEntry.putString("id", newId);
NumberTag levelTag = entryTag.getNumberTag("lvl");
NumberTag levelTag = enchEntry.getNumberTag("lvl");
if (levelTag != null) {
enchantmentEntry.putShort("lvl", levelTag.asShort());
}
@ -389,9 +374,9 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
tag.put("StoredEnchantments", newStoredEnch);
}
ListTag canPlaceOnTag = tag.getListTag("CanPlaceOn");
ListTag<?> canPlaceOnTag = tag.getListTag("CanPlaceOn");
if (canPlaceOnTag != null) {
ListTag newCanPlaceOn = new ListTag(StringTag.class);
ListTag<StringTag> newCanPlaceOn = new ListTag<>(StringTag.class);
tag.put(NBT_TAG_NAME + "|CanPlaceOn", canPlaceOnTag.copy());
for (Tag oldTag : canPlaceOnTag) {
Object value = oldTag.getValue();
@ -412,9 +397,9 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
tag.put("CanPlaceOn", newCanPlaceOn);
}
ListTag canDestroyTag = tag.getListTag("CanDestroy");
ListTag<?> canDestroyTag = tag.getListTag("CanDestroy");
if (canDestroyTag != null) {
ListTag newCanDestroy = new ListTag(StringTag.class);
ListTag<StringTag> newCanDestroy = new ListTag<>(StringTag.class);
tag.put(NBT_TAG_NAME + "|CanDestroy", canDestroyTag.copy());
for (Tag oldTag : canDestroyTag) {
Object value = oldTag.getValue();
@ -594,16 +579,11 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
blockEntityTag.putInt("Base", 15 - baseTag.asInt()); // invert color id
}
ListTag patternsTag = blockEntityTag.getListTag("Patterns");
ListTag<CompoundTag> patternsTag = blockEntityTag.getListTag("Patterns", CompoundTag.class);
if (patternsTag != null) {
for (Tag pattern : patternsTag) {
if (!(pattern instanceof CompoundTag)) {
continue;
}
CompoundTag patternTag = (CompoundTag) pattern;
NumberTag colorTag = patternTag.getNumberTag("Color");
patternTag.putInt("Color", 15 - colorTag.asInt()); // Invert color id
for (CompoundTag pattern : patternsTag) {
NumberTag colorTag = pattern.getNumberTag("Color");
pattern.putInt("Color", 15 - colorTag.asInt()); // Invert color id
}
}
}
@ -619,16 +599,11 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
}
// ench is now Enchantments and now uses identifiers
ListTag enchantments = tag.getListTag("Enchantments");
ListTag<CompoundTag> enchantments = tag.getListTag("Enchantments", CompoundTag.class);
if (enchantments != null) {
ListTag ench = new ListTag(CompoundTag.class);
for (Tag enchantmentEntry : enchantments) {
if (!(enchantmentEntry instanceof CompoundTag)) {
continue;
}
CompoundTag entryTag = (CompoundTag) enchantmentEntry;
StringTag idTag = entryTag.getStringTag("id");
ListTag<CompoundTag> ench = new ListTag<>(CompoundTag.class);
for (CompoundTag enchantmentEntry : enchantments) {
StringTag idTag = enchantmentEntry.getStringTag("id");
if (idTag == null) {
continue;
}
@ -641,7 +616,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
}
if (oldId != null) {
enchEntry.putShort("id", oldId);
NumberTag levelTag = entryTag.getNumberTag("lvl");
NumberTag levelTag = enchantmentEntry.getNumberTag("lvl");
if (levelTag != null) {
enchEntry.putShort("lvl", levelTag.asShort());
}
@ -653,16 +628,11 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
}
ListTag storedEnch = tag.getListTag("StoredEnchantments");
ListTag<CompoundTag> storedEnch = tag.getListTag("StoredEnchantments", CompoundTag.class);
if (storedEnch != null) {
ListTag newStoredEnch = new ListTag(CompoundTag.class);
for (Tag enchantmentEntry : storedEnch) {
if (!(enchantmentEntry instanceof CompoundTag)) {
continue;
}
CompoundTag entryTag = (CompoundTag) enchantmentEntry;
StringTag idTag = entryTag.getStringTag("id");
ListTag<CompoundTag> newStoredEnch = new ListTag<>(CompoundTag.class);
for (CompoundTag enchantmentEntry : storedEnch) {
StringTag idTag = enchantmentEntry.getStringTag("id");
if (idTag == null) {
continue;
}
@ -679,7 +649,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
}
enchEntry.putShort("id", oldId);
NumberTag levelTag = entryTag.getNumberTag("lvl");
NumberTag levelTag = enchantmentEntry.getNumberTag("lvl");
if (levelTag != null) {
enchEntry.putShort("lvl", levelTag.asShort());
}
@ -690,8 +660,8 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
if (tag.getListTag(NBT_TAG_NAME + "|CanPlaceOn") != null) {
tag.put("CanPlaceOn", tag.remove(NBT_TAG_NAME + "|CanPlaceOn"));
} else if (tag.getListTag("CanPlaceOn") != null) {
ListTag old = tag.getListTag("CanPlaceOn");
ListTag newCanPlaceOn = new ListTag(StringTag.class);
ListTag<?> old = tag.getListTag("CanPlaceOn");
ListTag<StringTag> newCanPlaceOn = new ListTag<>(StringTag.class);
for (Tag oldTag : old) {
Object value = oldTag.getValue();
String[] newValues = BlockIdData.fallbackReverseMapping.get(value instanceof String
@ -702,7 +672,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
newCanPlaceOn.add(new StringTag(newValue));
}
} else {
newCanPlaceOn.add(oldTag);
newCanPlaceOn.add(new StringTag(value.toString()));
}
}
tag.put("CanPlaceOn", newCanPlaceOn);
@ -710,8 +680,8 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
if (tag.getListTag(NBT_TAG_NAME + "|CanDestroy") != null) {
tag.put("CanDestroy", tag.remove(NBT_TAG_NAME + "|CanDestroy"));
} else if (tag.getListTag("CanDestroy") != null) {
ListTag old = tag.getListTag("CanDestroy");
ListTag newCanDestroy = new ListTag(StringTag.class);
ListTag<?> old = tag.getListTag("CanDestroy");
ListTag<StringTag> newCanDestroy = new ListTag<>(StringTag.class);
for (Tag oldTag : old) {
Object value = oldTag.getValue();
String[] newValues = BlockIdData.fallbackReverseMapping.get(value instanceof String
@ -722,7 +692,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
newCanDestroy.add(new StringTag(newValue));
}
} else {
newCanDestroy.add(oldTag);
newCanDestroy.add(new StringTag(oldTag.getValue().toString()));
}
}
tag.put("CanDestroy", newCanDestroy);

View File

@ -60,17 +60,12 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler {
Via.getPlatform().getLogger().warning("Why does this block have the banner block entity? :(" + tag);
}
ListTag patterns = tag.getListTag("Patterns");
ListTag<CompoundTag> patterns = tag.getListTag("Patterns", CompoundTag.class);
if (patterns != null) {
for (Tag pattern : patterns) {
if (!(pattern instanceof CompoundTag)) {
continue;
}
CompoundTag patternTag = (CompoundTag) pattern;
NumberTag colorTag = patternTag.getNumberTag("Color");
for (CompoundTag pattern : patterns) {
NumberTag colorTag = pattern.getNumberTag("Color");
if (colorTag != null) {
patternTag.putInt("Color", 15 - colorTag.asInt()); // Invert color id
pattern.putInt("Color", 15 - colorTag.asInt()); // Invert color id
}
}
}

View File

@ -244,14 +244,12 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
// Display Lore now uses JSON
CompoundTag display = item.tag().getCompoundTag("display");
if (display != null) {
ListTag lore = display.getListTag("Lore");
ListTag<StringTag> lore = display.getListTag("Lore", StringTag.class);
if (lore != null) {
display.put(NBT_TAG_NAME + "|Lore", new ListTag(lore.copy().getValue())); // Save old lore
for (Tag loreEntry : lore) {
if (loreEntry instanceof StringTag) {
String jsonText = ComponentUtil.legacyToJsonString(((StringTag) loreEntry).getValue(), true);
((StringTag) loreEntry).setValue(jsonText);
}
display.put(NBT_TAG_NAME + "|Lore", new ListTag<>(lore.copy().getValue())); // Save old lore
for (StringTag loreEntry : lore) {
String jsonText = ComponentUtil.legacyToJsonString(loreEntry.getValue(), true);
loreEntry.setValue(jsonText);
}
}
}
@ -268,16 +266,14 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
// Display Name now uses JSON
CompoundTag display = item.tag().getCompoundTag("display");
if (display != null) {
ListTag lore = display.getListTag("Lore");
ListTag<StringTag> lore = display.getListTag("Lore", StringTag.class);
if (lore != null) {
Tag savedLore = display.remove(NBT_TAG_NAME + "|Lore");
if (savedLore instanceof ListTag) {
display.put("Lore", new ListTag(((ListTag) savedLore).getValue()));
display.put("Lore", new ListTag<>(((ListTag<?>) savedLore).getValue()));
} else {
for (Tag loreEntry : lore) {
if (loreEntry instanceof StringTag) {
((StringTag) loreEntry).setValue(ComponentUtil.jsonToLegacy(((StringTag) loreEntry).getValue()));
}
for (StringTag loreEntry : lore) {
loreEntry.setValue(ComponentUtil.jsonToLegacy(loreEntry.getValue()));
}
}
}

View File

@ -57,15 +57,18 @@ public class PlayerPackets {
CompoundTag tag = item.tag();
if (tag == null) return;
ListTag pages = tag.getListTag("pages");
ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class);
// Fix for https://github.com/ViaVersion/ViaVersion/issues/2660
if (pages == null) {
tag.put("pages", new ListTag(Collections.singletonList(new StringTag())));
pages = new ListTag<>(StringTag.class);
pages.add(new StringTag());
tag.put("pages", pages);
return;
}
// Client limit when editing a book was upped from 50 to 100 in 1.14, but some anti-exploit plugins ban with a size higher than the old client limit
if (Via.getConfig().isTruncate1_14Books() && pages != null) {
if (Via.getConfig().isTruncate1_14Books()) {
if (pages.size() > 50) {
pages.setValue(pages.getValue().subList(0, 50));
}

View File

@ -38,12 +38,11 @@ public class MappingData extends MappingDataBase {
dimensionRegistry = MappingDataLoader.loadNBTFromFile("dimension-registry-1.16.2.nbt");
// Data of each dimension
final ListTag dimensions = dimensionRegistry.getCompoundTag("minecraft:dimension_type").get("value");
for (final Tag dimension : dimensions) {
final CompoundTag dimensionCompound = (CompoundTag) dimension;
final ListTag<CompoundTag> dimensions = dimensionRegistry.getCompoundTag("minecraft:dimension_type").getListTag("value", CompoundTag.class);
for (final CompoundTag dimension : dimensions) {
// Copy with an empty name
final CompoundTag dimensionData = dimensionCompound.getCompoundTag("element").copy();
dimensionDataMap.put(dimensionCompound.getStringTag("name").getValue(), dimensionData);
final CompoundTag dimensionData = dimension.getCompoundTag("element").copy();
dimensionDataMap.put(dimension.getStringTag("name").getValue(), dimensionData);
}
}

View File

@ -79,7 +79,7 @@ public class EntityPackets {
private static final String[] WORLD_NAMES = {"minecraft:overworld", "minecraft:the_nether", "minecraft:the_end"};
static {
ListTag list = new ListTag(CompoundTag.class);
ListTag<CompoundTag> list = new ListTag<>(CompoundTag.class);
list.add(createOverworldEntry());
list.add(createOverworldCavesEntry());
list.add(createNetherEntry());

View File

@ -155,15 +155,10 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
}
}
} else if (item.identifier() == 759 && tag != null) {
ListTag pages = tag.getListTag("pages");
ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class);
if (pages != null) {
for (Tag pageTag : pages) {
if (!(pageTag instanceof StringTag)) {
continue;
}
StringTag page = (StringTag) pageTag;
page.setValue(protocol.getComponentRewriter().processText(page.getValue()).toString());
for (StringTag pageTag : pages) {
pageTag.setValue(protocol.getComponentRewriter().processText(pageTag.getValue()).toString());
}
}
}
@ -198,13 +193,10 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
public static void oldToNewAttributes(Item item) {
if (item.tag() == null) return;
ListTag attributes = item.tag().getListTag("AttributeModifiers");
ListTag<CompoundTag> attributes = item.tag().getListTag("AttributeModifiers", CompoundTag.class);
if (attributes == null) return;
for (Tag tag : attributes) {
if (!(tag instanceof CompoundTag)) continue;
CompoundTag attribute = (CompoundTag) tag;
for (CompoundTag attribute : attributes) {
rewriteAttributeName(attribute, "AttributeName", false);
rewriteAttributeName(attribute, "Name", false);
NumberTag leastTag = attribute.getNumberTag("UUIDLeast");
@ -219,13 +211,10 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
public static void newToOldAttributes(Item item) {
if (item.tag() == null) return;
ListTag attributes = item.tag().getListTag("AttributeModifiers");
ListTag<CompoundTag> attributes = item.tag().getListTag("AttributeModifiers", CompoundTag.class);
if (attributes == null) return;
for (Tag tag : attributes) {
if (!(tag instanceof CompoundTag)) continue;
CompoundTag attribute = (CompoundTag) tag;
for (CompoundTag attribute : attributes) {
rewriteAttributeName(attribute, "AttributeName", true);
rewriteAttributeName(attribute, "Name", true);
IntArrayTag uuidTag = attribute.getIntArrayTag("UUID");

View File

@ -88,14 +88,14 @@ public final class Protocol1_17_1To1_17 extends AbstractProtocol<ClientboundPack
// Save pages to tag
int pages = wrapper.read(Type.VAR_INT);
ListTag pagesTag = new ListTag(StringTag.class);
ListTag<StringTag> pagesTag = new ListTag<>(StringTag.class);
for (int i = 0; i < pages; i++) {
String page = wrapper.read(PAGE_STRING_TYPE);
pagesTag.add(new StringTag(page));
}
// Legacy servers don't like an empty pages list
if (pagesTag.size() == 0) {
if (pagesTag.isEmpty()) {
pagesTag.add(new StringTag(""));
}

View File

@ -78,9 +78,9 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_16_2
handler(wrapper -> {
// Add new dimension fields
CompoundTag dimensionRegistry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0).get("minecraft:dimension_type");
ListTag dimensions = dimensionRegistry.get("value");
for (Tag dimension : dimensions) {
CompoundTag dimensionCompound = ((CompoundTag) dimension).get("element");
ListTag<CompoundTag> dimensions = dimensionRegistry.getListTag("value", CompoundTag.class);
for (CompoundTag dimension : dimensions) {
CompoundTag dimensionCompound = dimension.get("element");
addNewDimensionData(dimensionCompound);
}

View File

@ -70,9 +70,9 @@ public final class Protocol1_18_2To1_18 extends AbstractProtocol<ClientboundPack
handler(wrapper -> {
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
final CompoundTag dimensionsHolder = registry.get("minecraft:dimension_type");
final ListTag dimensions = dimensionsHolder.get("value");
for (final Tag dimension : dimensions) {
addTagPrefix(((CompoundTag) dimension).get("element"));
final ListTag<CompoundTag> dimensions = dimensionsHolder.getListTag("value", CompoundTag.class);
for (final CompoundTag dimension : dimensions) {
addTagPrefix(dimension.get("element"));
}
addTagPrefix(wrapper.get(Type.NAMED_COMPOUND_TAG, 1));

View File

@ -222,11 +222,10 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
chatTypeStorage.clear();
final CompoundTag registry = wrapper.passthrough(Type.NAMED_COMPOUND_TAG);
final ListTag chatTypes = registry.getCompoundTag("minecraft:chat_type").get("value");
for (final Tag chatType : chatTypes) {
final CompoundTag chatTypeCompound = (CompoundTag) chatType;
final NumberTag idTag = chatTypeCompound.get("id");
chatTypeStorage.addChatType(idTag.asInt(), chatTypeCompound);
final ListTag<CompoundTag> chatTypes = registry.getCompoundTag("minecraft:chat_type").getListTag("value", CompoundTag.class);
for (final CompoundTag chatType : chatTypes) {
final NumberTag idTag = chatType.get("id");
chatTypeStorage.addChatType(idTag.asInt(), chatType);
}
// Replace chat types - they won't actually be used
@ -405,12 +404,12 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
}
// Add the replacements
final ListTag parameters = tag.getListTag("parameters");
final ListTag<StringTag> parameters = tag.getListTag("parameters", StringTag.class);
final List<ATextComponent> arguments = new ArrayList<>();
if (parameters != null) {
for (final Tag element : parameters) {
for (final StringTag element : parameters) {
JsonElement argument = null;
switch ((String) element.getValue()) {
switch (element.getValue()) {
case "sender":
argument = senderName;
break;

View File

@ -64,9 +64,9 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_3
registry.put("minecraft:damage_type", damageTypeRegistry);
final CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
final ListTag biomes = biomeRegistry.get("value");
for (final Tag biomeTag : biomes) {
final CompoundTag biomeData = ((CompoundTag) biomeTag).get("element");
final ListTag<CompoundTag> biomes = biomeRegistry.getListTag("value", CompoundTag.class);
for (final CompoundTag biomeTag : biomes) {
final CompoundTag biomeData = biomeTag.get("element");
final StringTag precipitation = biomeData.get("precipitation");
final byte precipitationByte = precipitation.getValue().equals("none") ? (byte) 0 : 1;
biomeData.put("has_precipitation", new ByteTag(precipitationByte));

View File

@ -37,11 +37,10 @@ public final class MappingData extends MappingDataBase {
@Override
protected void loadExtras(final CompoundTag daata) {
final ListTag chatTypes = MappingDataLoader.loadNBTFromFile("chat-types-1.19.nbt").get("values");
for (final Tag chatType : chatTypes) {
final CompoundTag chatTypeCompound = (CompoundTag) chatType;
final NumberTag idTag = chatTypeCompound.get("id");
defaultChatTypes.put(idTag.asInt(), chatTypeCompound);
final ListTag<CompoundTag> chatTypes = MappingDataLoader.loadNBTFromFile("chat-types-1.19.nbt").getListTag("values", CompoundTag.class);
for (final CompoundTag chatType : chatTypes) {
final NumberTag idTag = chatType.get("id");
defaultChatTypes.put(idTag.asInt(), chatType);
}
}

View File

@ -209,13 +209,12 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_18,
tag.put("minecraft:chat_type", CHAT_REGISTRY.copy());
// Cache a whole lot of data
final ListTag dimensions = tag.getCompoundTag("minecraft:dimension_type").get("value");
final ListTag<CompoundTag> dimensions = tag.getCompoundTag("minecraft:dimension_type").getListTag("value", CompoundTag.class);
final Map<String, DimensionData> dimensionDataMap = new HashMap<>(dimensions.size());
final Map<CompoundTag, String> dimensionsMap = new HashMap<>(dimensions.size());
for (final Tag dimension : dimensions) {
final CompoundTag dimensionCompound = (CompoundTag) dimension;
final CompoundTag element = dimensionCompound.get("element");
final String name = (String) dimensionCompound.get("name").getValue();
for (final CompoundTag dimension : dimensions) {
final CompoundTag element = dimension.get("element");
final String name = dimension.getStringTag("name").getValue();
addMonsterSpawnData(element);
dimensionDataMap.put(name, new DimensionDataImpl(element));
dimensionsMap.put(element.copy(), name);

View File

@ -372,7 +372,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
public static void to1_20_2Effects(final Item item) {
final Tag customPotionEffectsTag = item.tag().remove("CustomPotionEffects");
if (customPotionEffectsTag instanceof ListTag) {
final ListTag effectsTag = (ListTag) customPotionEffectsTag;
final ListTag<?> effectsTag = (ListTag<?>) customPotionEffectsTag;
item.tag().put("custom_potion_effects", customPotionEffectsTag);
for (final Tag tag : effectsTag) {
@ -403,7 +403,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
public static void to1_20_1Effects(final Item item) {
final Tag customPotionEffectsTag = item.tag().remove("custom_potion_effects");
if (customPotionEffectsTag instanceof ListTag) {
final ListTag effectsTag = (ListTag) customPotionEffectsTag;
final ListTag<?> effectsTag = (ListTag<?>) customPotionEffectsTag;
item.tag().put("CustomPotionEffects", effectsTag);
for (final Tag tag : effectsTag) {

View File

@ -150,20 +150,15 @@ public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter<Clientboun
}
private void updatePages(final CompoundTag tag, final String key) {
final ListTag pages = tag.getListTag(key);
final ListTag<StringTag> pages = tag.getListTag(key, StringTag.class);
if (pages == null) {
return;
}
for (final Tag pageTag : pages) {
if (!(pageTag instanceof StringTag)) {
continue;
}
final StringTag stringTag = (StringTag) pageTag;
for (final StringTag pageTag : pages) {
try {
final JsonElement updatedComponent = ComponentUtil.convertJson(stringTag.getValue(), ComponentUtil.SerializerVersion.V1_19_4, ComponentUtil.SerializerVersion.V1_20_3);
stringTag.setValue(updatedComponent.toString());
final JsonElement updatedComponent = ComponentUtil.convertJson(pageTag.getValue(), ComponentUtil.SerializerVersion.V1_19_4, ComponentUtil.SerializerVersion.V1_20_3);
pageTag.setValue(updatedComponent.toString());
} catch (final Exception e) {
Via.getManager().debugHandler().error("Error during book conversion", e);
}

View File

@ -77,10 +77,10 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_4
handler(wrapper -> {
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
final CompoundTag damageTypeRegistry = registry.get("minecraft:damage_type");
final ListTag damageTypes = damageTypeRegistry.get("value");
final ListTag<CompoundTag> damageTypes = damageTypeRegistry.get("value");
int highestId = -1;
for (final Tag damageType : damageTypes) {
final IntTag id = ((CompoundTag) damageType).get("id");
for (final CompoundTag damageType : damageTypes) {
final IntTag id = damageType.get("id");
highestId = Math.max(highestId, id.asInt());
}

View File

@ -170,16 +170,16 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_19_
final CompoundTag frontText = new CompoundTag();
tag.put("front_text", frontText);
final ListTag messages = new ListTag(StringTag.class);
final ListTag<StringTag> messages = new ListTag<>(StringTag.class);
for (int i = 1; i < 5; i++) {
final Tag text = tag.remove("Text" + i);
final StringTag text = tag.remove("Text" + i);
messages.add(text != null ? text : new StringTag(ComponentUtil.emptyJsonComponentString()));
}
frontText.put("messages", messages);
final ListTag filteredMessages = new ListTag(StringTag.class);
final ListTag<StringTag> filteredMessages = new ListTag<>(StringTag.class);
for (int i = 1; i < 5; i++) {
final Tag text = tag.remove("FilteredText" + i);
final StringTag text = tag.remove("FilteredText" + i);
filteredMessages.add(text != null ? text : messages.get(i - 1));
}
if (!filteredMessages.equals(messages)) {

View File

@ -221,24 +221,20 @@ public class ItemRewriter {
}
CompoundTag tag = item.tag();
ListTag pages = tag.getListTag("pages");
ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class);
if (pages == null) {
return;
}
for (int i = 0; i < pages.size(); i++) {
Tag pageTag = pages.get(i);
if (!(pageTag instanceof StringTag)) {
continue;
}
StringTag stag = (StringTag) pageTag;
String value = stag.getValue();
StringTag pageTag = pages.get(i);
String value = pageTag.getValue();
if (value.replaceAll(" ", "").isEmpty()) {
value = "\"" + fixBookSpaceChars(value) + "\"";
} else {
value = fixBookSpaceChars(value);
}
stag.setValue(value);
pageTag.setValue(value);
}
}
@ -289,17 +285,15 @@ public class ItemRewriter {
tag = new CompoundTag();
}
ListTag pages = tag.getListTag("pages");
ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class);
if (pages == null) {
pages = new ListTag(Collections.singletonList(new StringTag(Protocol1_9To1_8.fixJson("").toString())));
pages = new ListTag<>(Collections.singletonList(new StringTag(Protocol1_9To1_8.fixJson("").toString())));
tag.put("pages", pages);
item.setTag(tag);
return;
}
for (int i = 0; i < pages.size(); i++) {
if (!(pages.get(i) instanceof StringTag))
continue;
StringTag page = pages.get(i);
page.setValue(Protocol1_9To1_8.fixJson(page.getValue()).toString());
}

View File

@ -254,13 +254,13 @@ public class ComponentRewriter<C extends ClientboundPacketType> {
}
if (tag instanceof ListTag) {
processListTag((ListTag) tag);
processListTag((ListTag<?>) tag);
} else if (tag instanceof CompoundTag) {
processCompoundTag((CompoundTag) tag);
}
}
private void processListTag(final ListTag tag) {
private void processListTag(final ListTag<?> tag) {
for (final Tag entry : tag) {
processTag(entry);
}
@ -271,13 +271,13 @@ public class ComponentRewriter<C extends ClientboundPacketType> {
if (translate != null) {
handleTranslate(tag, translate);
final ListTag with = tag.getListTag("with");
final ListTag<?> with = tag.getListTag("with");
if (with != null) {
processListTag(with);
}
}
final ListTag extra = tag.getListTag("extra");
final ListTag<?> extra = tag.getListTag("extra");
if (extra != null) {
processListTag(extra);
}

View File

@ -449,7 +449,7 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
public void trackBiomeSize(final UserConnection connection, final CompoundTag registry) {
final CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
final ListTag biomes = biomeRegistry.get("value");
final ListTag<?> biomes = biomeRegistry.get("value");
tracker(connection).setBiomesSent(biomes.size());
}
@ -465,12 +465,11 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
* Caches dimension data, later used to get height values and other important info.
*/
public void cacheDimensionData(final UserConnection connection, final CompoundTag registry) {
final ListTag dimensions = registry.getCompoundTag("minecraft:dimension_type").get("value");
final ListTag<CompoundTag> dimensions = registry.getCompoundTag("minecraft:dimension_type").getListTag("value", CompoundTag.class);
final Map<String, DimensionData> dimensionDataMap = new HashMap<>(dimensions.size());
for (final Tag dimension : dimensions) {
final CompoundTag dimensionCompound = (CompoundTag) dimension;
final CompoundTag element = dimensionCompound.get("element");
final String name = dimensionCompound.getStringTag("name").getValue();
for (final CompoundTag dimension : dimensions) {
final CompoundTag element = dimension.get("element");
final String name = dimension.getStringTag("name").getValue();
dimensionDataMap.put(name, new DimensionDataImpl(element));
}
tracker(connection).setDimensions(dimensionDataMap);

View File

@ -78,7 +78,7 @@ public final class ComponentUtil {
private static Tag trimStrings(final Tag input) {
// Dirty fix for https://github.com/ViaVersion/ViaVersion/issues/3650
// Usually tripped by hover event data being too long, e.g. book or shulker box contents
// Usually tripped by hover event data being too long, e.g. book or shulker box contents, which have to be held in full as SNBT
if (input == null) {
return null;
}

View File

@ -37,12 +37,15 @@ public final class TagUtil {
entry.setValue(updatedTag);
}
} else if (tag instanceof ListTag) {
final ListTag listTag = (ListTag) tag;
listTag.getValue().replaceAll(t -> handleDeep(null, t, consumer));
handleListTag((ListTag<?>) tag, consumer);
}
return consumer.update(key, tag);
}
private static <T extends Tag> void handleListTag(final ListTag<T> listTag, final TagUpdater consumer) {
listTag.getValue().replaceAll(t -> (T) handleDeep(null, t, consumer));
}
@FunctionalInterface
public interface TagUpdater {

View File

@ -5,8 +5,8 @@ metadata.format.version = "1.1"
gson = "2.10.1"
fastutil = "8.5.12"
flare = "2.0.1"
vianbt = "4.2.0"
mcstructs = "2.4.2-SNAPSHOT"
vianbt = "4.4.0"
mcstructs = "2.4.2"
# Common provided
netty = "4.0.20.Final"