Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-26 00:00:28 +01:00
Merge branch 'master' into dev
# Conflicts: # common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java # common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java # gradle.properties # gradle/libs.versions.toml
Dieser Commit ist enthalten in:
Commit
93990c8baa
2
.github/FUNDING.yml
vendored
Normale Datei
2
.github/FUNDING.yml
vendored
Normale Datei
@ -0,0 +1,2 @@
|
||||
github: kennytv
|
||||
patreon: kennytv
|
@ -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;
|
||||
@ -89,8 +90,8 @@ public class MappingDataBase implements MappingData {
|
||||
recipeSerializerMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "recipe_serializers");
|
||||
itemDataSerializerMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "data_component_type");
|
||||
|
||||
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) {
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
|
@ -43,7 +43,8 @@ public final class BukkitEncodeHandler extends MessageToMessageEncoder<ByteBuf>
|
||||
|
||||
@Override
|
||||
protected void encode(final ChannelHandlerContext ctx, final ByteBuf bytebuf, final List<Object> out) throws Exception {
|
||||
if (!connection.checkClientboundPacket()) {
|
||||
// Check if the channel is open as older servers might start sending packets through the pipeline despite the channel being closed
|
||||
if (!connection.checkClientboundPacket() || !ctx.channel().isOpen()) {
|
||||
throw CancelEncoderException.generate(null);
|
||||
}
|
||||
if (!connection.shouldTransformPacket()) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -300,21 +300,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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -329,16 +324,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;
|
||||
}
|
||||
@ -351,7 +341,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());
|
||||
}
|
||||
@ -362,16 +352,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;
|
||||
}
|
||||
@ -384,7 +369,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());
|
||||
}
|
||||
@ -394,9 +379,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();
|
||||
@ -417,9 +402,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();
|
||||
@ -599,16 +584,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
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -624,16 +604,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;
|
||||
}
|
||||
@ -646,7 +621,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());
|
||||
}
|
||||
@ -658,16 +633,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;
|
||||
}
|
||||
@ -684,7 +654,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());
|
||||
}
|
||||
@ -695,8 +665,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
|
||||
@ -707,7 +677,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);
|
||||
@ -715,8 +685,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
|
||||
@ -727,7 +697,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);
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,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());
|
||||
|
@ -156,15 +156,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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -199,13 +194,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");
|
||||
@ -220,13 +212,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");
|
||||
|
@ -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(""));
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,14 +210,13 @@ 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 NumberTag idTag = dimensionCompound.get("id");
|
||||
final CompoundTag element = dimensionCompound.get("element");
|
||||
final String name = (String) dimensionCompound.get("name").getValue();
|
||||
for (final CompoundTag dimension : dimensions) {
|
||||
final NumberTag idTag = dimension.get("id");
|
||||
final CompoundTag element = dimension.get("element");
|
||||
final String name = dimension.getStringTag("name").getValue();
|
||||
addMonsterSpawnData(element);
|
||||
dimensionDataMap.put(Key.stripMinecraftNamespace(name), new DimensionDataImpl(idTag.asInt(), element));
|
||||
dimensionsMap.put(element.copy(), name);
|
||||
|
@ -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) {
|
||||
|
@ -152,20 +152,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);
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
data.add(StructuredDataKey.MAP_ID, map.asInt());
|
||||
}
|
||||
|
||||
updateMapDecorations(data, tag.getListTag("Decorations"));
|
||||
updateMapDecorations(data, tag.getListTag("Decorations", CompoundTag.class));
|
||||
|
||||
// MAP_POST_PROCESSING is only used internally
|
||||
|
||||
@ -325,7 +325,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
|
||||
private void updateEnchantments(final StructuredDataContainer data, final CompoundTag tag, final String key,
|
||||
final StructuredDataKey<Enchantments> newKey, final boolean show) {
|
||||
final ListTag enchantmentsTag = tag.getListTag(key);
|
||||
final ListTag<CompoundTag> enchantmentsTag = tag.getListTag(key, CompoundTag.class);
|
||||
if (enchantmentsTag == null) {
|
||||
return;
|
||||
}
|
||||
@ -333,14 +333,9 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
tag.remove(key);
|
||||
|
||||
final Enchantments enchantments = new Enchantments(new Int2IntOpenHashMap(), show);
|
||||
for (final Tag enchantment : enchantmentsTag) {
|
||||
if (!(enchantment instanceof CompoundTag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final CompoundTag compound = (CompoundTag) enchantment;
|
||||
final StringTag id = compound.getStringTag("id");
|
||||
final NumberTag lvl = compound.getNumberTag("lvl");
|
||||
for (final CompoundTag enchantment : enchantmentsTag) {
|
||||
final StringTag id = enchantment.getStringTag("id");
|
||||
final NumberTag lvl = enchantment.getNumberTag("lvl");
|
||||
if (id == null || lvl == null) {
|
||||
continue;
|
||||
}
|
||||
@ -384,7 +379,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
continue;
|
||||
}
|
||||
|
||||
for (final Tag propertyTag : (ListTag) entry.getValue()) {
|
||||
for (final Tag propertyTag : (ListTag<?>) entry.getValue()) {
|
||||
if (!(propertyTag instanceof CompoundTag)) {
|
||||
continue;
|
||||
}
|
||||
@ -407,25 +402,20 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
data.add(StructuredDataKey.PROFILE, new GameProfile(name, uuid, properties.toArray(new GameProfile.Property[0])));
|
||||
}
|
||||
|
||||
private void updateMapDecorations(final StructuredDataContainer data, final ListTag decorationsTag) {
|
||||
private void updateMapDecorations(final StructuredDataContainer data, final ListTag<CompoundTag> decorationsTag) {
|
||||
if (decorationsTag == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final CompoundTag updatedDecorationsTag = new CompoundTag();
|
||||
for (final Tag decorationTag : decorationsTag) {
|
||||
if (!(decorationTag instanceof CompoundTag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final CompoundTag decoration = (CompoundTag) decorationTag;
|
||||
final StringTag idTag = decoration.getStringTag("id");
|
||||
for (final CompoundTag decorationTag : decorationsTag) {
|
||||
final StringTag idTag = decorationTag.getStringTag("id");
|
||||
final String id = idTag != null ? idTag.asRawString() : "";
|
||||
final NumberTag typeTag = decoration.getNumberTag("type");
|
||||
final NumberTag typeTag = decorationTag.getNumberTag("type");
|
||||
final int type = typeTag != null ? typeTag.asInt() : 0;
|
||||
final NumberTag xTag = decoration.getNumberTag("x");
|
||||
final NumberTag zTag = decoration.getNumberTag("z");
|
||||
final NumberTag rotationTag = decoration.getNumberTag("rot");
|
||||
final NumberTag xTag = decorationTag.getNumberTag("x");
|
||||
final NumberTag zTag = decorationTag.getNumberTag("z");
|
||||
final NumberTag rotationTag = decorationTag.getNumberTag("rot");
|
||||
|
||||
final CompoundTag updatedDecorationTag = new CompoundTag();
|
||||
updatedDecorationTag.putString("type", MapDecorationMappings.mapDecoration(type));
|
||||
|
@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.rewriter;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
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.data.entity.DimensionData;
|
||||
@ -66,15 +65,14 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
||||
|
||||
for (final Map.Entry<String, Tag> entry : registryData.entrySet()) {
|
||||
final CompoundTag entryTag = (CompoundTag) entry.getValue();
|
||||
final StringTag typeTag = entryTag.get("type");
|
||||
final ListTag valueTag = entryTag.get("value");
|
||||
final StringTag typeTag = entryTag.getStringTag("type");
|
||||
final ListTag<CompoundTag> valueTag = entryTag.getListTag("value", CompoundTag.class);
|
||||
RegistryEntry[] registryEntries = new RegistryEntry[valueTag.size()];
|
||||
boolean requiresDummyValues = false;
|
||||
int entriesLength = registryEntries.length;
|
||||
for (final Tag tag : valueTag) {
|
||||
final CompoundTag compoundTag = (CompoundTag) tag;
|
||||
final StringTag nameTag = compoundTag.get("name");
|
||||
final int id = ((NumberTag) compoundTag.get("id")).asInt();
|
||||
for (final CompoundTag tag : valueTag) {
|
||||
final StringTag nameTag = tag.getStringTag("name");
|
||||
final int id = tag.getNumberTag("id").asInt();
|
||||
entriesLength = Math.max(entriesLength, id + 1);
|
||||
if (id >= registryEntries.length) {
|
||||
// It was previously possible to have arbitrary ids
|
||||
@ -82,7 +80,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
||||
requiresDummyValues = true;
|
||||
}
|
||||
|
||||
registryEntries[id] = new RegistryEntry(nameTag.getValue(), compoundTag.get("element"));
|
||||
registryEntries[id] = new RegistryEntry(nameTag.getValue(), tag.get("element"));
|
||||
}
|
||||
|
||||
if (requiresDummyValues) {
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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)) {
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -475,7 +475,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());
|
||||
}
|
||||
|
||||
@ -491,13 +491,12 @@ 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 NumberTag idTag = dimensionCompound.get("id");
|
||||
final CompoundTag element = dimensionCompound.get("element");
|
||||
final String name = dimensionCompound.getStringTag("name").getValue();
|
||||
for (final CompoundTag dimension : dimensions) {
|
||||
final NumberTag idTag = dimension.get("id");
|
||||
final CompoundTag element = dimension.get("element");
|
||||
final String name = dimension.getStringTag("name").getValue();
|
||||
dimensionDataMap.put(Key.stripMinecraftNamespace(name), new DimensionDataImpl(idTag.asInt(), element));
|
||||
}
|
||||
tracker(connection).setDimensions(dimensionDataMap);
|
||||
|
@ -69,13 +69,30 @@ public final class ComponentUtil {
|
||||
|
||||
try {
|
||||
final ATextComponent component = TextComponentSerializer.V1_19_4.deserialize(element);
|
||||
return TextComponentCodec.V1_20_3.serializeNbt(component);
|
||||
return trimStrings(TextComponentCodec.V1_20_3.serializeNbt(component));
|
||||
} catch (final Exception e) {
|
||||
Via.getPlatform().getLogger().log(Level.SEVERE, "Error converting component: " + element, e);
|
||||
return new StringTag("<error>");
|
||||
}
|
||||
}
|
||||
|
||||
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, which have to be held in full as SNBT
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
return TagUtil.handleDeep(input, (key, tag) -> {
|
||||
if (tag instanceof StringTag) {
|
||||
final String value = ((StringTag) tag).getValue();
|
||||
if (value.length() > Short.MAX_VALUE) {
|
||||
((StringTag) tag).setValue("{}");
|
||||
}
|
||||
}
|
||||
return tag;
|
||||
});
|
||||
}
|
||||
|
||||
public static @Nullable JsonElement convertJson(@Nullable final JsonElement element, final SerializerVersion from, final SerializerVersion to) {
|
||||
return element != null ? convert(from, to, from.jsonSerializer.deserialize(element)) : null;
|
||||
}
|
||||
|
61
common/src/main/java/com/viaversion/viaversion/util/TagUtil.java
Normale Datei
61
common/src/main/java/com/viaversion/viaversion/util/TagUtil.java
Normale Datei
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viaversion.util;
|
||||
|
||||
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 org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class TagUtil {
|
||||
|
||||
public static Tag handleDeep(final Tag tag, final TagUpdater consumer) {
|
||||
return handleDeep(null, tag, consumer);
|
||||
}
|
||||
|
||||
private static Tag handleDeep(@Nullable final String key, final Tag tag, final TagUpdater consumer) {
|
||||
if (tag instanceof CompoundTag) {
|
||||
final CompoundTag compoundTag = (CompoundTag) tag;
|
||||
for (final Map.Entry<String, Tag> entry : compoundTag.entrySet()) {
|
||||
final Tag updatedTag = handleDeep(entry.getKey(), entry.getValue(), consumer);
|
||||
entry.setValue(updatedTag);
|
||||
}
|
||||
} else if (tag instanceof ListTag) {
|
||||
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 {
|
||||
|
||||
/**
|
||||
* Updates the given tag.
|
||||
*
|
||||
* @param key key of the tag if inside a CompoundTag
|
||||
* @param tag the tag to update
|
||||
* @return the updated tag, can be the original one
|
||||
*/
|
||||
Tag update(@Nullable String key, Tag tag);
|
||||
}
|
||||
}
|
@ -4,8 +4,8 @@ metadata.format.version = "1.1"
|
||||
|
||||
gson = "2.10.1"
|
||||
fastutil = "8.5.12"
|
||||
vianbt = "4.3.0"
|
||||
mcstructs = "2.4.2-SNAPSHOT"
|
||||
vianbt = "4.4.0"
|
||||
mcstructs = "2.4.2"
|
||||
|
||||
# Common provided
|
||||
netty = "4.0.20.Final"
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren