mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-25 03:25:11 +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
This commit is contained in:
commit
93990c8baa
2
.github/FUNDING.yml
vendored
Normal file
2
.github/FUNDING.yml
vendored
Normal file
@ -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.CompoundTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
|
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
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.github.steveice10.opennbt.tag.builtin.Tag;
|
||||||
import com.viaversion.viaversion.api.Via;
|
import com.viaversion.viaversion.api.Via;
|
||||||
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
||||||
@ -89,8 +90,8 @@ public class MappingDataBase implements MappingData {
|
|||||||
recipeSerializerMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "recipe_serializers");
|
recipeSerializerMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "recipe_serializers");
|
||||||
itemDataSerializerMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "data_component_type");
|
itemDataSerializerMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "data_component_type");
|
||||||
|
|
||||||
final ListTag unmappedParticles = unmappedIdentifierData.get("particles");
|
final ListTag<StringTag> unmappedParticles = unmappedIdentifierData.getListTag("particles", StringTag.class);
|
||||||
final ListTag mappedParticles = mappedIdentifierData.get("particles");
|
final ListTag<StringTag> mappedParticles = mappedIdentifierData.getListTag("particles", StringTag.class);
|
||||||
if (unmappedParticles != null && mappedParticles != null) {
|
if (unmappedParticles != null && mappedParticles != null) {
|
||||||
Mappings particleMappings = loadMappings(data, "particles");
|
Mappings particleMappings = loadMappings(data, "particles");
|
||||||
if (particleMappings == null) {
|
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.IntArrayTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
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.NBTIO;
|
||||||
import com.github.steveice10.opennbt.tag.io.TagReader;
|
import com.github.steveice10.opennbt.tag.io.TagReader;
|
||||||
import com.google.common.annotations.Beta;
|
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) {
|
public static FullMappings loadFullMappings(final CompoundTag mappingsTag, final CompoundTag unmappedIdentifiers, final CompoundTag mappedIdentifiers, final String key) {
|
||||||
final ListTag unmappedElements = unmappedIdentifiers.get(key);
|
final ListTag<StringTag> unmappedElements = unmappedIdentifiers.getListTag(key, StringTag.class);
|
||||||
final ListTag mappedElements = mappedIdentifiers.get(key);
|
final ListTag<StringTag> mappedElements = mappedIdentifiers.getListTag(key, StringTag.class);
|
||||||
if (unmappedElements == null || mappedElements == null) {
|
if (unmappedElements == null || mappedElements == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -239,8 +240,8 @@ public final class MappingDataLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new FullMappingsBase(
|
return new FullMappingsBase(
|
||||||
unmappedElements.getValue().stream().map(t -> (String) t.getValue()).collect(Collectors.toList()),
|
unmappedElements.getValue().stream().map(StringTag::getValue).collect(Collectors.toList()),
|
||||||
mappedElements.getValue().stream().map(t -> (String) t.getValue()).collect(Collectors.toList()),
|
mappedElements.getValue().stream().map(StringTag::getValue).collect(Collectors.toList()),
|
||||||
mappings
|
mappings
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,8 @@ public final class BukkitEncodeHandler extends MessageToMessageEncoder<ByteBuf>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void encode(final ChannelHandlerContext ctx, final ByteBuf bytebuf, final List<Object> out) throws Exception {
|
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);
|
throw CancelEncoderException.generate(null);
|
||||||
}
|
}
|
||||||
if (!connection.shouldTransformPacket()) {
|
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.IntArrayTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
|
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.github.steveice10.opennbt.tag.builtin.Tag;
|
||||||
import com.viaversion.viaversion.api.Via;
|
import com.viaversion.viaversion.api.Via;
|
||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
@ -166,9 +167,9 @@ public final class ConnectionData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Via.getPlatform().getLogger().info("Loading block connection mappings ...");
|
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++) {
|
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);
|
KEY_TO_ID.put(key, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,11 +178,10 @@ public final class ConnectionData {
|
|||||||
if (!Via.getConfig().isReduceBlockStorageMemory()) {
|
if (!Via.getConfig().isReduceBlockStorageMemory()) {
|
||||||
blockConnectionData = new Int2ObjectOpenHashMap<>(2048);
|
blockConnectionData = new Int2ObjectOpenHashMap<>(2048);
|
||||||
|
|
||||||
ListTag blockConnectionMappings = MappingDataLoader.loadNBT("blockConnections.nbt").getListTag("data");
|
ListTag<CompoundTag> blockConnectionMappings = MappingDataLoader.loadNBT("blockConnections.nbt").getListTag("data", CompoundTag.class);
|
||||||
for (Tag blockTag : blockConnectionMappings) {
|
for (CompoundTag blockTag : blockConnectionMappings) {
|
||||||
CompoundTag blockCompoundTag = (CompoundTag) blockTag;
|
|
||||||
BlockData blockData = new BlockData();
|
BlockData blockData = new BlockData();
|
||||||
for (Entry<String, Tag> entry : blockCompoundTag.entrySet()) {
|
for (Entry<String, Tag> entry : blockTag.entrySet()) {
|
||||||
String key = entry.getKey();
|
String key = entry.getKey();
|
||||||
if (key.equals("id") || key.equals("ids")) {
|
if (key.equals("id") || key.equals("ids")) {
|
||||||
continue;
|
continue;
|
||||||
@ -198,11 +198,11 @@ public final class ConnectionData {
|
|||||||
blockData.put(connectionTypeId, attachingFaces);
|
blockData.put(connectionTypeId, attachingFaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
NumberTag idTag = blockCompoundTag.getNumberTag("id");
|
NumberTag idTag = blockTag.getNumberTag("id");
|
||||||
if (idTag != null) {
|
if (idTag != null) {
|
||||||
blockConnectionData.put(idTag.asInt(), blockData);
|
blockConnectionData.put(idTag.asInt(), blockData);
|
||||||
} else {
|
} else {
|
||||||
IntArrayTag idsTag = blockCompoundTag.getIntArrayTag("ids");
|
IntArrayTag idsTag = blockTag.getIntArrayTag("ids");
|
||||||
for (int id : idsTag.getValue()) {
|
for (int id : idsTag.getValue()) {
|
||||||
blockConnectionData.put(id, blockData);
|
blockConnectionData.put(id, blockData);
|
||||||
}
|
}
|
||||||
|
@ -300,21 +300,16 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
|
|||||||
blockEntityTag.putInt("Base", 15 - baseTag.asInt());
|
blockEntityTag.putInt("Base", 15 - baseTag.asInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
ListTag patternsTag = blockEntityTag.getListTag("Patterns");
|
ListTag<CompoundTag> patternsTag = blockEntityTag.getListTag("Patterns", CompoundTag.class);
|
||||||
if (patternsTag != null) {
|
if (patternsTag != null) {
|
||||||
for (Tag pattern : patternsTag) {
|
for (CompoundTag pattern : patternsTag) {
|
||||||
if (!(pattern instanceof CompoundTag)) {
|
NumberTag colorTag = pattern.getNumberTag("Color");
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
CompoundTag patternTag = (CompoundTag) pattern;
|
|
||||||
NumberTag colorTag = patternTag.getNumberTag("Color");
|
|
||||||
if (colorTag == null) {
|
if (colorTag == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invert color id
|
// 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
|
// ench is now Enchantments and now uses identifiers
|
||||||
ListTag ench = tag.getListTag("ench");
|
ListTag<CompoundTag> ench = tag.getListTag("ench", CompoundTag.class);
|
||||||
if (ench != null) {
|
if (ench != null) {
|
||||||
ListTag enchantments = new ListTag(CompoundTag.class);
|
ListTag<CompoundTag> enchantments = new ListTag<>(CompoundTag.class);
|
||||||
for (Tag enchEntry : ench) {
|
for (CompoundTag enchEntry : ench) {
|
||||||
if (!(enchEntry instanceof CompoundTag)) {
|
NumberTag idTag = enchEntry.getNumberTag("id");
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
CompoundTag entryTag = (CompoundTag) enchEntry;
|
|
||||||
NumberTag idTag = entryTag.getNumberTag("id");
|
|
||||||
if (idTag == null) {
|
if (idTag == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -351,7 +341,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
|
|||||||
}
|
}
|
||||||
enchantmentEntry.putString("id", newId);
|
enchantmentEntry.putString("id", newId);
|
||||||
|
|
||||||
NumberTag levelTag = entryTag.getNumberTag("lvl");
|
NumberTag levelTag = enchEntry.getNumberTag("lvl");
|
||||||
if (levelTag != null) {
|
if (levelTag != null) {
|
||||||
enchantmentEntry.putShort("lvl", levelTag.asShort());
|
enchantmentEntry.putShort("lvl", levelTag.asShort());
|
||||||
}
|
}
|
||||||
@ -362,16 +352,11 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
|
|||||||
tag.put("Enchantments", enchantments);
|
tag.put("Enchantments", enchantments);
|
||||||
}
|
}
|
||||||
|
|
||||||
ListTag storedEnch = tag.getListTag("StoredEnchantments");
|
ListTag<CompoundTag> storedEnch = tag.getListTag("StoredEnchantments", CompoundTag.class);
|
||||||
if (storedEnch != null) {
|
if (storedEnch != null) {
|
||||||
ListTag newStoredEnch = new ListTag(CompoundTag.class);
|
ListTag<CompoundTag> newStoredEnch = new ListTag<>(CompoundTag.class);
|
||||||
for (Tag enchEntry : storedEnch) {
|
for (CompoundTag enchEntry : storedEnch) {
|
||||||
if (!(enchEntry instanceof CompoundTag)) {
|
NumberTag idTag = enchEntry.getNumberTag("id");
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
CompoundTag entryTag = (CompoundTag) enchEntry;
|
|
||||||
NumberTag idTag = entryTag.getNumberTag("id");
|
|
||||||
if (idTag == null) {
|
if (idTag == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -384,7 +369,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
|
|||||||
}
|
}
|
||||||
enchantmentEntry.putString("id", newId);
|
enchantmentEntry.putString("id", newId);
|
||||||
|
|
||||||
NumberTag levelTag = entryTag.getNumberTag("lvl");
|
NumberTag levelTag = enchEntry.getNumberTag("lvl");
|
||||||
if (levelTag != null) {
|
if (levelTag != null) {
|
||||||
enchantmentEntry.putShort("lvl", levelTag.asShort());
|
enchantmentEntry.putShort("lvl", levelTag.asShort());
|
||||||
}
|
}
|
||||||
@ -394,9 +379,9 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
|
|||||||
tag.put("StoredEnchantments", newStoredEnch);
|
tag.put("StoredEnchantments", newStoredEnch);
|
||||||
}
|
}
|
||||||
|
|
||||||
ListTag canPlaceOnTag = tag.getListTag("CanPlaceOn");
|
ListTag<?> canPlaceOnTag = tag.getListTag("CanPlaceOn");
|
||||||
if (canPlaceOnTag != null) {
|
if (canPlaceOnTag != null) {
|
||||||
ListTag newCanPlaceOn = new ListTag(StringTag.class);
|
ListTag<StringTag> newCanPlaceOn = new ListTag<>(StringTag.class);
|
||||||
tag.put(NBT_TAG_NAME + "|CanPlaceOn", canPlaceOnTag.copy());
|
tag.put(NBT_TAG_NAME + "|CanPlaceOn", canPlaceOnTag.copy());
|
||||||
for (Tag oldTag : canPlaceOnTag) {
|
for (Tag oldTag : canPlaceOnTag) {
|
||||||
Object value = oldTag.getValue();
|
Object value = oldTag.getValue();
|
||||||
@ -417,9 +402,9 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
|
|||||||
tag.put("CanPlaceOn", newCanPlaceOn);
|
tag.put("CanPlaceOn", newCanPlaceOn);
|
||||||
}
|
}
|
||||||
|
|
||||||
ListTag canDestroyTag = tag.getListTag("CanDestroy");
|
ListTag<?> canDestroyTag = tag.getListTag("CanDestroy");
|
||||||
if (canDestroyTag != null) {
|
if (canDestroyTag != null) {
|
||||||
ListTag newCanDestroy = new ListTag(StringTag.class);
|
ListTag<StringTag> newCanDestroy = new ListTag<>(StringTag.class);
|
||||||
tag.put(NBT_TAG_NAME + "|CanDestroy", canDestroyTag.copy());
|
tag.put(NBT_TAG_NAME + "|CanDestroy", canDestroyTag.copy());
|
||||||
for (Tag oldTag : canDestroyTag) {
|
for (Tag oldTag : canDestroyTag) {
|
||||||
Object value = oldTag.getValue();
|
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
|
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) {
|
if (patternsTag != null) {
|
||||||
for (Tag pattern : patternsTag) {
|
for (CompoundTag pattern : patternsTag) {
|
||||||
if (!(pattern instanceof CompoundTag)) {
|
NumberTag colorTag = pattern.getNumberTag("Color");
|
||||||
continue;
|
pattern.putInt("Color", 15 - colorTag.asInt()); // Invert color id
|
||||||
}
|
|
||||||
|
|
||||||
CompoundTag patternTag = (CompoundTag) pattern;
|
|
||||||
NumberTag colorTag = patternTag.getNumberTag("Color");
|
|
||||||
patternTag.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
|
// ench is now Enchantments and now uses identifiers
|
||||||
ListTag enchantments = tag.getListTag("Enchantments");
|
ListTag<CompoundTag> enchantments = tag.getListTag("Enchantments", CompoundTag.class);
|
||||||
if (enchantments != null) {
|
if (enchantments != null) {
|
||||||
ListTag ench = new ListTag(CompoundTag.class);
|
ListTag<CompoundTag> ench = new ListTag<>(CompoundTag.class);
|
||||||
for (Tag enchantmentEntry : enchantments) {
|
for (CompoundTag enchantmentEntry : enchantments) {
|
||||||
if (!(enchantmentEntry instanceof CompoundTag)) {
|
StringTag idTag = enchantmentEntry.getStringTag("id");
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
CompoundTag entryTag = (CompoundTag) enchantmentEntry;
|
|
||||||
StringTag idTag = entryTag.getStringTag("id");
|
|
||||||
if (idTag == null) {
|
if (idTag == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -646,7 +621,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
|
|||||||
}
|
}
|
||||||
if (oldId != null) {
|
if (oldId != null) {
|
||||||
enchEntry.putShort("id", oldId);
|
enchEntry.putShort("id", oldId);
|
||||||
NumberTag levelTag = entryTag.getNumberTag("lvl");
|
NumberTag levelTag = enchantmentEntry.getNumberTag("lvl");
|
||||||
if (levelTag != null) {
|
if (levelTag != null) {
|
||||||
enchEntry.putShort("lvl", levelTag.asShort());
|
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) {
|
if (storedEnch != null) {
|
||||||
ListTag newStoredEnch = new ListTag(CompoundTag.class);
|
ListTag<CompoundTag> newStoredEnch = new ListTag<>(CompoundTag.class);
|
||||||
for (Tag enchantmentEntry : storedEnch) {
|
for (CompoundTag enchantmentEntry : storedEnch) {
|
||||||
if (!(enchantmentEntry instanceof CompoundTag)) {
|
StringTag idTag = enchantmentEntry.getStringTag("id");
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
CompoundTag entryTag = (CompoundTag) enchantmentEntry;
|
|
||||||
StringTag idTag = entryTag.getStringTag("id");
|
|
||||||
if (idTag == null) {
|
if (idTag == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -684,7 +654,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
|
|||||||
}
|
}
|
||||||
|
|
||||||
enchEntry.putShort("id", oldId);
|
enchEntry.putShort("id", oldId);
|
||||||
NumberTag levelTag = entryTag.getNumberTag("lvl");
|
NumberTag levelTag = enchantmentEntry.getNumberTag("lvl");
|
||||||
if (levelTag != null) {
|
if (levelTag != null) {
|
||||||
enchEntry.putShort("lvl", levelTag.asShort());
|
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) {
|
if (tag.getListTag(NBT_TAG_NAME + "|CanPlaceOn") != null) {
|
||||||
tag.put("CanPlaceOn", tag.remove(NBT_TAG_NAME + "|CanPlaceOn"));
|
tag.put("CanPlaceOn", tag.remove(NBT_TAG_NAME + "|CanPlaceOn"));
|
||||||
} else if (tag.getListTag("CanPlaceOn") != null) {
|
} else if (tag.getListTag("CanPlaceOn") != null) {
|
||||||
ListTag old = tag.getListTag("CanPlaceOn");
|
ListTag<?> old = tag.getListTag("CanPlaceOn");
|
||||||
ListTag newCanPlaceOn = new ListTag(StringTag.class);
|
ListTag<StringTag> newCanPlaceOn = new ListTag<>(StringTag.class);
|
||||||
for (Tag oldTag : old) {
|
for (Tag oldTag : old) {
|
||||||
Object value = oldTag.getValue();
|
Object value = oldTag.getValue();
|
||||||
String[] newValues = BlockIdData.fallbackReverseMapping.get(value instanceof String
|
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));
|
newCanPlaceOn.add(new StringTag(newValue));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
newCanPlaceOn.add(oldTag);
|
newCanPlaceOn.add(new StringTag(value.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tag.put("CanPlaceOn", newCanPlaceOn);
|
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) {
|
if (tag.getListTag(NBT_TAG_NAME + "|CanDestroy") != null) {
|
||||||
tag.put("CanDestroy", tag.remove(NBT_TAG_NAME + "|CanDestroy"));
|
tag.put("CanDestroy", tag.remove(NBT_TAG_NAME + "|CanDestroy"));
|
||||||
} else if (tag.getListTag("CanDestroy") != null) {
|
} else if (tag.getListTag("CanDestroy") != null) {
|
||||||
ListTag old = tag.getListTag("CanDestroy");
|
ListTag<?> old = tag.getListTag("CanDestroy");
|
||||||
ListTag newCanDestroy = new ListTag(StringTag.class);
|
ListTag<StringTag> newCanDestroy = new ListTag<>(StringTag.class);
|
||||||
for (Tag oldTag : old) {
|
for (Tag oldTag : old) {
|
||||||
Object value = oldTag.getValue();
|
Object value = oldTag.getValue();
|
||||||
String[] newValues = BlockIdData.fallbackReverseMapping.get(value instanceof String
|
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));
|
newCanDestroy.add(new StringTag(newValue));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
newCanDestroy.add(oldTag);
|
newCanDestroy.add(new StringTag(oldTag.getValue().toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tag.put("CanDestroy", newCanDestroy);
|
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);
|
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) {
|
if (patterns != null) {
|
||||||
for (Tag pattern : patterns) {
|
for (CompoundTag pattern : patterns) {
|
||||||
if (!(pattern instanceof CompoundTag)) {
|
NumberTag colorTag = pattern.getNumberTag("Color");
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
CompoundTag patternTag = (CompoundTag) pattern;
|
|
||||||
NumberTag colorTag = patternTag.getNumberTag("Color");
|
|
||||||
if (colorTag != null) {
|
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
|
// Display Lore now uses JSON
|
||||||
CompoundTag display = item.tag().getCompoundTag("display");
|
CompoundTag display = item.tag().getCompoundTag("display");
|
||||||
if (display != null) {
|
if (display != null) {
|
||||||
ListTag lore = display.getListTag("Lore");
|
ListTag<StringTag> lore = display.getListTag("Lore", StringTag.class);
|
||||||
if (lore != null) {
|
if (lore != null) {
|
||||||
display.put(NBT_TAG_NAME + "|Lore", new ListTag(lore.copy().getValue())); // Save old lore
|
display.put(NBT_TAG_NAME + "|Lore", new ListTag<>(lore.copy().getValue())); // Save old lore
|
||||||
for (Tag loreEntry : lore) {
|
for (StringTag loreEntry : lore) {
|
||||||
if (loreEntry instanceof StringTag) {
|
String jsonText = ComponentUtil.legacyToJsonString(loreEntry.getValue(), true);
|
||||||
String jsonText = ComponentUtil.legacyToJsonString(((StringTag) loreEntry).getValue(), true);
|
loreEntry.setValue(jsonText);
|
||||||
((StringTag) loreEntry).setValue(jsonText);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -268,16 +266,14 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
|
|||||||
// Display Name now uses JSON
|
// Display Name now uses JSON
|
||||||
CompoundTag display = item.tag().getCompoundTag("display");
|
CompoundTag display = item.tag().getCompoundTag("display");
|
||||||
if (display != null) {
|
if (display != null) {
|
||||||
ListTag lore = display.getListTag("Lore");
|
ListTag<StringTag> lore = display.getListTag("Lore", StringTag.class);
|
||||||
if (lore != null) {
|
if (lore != null) {
|
||||||
Tag savedLore = display.remove(NBT_TAG_NAME + "|Lore");
|
Tag savedLore = display.remove(NBT_TAG_NAME + "|Lore");
|
||||||
if (savedLore instanceof ListTag) {
|
if (savedLore instanceof ListTag) {
|
||||||
display.put("Lore", new ListTag(((ListTag) savedLore).getValue()));
|
display.put("Lore", new ListTag<>(((ListTag<?>) savedLore).getValue()));
|
||||||
} else {
|
} else {
|
||||||
for (Tag loreEntry : lore) {
|
for (StringTag loreEntry : lore) {
|
||||||
if (loreEntry instanceof StringTag) {
|
loreEntry.setValue(ComponentUtil.jsonToLegacy(loreEntry.getValue()));
|
||||||
((StringTag) loreEntry).setValue(ComponentUtil.jsonToLegacy(((StringTag) loreEntry).getValue()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,15 +57,18 @@ public class PlayerPackets {
|
|||||||
CompoundTag tag = item.tag();
|
CompoundTag tag = item.tag();
|
||||||
if (tag == null) return;
|
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
|
// Fix for https://github.com/ViaVersion/ViaVersion/issues/2660
|
||||||
if (pages == null) {
|
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
|
// 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) {
|
if (pages.size() > 50) {
|
||||||
pages.setValue(pages.getValue().subList(0, 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");
|
dimensionRegistry = MappingDataLoader.loadNBTFromFile("dimension-registry-1.16.2.nbt");
|
||||||
|
|
||||||
// Data of each dimension
|
// Data of each dimension
|
||||||
final ListTag dimensions = dimensionRegistry.getCompoundTag("minecraft:dimension_type").get("value");
|
final ListTag<CompoundTag> dimensions = dimensionRegistry.getCompoundTag("minecraft:dimension_type").getListTag("value", CompoundTag.class);
|
||||||
for (final Tag dimension : dimensions) {
|
for (final CompoundTag dimension : dimensions) {
|
||||||
final CompoundTag dimensionCompound = (CompoundTag) dimension;
|
|
||||||
// Copy with an empty name
|
// Copy with an empty name
|
||||||
final CompoundTag dimensionData = dimensionCompound.getCompoundTag("element").copy();
|
final CompoundTag dimensionData = dimension.getCompoundTag("element").copy();
|
||||||
dimensionDataMap.put(dimensionCompound.getStringTag("name").getValue(), dimensionData);
|
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"};
|
private static final String[] WORLD_NAMES = {"minecraft:overworld", "minecraft:the_nether", "minecraft:the_end"};
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ListTag list = new ListTag(CompoundTag.class);
|
ListTag<CompoundTag> list = new ListTag<>(CompoundTag.class);
|
||||||
list.add(createOverworldEntry());
|
list.add(createOverworldEntry());
|
||||||
list.add(createOverworldCavesEntry());
|
list.add(createOverworldCavesEntry());
|
||||||
list.add(createNetherEntry());
|
list.add(createNetherEntry());
|
||||||
|
@ -156,15 +156,10 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (item.identifier() == 759 && tag != null) {
|
} else if (item.identifier() == 759 && tag != null) {
|
||||||
ListTag pages = tag.getListTag("pages");
|
ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class);
|
||||||
if (pages != null) {
|
if (pages != null) {
|
||||||
for (Tag pageTag : pages) {
|
for (StringTag pageTag : pages) {
|
||||||
if (!(pageTag instanceof StringTag)) {
|
pageTag.setValue(protocol.getComponentRewriter().processText(pageTag.getValue()).toString());
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
StringTag page = (StringTag) pageTag;
|
|
||||||
page.setValue(protocol.getComponentRewriter().processText(page.getValue()).toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,13 +194,10 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
|
|||||||
public static void oldToNewAttributes(Item item) {
|
public static void oldToNewAttributes(Item item) {
|
||||||
if (item.tag() == null) return;
|
if (item.tag() == null) return;
|
||||||
|
|
||||||
ListTag attributes = item.tag().getListTag("AttributeModifiers");
|
ListTag<CompoundTag> attributes = item.tag().getListTag("AttributeModifiers", CompoundTag.class);
|
||||||
if (attributes == null) return;
|
if (attributes == null) return;
|
||||||
|
|
||||||
for (Tag tag : attributes) {
|
for (CompoundTag attribute : attributes) {
|
||||||
if (!(tag instanceof CompoundTag)) continue;
|
|
||||||
|
|
||||||
CompoundTag attribute = (CompoundTag) tag;
|
|
||||||
rewriteAttributeName(attribute, "AttributeName", false);
|
rewriteAttributeName(attribute, "AttributeName", false);
|
||||||
rewriteAttributeName(attribute, "Name", false);
|
rewriteAttributeName(attribute, "Name", false);
|
||||||
NumberTag leastTag = attribute.getNumberTag("UUIDLeast");
|
NumberTag leastTag = attribute.getNumberTag("UUIDLeast");
|
||||||
@ -220,13 +212,10 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
|
|||||||
public static void newToOldAttributes(Item item) {
|
public static void newToOldAttributes(Item item) {
|
||||||
if (item.tag() == null) return;
|
if (item.tag() == null) return;
|
||||||
|
|
||||||
ListTag attributes = item.tag().getListTag("AttributeModifiers");
|
ListTag<CompoundTag> attributes = item.tag().getListTag("AttributeModifiers", CompoundTag.class);
|
||||||
if (attributes == null) return;
|
if (attributes == null) return;
|
||||||
|
|
||||||
for (Tag tag : attributes) {
|
for (CompoundTag attribute : attributes) {
|
||||||
if (!(tag instanceof CompoundTag)) continue;
|
|
||||||
|
|
||||||
CompoundTag attribute = (CompoundTag) tag;
|
|
||||||
rewriteAttributeName(attribute, "AttributeName", true);
|
rewriteAttributeName(attribute, "AttributeName", true);
|
||||||
rewriteAttributeName(attribute, "Name", true);
|
rewriteAttributeName(attribute, "Name", true);
|
||||||
IntArrayTag uuidTag = attribute.getIntArrayTag("UUID");
|
IntArrayTag uuidTag = attribute.getIntArrayTag("UUID");
|
||||||
|
@ -88,14 +88,14 @@ public final class Protocol1_17_1To1_17 extends AbstractProtocol<ClientboundPack
|
|||||||
|
|
||||||
// Save pages to tag
|
// Save pages to tag
|
||||||
int pages = wrapper.read(Type.VAR_INT);
|
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++) {
|
for (int i = 0; i < pages; i++) {
|
||||||
String page = wrapper.read(PAGE_STRING_TYPE);
|
String page = wrapper.read(PAGE_STRING_TYPE);
|
||||||
pagesTag.add(new StringTag(page));
|
pagesTag.add(new StringTag(page));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Legacy servers don't like an empty pages list
|
// Legacy servers don't like an empty pages list
|
||||||
if (pagesTag.size() == 0) {
|
if (pagesTag.isEmpty()) {
|
||||||
pagesTag.add(new StringTag(""));
|
pagesTag.add(new StringTag(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,9 +78,9 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_16_2
|
|||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
// Add new dimension fields
|
// Add new dimension fields
|
||||||
CompoundTag dimensionRegistry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0).get("minecraft:dimension_type");
|
CompoundTag dimensionRegistry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0).get("minecraft:dimension_type");
|
||||||
ListTag dimensions = dimensionRegistry.get("value");
|
ListTag<CompoundTag> dimensions = dimensionRegistry.getListTag("value", CompoundTag.class);
|
||||||
for (Tag dimension : dimensions) {
|
for (CompoundTag dimension : dimensions) {
|
||||||
CompoundTag dimensionCompound = ((CompoundTag) dimension).get("element");
|
CompoundTag dimensionCompound = dimension.get("element");
|
||||||
addNewDimensionData(dimensionCompound);
|
addNewDimensionData(dimensionCompound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,9 +70,9 @@ public final class Protocol1_18_2To1_18 extends AbstractProtocol<ClientboundPack
|
|||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
|
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
|
||||||
final CompoundTag dimensionsHolder = registry.get("minecraft:dimension_type");
|
final CompoundTag dimensionsHolder = registry.get("minecraft:dimension_type");
|
||||||
final ListTag dimensions = dimensionsHolder.get("value");
|
final ListTag<CompoundTag> dimensions = dimensionsHolder.getListTag("value", CompoundTag.class);
|
||||||
for (final Tag dimension : dimensions) {
|
for (final CompoundTag dimension : dimensions) {
|
||||||
addTagPrefix(((CompoundTag) dimension).get("element"));
|
addTagPrefix(dimension.get("element"));
|
||||||
}
|
}
|
||||||
|
|
||||||
addTagPrefix(wrapper.get(Type.NAMED_COMPOUND_TAG, 1));
|
addTagPrefix(wrapper.get(Type.NAMED_COMPOUND_TAG, 1));
|
||||||
|
@ -222,11 +222,10 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
|
|||||||
chatTypeStorage.clear();
|
chatTypeStorage.clear();
|
||||||
|
|
||||||
final CompoundTag registry = wrapper.passthrough(Type.NAMED_COMPOUND_TAG);
|
final CompoundTag registry = wrapper.passthrough(Type.NAMED_COMPOUND_TAG);
|
||||||
final ListTag chatTypes = registry.getCompoundTag("minecraft:chat_type").get("value");
|
final ListTag<CompoundTag> chatTypes = registry.getCompoundTag("minecraft:chat_type").getListTag("value", CompoundTag.class);
|
||||||
for (final Tag chatType : chatTypes) {
|
for (final CompoundTag chatType : chatTypes) {
|
||||||
final CompoundTag chatTypeCompound = (CompoundTag) chatType;
|
final NumberTag idTag = chatType.get("id");
|
||||||
final NumberTag idTag = chatTypeCompound.get("id");
|
chatTypeStorage.addChatType(idTag.asInt(), chatType);
|
||||||
chatTypeStorage.addChatType(idTag.asInt(), chatTypeCompound);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace chat types - they won't actually be used
|
// 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
|
// Add the replacements
|
||||||
final ListTag parameters = tag.getListTag("parameters");
|
final ListTag<StringTag> parameters = tag.getListTag("parameters", StringTag.class);
|
||||||
final List<ATextComponent> arguments = new ArrayList<>();
|
final List<ATextComponent> arguments = new ArrayList<>();
|
||||||
if (parameters != null) {
|
if (parameters != null) {
|
||||||
for (final Tag element : parameters) {
|
for (final StringTag element : parameters) {
|
||||||
JsonElement argument = null;
|
JsonElement argument = null;
|
||||||
switch ((String) element.getValue()) {
|
switch (element.getValue()) {
|
||||||
case "sender":
|
case "sender":
|
||||||
argument = senderName;
|
argument = senderName;
|
||||||
break;
|
break;
|
||||||
|
@ -64,9 +64,9 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_3
|
|||||||
registry.put("minecraft:damage_type", damageTypeRegistry);
|
registry.put("minecraft:damage_type", damageTypeRegistry);
|
||||||
|
|
||||||
final CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
|
final CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
|
||||||
final ListTag biomes = biomeRegistry.get("value");
|
final ListTag<CompoundTag> biomes = biomeRegistry.getListTag("value", CompoundTag.class);
|
||||||
for (final Tag biomeTag : biomes) {
|
for (final CompoundTag biomeTag : biomes) {
|
||||||
final CompoundTag biomeData = ((CompoundTag) biomeTag).get("element");
|
final CompoundTag biomeData = biomeTag.get("element");
|
||||||
final StringTag precipitation = biomeData.get("precipitation");
|
final StringTag precipitation = biomeData.get("precipitation");
|
||||||
final byte precipitationByte = precipitation.getValue().equals("none") ? (byte) 0 : 1;
|
final byte precipitationByte = precipitation.getValue().equals("none") ? (byte) 0 : 1;
|
||||||
biomeData.put("has_precipitation", new ByteTag(precipitationByte));
|
biomeData.put("has_precipitation", new ByteTag(precipitationByte));
|
||||||
|
@ -37,11 +37,10 @@ public final class MappingData extends MappingDataBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void loadExtras(final CompoundTag daata) {
|
protected void loadExtras(final CompoundTag daata) {
|
||||||
final ListTag chatTypes = MappingDataLoader.loadNBTFromFile("chat-types-1.19.nbt").get("values");
|
final ListTag<CompoundTag> chatTypes = MappingDataLoader.loadNBTFromFile("chat-types-1.19.nbt").getListTag("values", CompoundTag.class);
|
||||||
for (final Tag chatType : chatTypes) {
|
for (final CompoundTag chatType : chatTypes) {
|
||||||
final CompoundTag chatTypeCompound = (CompoundTag) chatType;
|
final NumberTag idTag = chatType.get("id");
|
||||||
final NumberTag idTag = chatTypeCompound.get("id");
|
defaultChatTypes.put(idTag.asInt(), chatType);
|
||||||
defaultChatTypes.put(idTag.asInt(), chatTypeCompound);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,14 +210,13 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_18,
|
|||||||
tag.put("minecraft:chat_type", CHAT_REGISTRY.copy());
|
tag.put("minecraft:chat_type", CHAT_REGISTRY.copy());
|
||||||
|
|
||||||
// Cache a whole lot of data
|
// 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<String, DimensionData> dimensionDataMap = new HashMap<>(dimensions.size());
|
||||||
final Map<CompoundTag, String> dimensionsMap = new HashMap<>(dimensions.size());
|
final Map<CompoundTag, String> dimensionsMap = new HashMap<>(dimensions.size());
|
||||||
for (final Tag dimension : dimensions) {
|
for (final CompoundTag dimension : dimensions) {
|
||||||
final CompoundTag dimensionCompound = (CompoundTag) dimension;
|
final NumberTag idTag = dimension.get("id");
|
||||||
final NumberTag idTag = dimensionCompound.get("id");
|
final CompoundTag element = dimension.get("element");
|
||||||
final CompoundTag element = dimensionCompound.get("element");
|
final String name = dimension.getStringTag("name").getValue();
|
||||||
final String name = (String) dimensionCompound.get("name").getValue();
|
|
||||||
addMonsterSpawnData(element);
|
addMonsterSpawnData(element);
|
||||||
dimensionDataMap.put(Key.stripMinecraftNamespace(name), new DimensionDataImpl(idTag.asInt(), element));
|
dimensionDataMap.put(Key.stripMinecraftNamespace(name), new DimensionDataImpl(idTag.asInt(), element));
|
||||||
dimensionsMap.put(element.copy(), name);
|
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) {
|
public static void to1_20_2Effects(final Item item) {
|
||||||
final Tag customPotionEffectsTag = item.tag().remove("CustomPotionEffects");
|
final Tag customPotionEffectsTag = item.tag().remove("CustomPotionEffects");
|
||||||
if (customPotionEffectsTag instanceof ListTag) {
|
if (customPotionEffectsTag instanceof ListTag) {
|
||||||
final ListTag effectsTag = (ListTag) customPotionEffectsTag;
|
final ListTag<?> effectsTag = (ListTag<?>) customPotionEffectsTag;
|
||||||
item.tag().put("custom_potion_effects", customPotionEffectsTag);
|
item.tag().put("custom_potion_effects", customPotionEffectsTag);
|
||||||
|
|
||||||
for (final Tag tag : effectsTag) {
|
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) {
|
public static void to1_20_1Effects(final Item item) {
|
||||||
final Tag customPotionEffectsTag = item.tag().remove("custom_potion_effects");
|
final Tag customPotionEffectsTag = item.tag().remove("custom_potion_effects");
|
||||||
if (customPotionEffectsTag instanceof ListTag) {
|
if (customPotionEffectsTag instanceof ListTag) {
|
||||||
final ListTag effectsTag = (ListTag) customPotionEffectsTag;
|
final ListTag<?> effectsTag = (ListTag<?>) customPotionEffectsTag;
|
||||||
item.tag().put("CustomPotionEffects", effectsTag);
|
item.tag().put("CustomPotionEffects", effectsTag);
|
||||||
|
|
||||||
for (final Tag tag : 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) {
|
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) {
|
if (pages == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final Tag pageTag : pages) {
|
for (final StringTag pageTag : pages) {
|
||||||
if (!(pageTag instanceof StringTag)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
final StringTag stringTag = (StringTag) pageTag;
|
|
||||||
try {
|
try {
|
||||||
final JsonElement updatedComponent = ComponentUtil.convertJson(stringTag.getValue(), ComponentUtil.SerializerVersion.V1_19_4, ComponentUtil.SerializerVersion.V1_20_3);
|
final JsonElement updatedComponent = ComponentUtil.convertJson(pageTag.getValue(), ComponentUtil.SerializerVersion.V1_19_4, ComponentUtil.SerializerVersion.V1_20_3);
|
||||||
stringTag.setValue(updatedComponent.toString());
|
pageTag.setValue(updatedComponent.toString());
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
Via.getManager().debugHandler().error("Error during book conversion", 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());
|
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
|
// 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,
|
private void updateEnchantments(final StructuredDataContainer data, final CompoundTag tag, final String key,
|
||||||
final StructuredDataKey<Enchantments> newKey, final boolean show) {
|
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) {
|
if (enchantmentsTag == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -333,14 +333,9 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
tag.remove(key);
|
tag.remove(key);
|
||||||
|
|
||||||
final Enchantments enchantments = new Enchantments(new Int2IntOpenHashMap(), show);
|
final Enchantments enchantments = new Enchantments(new Int2IntOpenHashMap(), show);
|
||||||
for (final Tag enchantment : enchantmentsTag) {
|
for (final CompoundTag enchantment : enchantmentsTag) {
|
||||||
if (!(enchantment instanceof CompoundTag)) {
|
final StringTag id = enchantment.getStringTag("id");
|
||||||
continue;
|
final NumberTag lvl = enchantment.getNumberTag("lvl");
|
||||||
}
|
|
||||||
|
|
||||||
final CompoundTag compound = (CompoundTag) enchantment;
|
|
||||||
final StringTag id = compound.getStringTag("id");
|
|
||||||
final NumberTag lvl = compound.getNumberTag("lvl");
|
|
||||||
if (id == null || lvl == null) {
|
if (id == null || lvl == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -384,7 +379,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final Tag propertyTag : (ListTag) entry.getValue()) {
|
for (final Tag propertyTag : (ListTag<?>) entry.getValue()) {
|
||||||
if (!(propertyTag instanceof CompoundTag)) {
|
if (!(propertyTag instanceof CompoundTag)) {
|
||||||
continue;
|
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])));
|
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) {
|
if (decorationsTag == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final CompoundTag updatedDecorationsTag = new CompoundTag();
|
final CompoundTag updatedDecorationsTag = new CompoundTag();
|
||||||
for (final Tag decorationTag : decorationsTag) {
|
for (final CompoundTag decorationTag : decorationsTag) {
|
||||||
if (!(decorationTag instanceof CompoundTag)) {
|
final StringTag idTag = decorationTag.getStringTag("id");
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
final CompoundTag decoration = (CompoundTag) decorationTag;
|
|
||||||
final StringTag idTag = decoration.getStringTag("id");
|
|
||||||
final String id = idTag != null ? idTag.asRawString() : "";
|
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 int type = typeTag != null ? typeTag.asInt() : 0;
|
||||||
final NumberTag xTag = decoration.getNumberTag("x");
|
final NumberTag xTag = decorationTag.getNumberTag("x");
|
||||||
final NumberTag zTag = decoration.getNumberTag("z");
|
final NumberTag zTag = decorationTag.getNumberTag("z");
|
||||||
final NumberTag rotationTag = decoration.getNumberTag("rot");
|
final NumberTag rotationTag = decorationTag.getNumberTag("rot");
|
||||||
|
|
||||||
final CompoundTag updatedDecorationTag = new CompoundTag();
|
final CompoundTag updatedDecorationTag = new CompoundTag();
|
||||||
updatedDecorationTag.putString("type", MapDecorationMappings.mapDecoration(type));
|
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.CompoundTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
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.StringTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||||
import com.viaversion.viaversion.api.data.entity.DimensionData;
|
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()) {
|
for (final Map.Entry<String, Tag> entry : registryData.entrySet()) {
|
||||||
final CompoundTag entryTag = (CompoundTag) entry.getValue();
|
final CompoundTag entryTag = (CompoundTag) entry.getValue();
|
||||||
final StringTag typeTag = entryTag.get("type");
|
final StringTag typeTag = entryTag.getStringTag("type");
|
||||||
final ListTag valueTag = entryTag.get("value");
|
final ListTag<CompoundTag> valueTag = entryTag.getListTag("value", CompoundTag.class);
|
||||||
RegistryEntry[] registryEntries = new RegistryEntry[valueTag.size()];
|
RegistryEntry[] registryEntries = new RegistryEntry[valueTag.size()];
|
||||||
boolean requiresDummyValues = false;
|
boolean requiresDummyValues = false;
|
||||||
int entriesLength = registryEntries.length;
|
int entriesLength = registryEntries.length;
|
||||||
for (final Tag tag : valueTag) {
|
for (final CompoundTag tag : valueTag) {
|
||||||
final CompoundTag compoundTag = (CompoundTag) tag;
|
final StringTag nameTag = tag.getStringTag("name");
|
||||||
final StringTag nameTag = compoundTag.get("name");
|
final int id = tag.getNumberTag("id").asInt();
|
||||||
final int id = ((NumberTag) compoundTag.get("id")).asInt();
|
|
||||||
entriesLength = Math.max(entriesLength, id + 1);
|
entriesLength = Math.max(entriesLength, id + 1);
|
||||||
if (id >= registryEntries.length) {
|
if (id >= registryEntries.length) {
|
||||||
// It was previously possible to have arbitrary ids
|
// It was previously possible to have arbitrary ids
|
||||||
@ -82,7 +80,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
|||||||
requiresDummyValues = true;
|
requiresDummyValues = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
registryEntries[id] = new RegistryEntry(nameTag.getValue(), compoundTag.get("element"));
|
registryEntries[id] = new RegistryEntry(nameTag.getValue(), tag.get("element"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requiresDummyValues) {
|
if (requiresDummyValues) {
|
||||||
|
@ -77,10 +77,10 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_4
|
|||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
|
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
|
||||||
final CompoundTag damageTypeRegistry = registry.get("minecraft:damage_type");
|
final CompoundTag damageTypeRegistry = registry.get("minecraft:damage_type");
|
||||||
final ListTag damageTypes = damageTypeRegistry.get("value");
|
final ListTag<CompoundTag> damageTypes = damageTypeRegistry.get("value");
|
||||||
int highestId = -1;
|
int highestId = -1;
|
||||||
for (final Tag damageType : damageTypes) {
|
for (final CompoundTag damageType : damageTypes) {
|
||||||
final IntTag id = ((CompoundTag) damageType).get("id");
|
final IntTag id = damageType.get("id");
|
||||||
highestId = Math.max(highestId, id.asInt());
|
highestId = Math.max(highestId, id.asInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,16 +170,16 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_19_
|
|||||||
final CompoundTag frontText = new CompoundTag();
|
final CompoundTag frontText = new CompoundTag();
|
||||||
tag.put("front_text", frontText);
|
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++) {
|
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()));
|
messages.add(text != null ? text : new StringTag(ComponentUtil.emptyJsonComponentString()));
|
||||||
}
|
}
|
||||||
frontText.put("messages", messages);
|
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++) {
|
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));
|
filteredMessages.add(text != null ? text : messages.get(i - 1));
|
||||||
}
|
}
|
||||||
if (!filteredMessages.equals(messages)) {
|
if (!filteredMessages.equals(messages)) {
|
||||||
|
@ -221,24 +221,20 @@ public class ItemRewriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CompoundTag tag = item.tag();
|
CompoundTag tag = item.tag();
|
||||||
ListTag pages = tag.getListTag("pages");
|
ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class);
|
||||||
if (pages == null) {
|
if (pages == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < pages.size(); i++) {
|
for (int i = 0; i < pages.size(); i++) {
|
||||||
Tag pageTag = pages.get(i);
|
StringTag pageTag = pages.get(i);
|
||||||
if (!(pageTag instanceof StringTag)) {
|
String value = pageTag.getValue();
|
||||||
continue;
|
|
||||||
}
|
|
||||||
StringTag stag = (StringTag) pageTag;
|
|
||||||
String value = stag.getValue();
|
|
||||||
if (value.replaceAll(" ", "").isEmpty()) {
|
if (value.replaceAll(" ", "").isEmpty()) {
|
||||||
value = "\"" + fixBookSpaceChars(value) + "\"";
|
value = "\"" + fixBookSpaceChars(value) + "\"";
|
||||||
} else {
|
} else {
|
||||||
value = fixBookSpaceChars(value);
|
value = fixBookSpaceChars(value);
|
||||||
}
|
}
|
||||||
stag.setValue(value);
|
pageTag.setValue(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,17 +285,15 @@ public class ItemRewriter {
|
|||||||
tag = new CompoundTag();
|
tag = new CompoundTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
ListTag pages = tag.getListTag("pages");
|
ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class);
|
||||||
if (pages == null) {
|
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);
|
tag.put("pages", pages);
|
||||||
item.setTag(tag);
|
item.setTag(tag);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < pages.size(); i++) {
|
for (int i = 0; i < pages.size(); i++) {
|
||||||
if (!(pages.get(i) instanceof StringTag))
|
|
||||||
continue;
|
|
||||||
StringTag page = pages.get(i);
|
StringTag page = pages.get(i);
|
||||||
page.setValue(Protocol1_9To1_8.fixJson(page.getValue()).toString());
|
page.setValue(Protocol1_9To1_8.fixJson(page.getValue()).toString());
|
||||||
}
|
}
|
||||||
|
@ -254,13 +254,13 @@ public class ComponentRewriter<C extends ClientboundPacketType> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tag instanceof ListTag) {
|
if (tag instanceof ListTag) {
|
||||||
processListTag((ListTag) tag);
|
processListTag((ListTag<?>) tag);
|
||||||
} else if (tag instanceof CompoundTag) {
|
} else if (tag instanceof CompoundTag) {
|
||||||
processCompoundTag((CompoundTag) tag);
|
processCompoundTag((CompoundTag) tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processListTag(final ListTag tag) {
|
private void processListTag(final ListTag<?> tag) {
|
||||||
for (final Tag entry : tag) {
|
for (final Tag entry : tag) {
|
||||||
processTag(entry);
|
processTag(entry);
|
||||||
}
|
}
|
||||||
@ -271,13 +271,13 @@ public class ComponentRewriter<C extends ClientboundPacketType> {
|
|||||||
if (translate != null) {
|
if (translate != null) {
|
||||||
handleTranslate(tag, translate);
|
handleTranslate(tag, translate);
|
||||||
|
|
||||||
final ListTag with = tag.getListTag("with");
|
final ListTag<?> with = tag.getListTag("with");
|
||||||
if (with != null) {
|
if (with != null) {
|
||||||
processListTag(with);
|
processListTag(with);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final ListTag extra = tag.getListTag("extra");
|
final ListTag<?> extra = tag.getListTag("extra");
|
||||||
if (extra != null) {
|
if (extra != null) {
|
||||||
processListTag(extra);
|
processListTag(extra);
|
||||||
}
|
}
|
||||||
|
@ -475,7 +475,7 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
|||||||
|
|
||||||
public void trackBiomeSize(final UserConnection connection, final CompoundTag registry) {
|
public void trackBiomeSize(final UserConnection connection, final CompoundTag registry) {
|
||||||
final CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
|
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());
|
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.
|
* Caches dimension data, later used to get height values and other important info.
|
||||||
*/
|
*/
|
||||||
public void cacheDimensionData(final UserConnection connection, final CompoundTag registry) {
|
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());
|
final Map<String, DimensionData> dimensionDataMap = new HashMap<>(dimensions.size());
|
||||||
for (final Tag dimension : dimensions) {
|
for (final CompoundTag dimension : dimensions) {
|
||||||
final CompoundTag dimensionCompound = (CompoundTag) dimension;
|
final NumberTag idTag = dimension.get("id");
|
||||||
final NumberTag idTag = dimensionCompound.get("id");
|
final CompoundTag element = dimension.get("element");
|
||||||
final CompoundTag element = dimensionCompound.get("element");
|
final String name = dimension.getStringTag("name").getValue();
|
||||||
final String name = dimensionCompound.getStringTag("name").getValue();
|
|
||||||
dimensionDataMap.put(Key.stripMinecraftNamespace(name), new DimensionDataImpl(idTag.asInt(), element));
|
dimensionDataMap.put(Key.stripMinecraftNamespace(name), new DimensionDataImpl(idTag.asInt(), element));
|
||||||
}
|
}
|
||||||
tracker(connection).setDimensions(dimensionDataMap);
|
tracker(connection).setDimensions(dimensionDataMap);
|
||||||
|
@ -69,13 +69,30 @@ public final class ComponentUtil {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
final ATextComponent component = TextComponentSerializer.V1_19_4.deserialize(element);
|
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) {
|
} catch (final Exception e) {
|
||||||
Via.getPlatform().getLogger().log(Level.SEVERE, "Error converting component: " + element, e);
|
Via.getPlatform().getLogger().log(Level.SEVERE, "Error converting component: " + element, e);
|
||||||
return new StringTag("<error>");
|
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) {
|
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;
|
return element != null ? convert(from, to, from.jsonSerializer.deserialize(element)) : null;
|
||||||
}
|
}
|
||||||
|
@ -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"
|
gson = "2.10.1"
|
||||||
fastutil = "8.5.12"
|
fastutil = "8.5.12"
|
||||||
vianbt = "4.3.0"
|
vianbt = "4.4.0"
|
||||||
mcstructs = "2.4.2-SNAPSHOT"
|
mcstructs = "2.4.2"
|
||||||
|
|
||||||
# Common provided
|
# Common provided
|
||||||
netty = "4.0.20.Final"
|
netty = "4.0.20.Final"
|
||||||
|
Loading…
Reference in New Issue
Block a user