3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-25 15:50:10 +01:00

Replace tag instanceof checks/unchecked casts with helper methods

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-02-10 23:28:36 +01:00
Ursprung ad62d8552c
Commit 8a485db580
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
64 geänderte Dateien mit 495 neuen und 450 gelöschten Zeilen

Datei anzeigen

@ -18,7 +18,6 @@
package com.viaversion.viaversion.configuration;
import com.google.gson.JsonElement;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.configuration.ViaVersionConfig;
import com.viaversion.viaversion.api.minecraft.WorldIdentifiers;
import com.viaversion.viaversion.api.protocol.version.BlockedProtocolVersions;

Datei anzeigen

@ -18,9 +18,7 @@
package com.viaversion.viaversion.data.entity;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.data.entity.DimensionData;
public final class DimensionDataImpl implements DimensionData {
@ -34,19 +32,17 @@ public final class DimensionDataImpl implements DimensionData {
}
public DimensionDataImpl(final CompoundTag dimensionData) {
final Tag height = dimensionData.get("height");
if (height instanceof IntTag) {
this.height = ((NumberTag) height).asInt();
} else {
final NumberTag height = dimensionData.getNumberTag("height");
if (height == null) {
throw new IllegalArgumentException("height missing in dimension data: " + dimensionData);
}
this.height = height.asInt();
final Tag minY = dimensionData.get("min_y");
if (minY instanceof IntTag) {
this.minY = ((NumberTag) minY).asInt();
} else {
final NumberTag minY = dimensionData.getNumberTag("min_y");
if (minY == null) {
throw new IllegalArgumentException("min_y missing in dimension data: " + dimensionData);
}
this.minY = minY.asInt();
}
@Override

Datei anzeigen

@ -82,10 +82,6 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectSortedMap;
import java.util.logging.Level;
import org.checkerframework.checker.nullness.qual.Nullable;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -106,6 +102,9 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Function;
import java.util.logging.Level;
import org.checkerframework.checker.nullness.qual.Nullable;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
public class ProtocolManagerImpl implements ProtocolManager {
private static final Protocol BASE_PROTOCOL = new BaseProtocol();

Datei anzeigen

@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.base;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import java.util.UUID;
public class BaseProtocol1_16 extends BaseProtocol1_7 {

Datei anzeigen

@ -19,6 +19,7 @@ package com.viaversion.viaversion.protocols.protocol1_10to1_9_3;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
@ -28,13 +29,12 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
import com.viaversion.viaversion.api.type.types.version.Types1_9;
import com.viaversion.viaversion.protocols.protocol1_10to1_9_3.packets.InventoryPackets;
import com.viaversion.viaversion.protocols.protocol1_10to1_9_3.storage.ResourcePackTracker;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

Datei anzeigen

@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.protocol1_11to1_10;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.viaversion.viaversion.api.minecraft.item.Item;
@ -115,12 +114,11 @@ public class EntityIdRewriter {
}
public static void toClient(CompoundTag tag, boolean backwards) {
Tag idTag = tag.get("id");
if (idTag instanceof StringTag) {
StringTag id = (StringTag) idTag;
String newName = backwards ? oldToNewNames.inverse().get(id.getValue()) : oldToNewNames.get(id.getValue());
StringTag idTag = tag.getStringTag("id");
if (idTag != null) {
String newName = backwards ? oldToNewNames.inverse().get(idTag.getValue()) : oldToNewNames.get(idTag.getValue());
if (newName != null) {
id.setValue(newName);
idTag.setValue(newName);
}
}
}
@ -132,9 +130,9 @@ public class EntityIdRewriter {
public static void toClientSpawner(CompoundTag tag, boolean backwards) {
if (tag == null) return;
Tag spawnDataTag = tag.get("SpawnData");
CompoundTag spawnDataTag = tag.getCompoundTag("SpawnData");
if (spawnDataTag != null) {
toClient((CompoundTag) spawnDataTag, backwards);
toClient(spawnDataTag, backwards);
}
}
@ -144,7 +142,7 @@ public class EntityIdRewriter {
public static void toClientItem(Item item, boolean backwards) {
if (hasEntityTag(item)) {
toClient(item.tag().get("EntityTag"), backwards);
toClient(item.tag().getCompoundTag("EntityTag"), backwards);
}
if (item != null && item.amount() <= 0) item.setAmount(1);
}
@ -156,13 +154,12 @@ public class EntityIdRewriter {
public static void toServerItem(Item item, boolean backwards) {
if (!hasEntityTag(item)) return;
CompoundTag entityTag = item.tag().get("EntityTag");
Tag idTag = entityTag.get("id");
if (idTag instanceof StringTag) {
StringTag id = (StringTag) idTag;
String newName = backwards ? oldToNewNames.get(id.getValue()) : oldToNewNames.inverse().get(id.getValue());
CompoundTag entityTag = item.tag().getCompoundTag("EntityTag");
StringTag idTag = entityTag.getStringTag("id");
if (idTag != null) {
String newName = backwards ? oldToNewNames.get(idTag.getValue()) : oldToNewNames.inverse().get(idTag.getValue());
if (newName != null) {
id.setValue(newName);
idTag.setValue(newName);
}
}
}
@ -173,7 +170,7 @@ public class EntityIdRewriter {
CompoundTag tag = item.tag();
if (tag == null) return false;
Tag entityTag = tag.get("EntityTag");
return entityTag instanceof CompoundTag && ((CompoundTag) entityTag).get("id") instanceof StringTag;
CompoundTag entityTag = tag.getCompoundTag("EntityTag");
return entityTag != null && entityTag.getStringTag("id") != null;
}
}

Datei anzeigen

@ -21,6 +21,7 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
@ -28,6 +29,7 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
import com.viaversion.viaversion.api.type.types.version.Types1_9;
import com.viaversion.viaversion.protocols.protocol1_11to1_10.data.PotionColorMapping;
import com.viaversion.viaversion.protocols.protocol1_11to1_10.metadata.MetadataRewriter1_11To1_10;
@ -35,8 +37,6 @@ import com.viaversion.viaversion.protocols.protocol1_11to1_10.packets.InventoryP
import com.viaversion.viaversion.protocols.protocol1_11to1_10.storage.EntityTracker1_11;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.rewriter.SoundRewriter;
import com.viaversion.viaversion.util.Pair;
@ -193,13 +193,15 @@ public class Protocol1_11To1_10 extends AbstractProtocol<ClientboundPackets1_9_3
handler(wrapper -> {
CompoundTag tag = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 1)
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 1) {
EntityIdRewriter.toClientSpawner(tag);
}
if (tag.contains("id"))
StringTag idTag = tag.getStringTag("id");
if (idTag != null) {
// Handle new identifier
((StringTag) tag.get("id")).setValue(BlockEntityRewriter.toNewIdentifier((String) tag.get("id").getValue()));
idTag.setValue(BlockEntityRewriter.toNewIdentifier(idTag.getValue()));
}
});
}
});
@ -211,15 +213,18 @@ public class Protocol1_11To1_10 extends AbstractProtocol<ClientboundPackets1_9_3
if (chunk.getBlockEntities() == null) return;
for (CompoundTag tag : chunk.getBlockEntities()) {
if (tag.contains("id")) {
String identifier = ((StringTag) tag.get("id")).getValue();
if (identifier.equals("MobSpawner")) {
EntityIdRewriter.toClientSpawner(tag);
}
// Handle new identifier
((StringTag) tag.get("id")).setValue(BlockEntityRewriter.toNewIdentifier(identifier));
StringTag idTag = tag.getStringTag("id");
if (idTag == null) {
continue;
}
String identifier = idTag.getValue();
if (identifier.equals("MobSpawner")) {
EntityIdRewriter.toClientSpawner(tag);
}
// Handle new identifier
idTag.setValue(BlockEntityRewriter.toNewIdentifier(identifier));
}
});

Datei anzeigen

@ -23,6 +23,7 @@ import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.google.gson.JsonElement;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
@ -33,6 +34,7 @@ import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
import com.viaversion.viaversion.api.type.types.version.Types1_12;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.metadata.MetadataRewriter1_12To1_11_1;
@ -42,8 +44,6 @@ import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPacke
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.rewriter.SoundRewriter;

Datei anzeigen

@ -20,6 +20,7 @@ package com.viaversion.viaversion.protocols.protocol1_13_1to1_13;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.MappingData;
import com.viaversion.viaversion.api.data.MappingDataBase;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
import com.viaversion.viaversion.api.minecraft.item.Item;
@ -35,7 +36,6 @@ import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.packets.Inventor
import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.packets.WorldPackets;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;

Datei anzeigen

@ -17,16 +17,16 @@
*/
package com.viaversion.viaversion.protocols.protocol1_13_1to1_13.packets;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_13;
import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_13;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.rewriter.BlockRewriter;
public class WorldPackets {

Datei anzeigen

@ -166,7 +166,7 @@ public final class ConnectionData {
}
Via.getPlatform().getLogger().info("Loading block connection mappings ...");
ListTag blockStates = MappingDataLoader.loadNBT("blockstates-1.13.nbt").get("blockstates");
ListTag blockStates = MappingDataLoader.loadNBT("blockstates-1.13.nbt").getListTag("blockstates");
for (int id = 0; id < blockStates.size(); id++) {
String key = (String) blockStates.get(id).getValue();
KEY_TO_ID.put(key, id);
@ -177,7 +177,7 @@ public final class ConnectionData {
if (!Via.getConfig().isReduceBlockStorageMemory()) {
blockConnectionData = new Int2ObjectOpenHashMap<>(2048);
ListTag blockConnectionMappings = MappingDataLoader.loadNBT("blockConnections.nbt").get("data");
ListTag blockConnectionMappings = MappingDataLoader.loadNBT("blockConnections.nbt").getListTag("data");
for (Tag blockTag : blockConnectionMappings) {
CompoundTag blockCompoundTag = (CompoundTag) blockTag;
BlockData blockData = new BlockData();
@ -198,11 +198,11 @@ public final class ConnectionData {
blockData.put(connectionTypeId, attachingFaces);
}
NumberTag idTag = blockCompoundTag.get("id");
NumberTag idTag = blockCompoundTag.getNumberTag("id");
if (idTag != null) {
blockConnectionData.put(idTag.asInt(), blockData);
} else {
IntArrayTag idsTag = blockCompoundTag.get("ids");
IntArrayTag idsTag = blockCompoundTag.getIntArrayTag("ids");
for (int id : idsTag.getValue()) {
blockConnectionData.put(id, blockData);
}

Datei anzeigen

@ -23,7 +23,6 @@ import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.util.Key;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
import java.util.HashSet;
import java.util.Set;

Datei anzeigen

@ -62,8 +62,8 @@ public class ComponentRewriter1_13<C extends ClientboundPacketType> extends Comp
return;
}
CompoundTag itemTag = tag.get("tag");
NumberTag damageTag = tag.get("Damage");
CompoundTag itemTag = tag.getCompoundTag("tag");
NumberTag damageTag = tag.getNumberTag("Damage");
// Call item converter
short damage = damageTag != null ? damageTag.asShort() : 0;

Datei anzeigen

@ -18,7 +18,6 @@
package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data;
import com.viaversion.viaversion.util.Key;
import java.util.HashMap;
import java.util.Map;

Datei anzeigen

@ -28,18 +28,21 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.data.*;
import com.viaversion.viaversion.api.data.BiMappings;
import com.viaversion.viaversion.api.data.Int2IntMapBiMappings;
import com.viaversion.viaversion.api.data.MappingDataBase;
import com.viaversion.viaversion.api.data.MappingDataLoader;
import com.viaversion.viaversion.api.data.Mappings;
import com.viaversion.viaversion.util.GsonUtil;
import com.viaversion.viaversion.util.Int2IntBiHashMap;
import com.viaversion.viaversion.util.Key;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.Nullable;
public class MappingData extends MappingDataBase {
private final Map<String, int[]> blockTags = new HashMap<>();
@ -56,11 +59,11 @@ public class MappingData extends MappingDataBase {
@Override
protected void loadExtras(final CompoundTag data) {
loadTags(blockTags, data.get("block_tags"));
loadTags(itemTags, data.get("item_tags"));
loadTags(fluidTags, data.get("fluid_tags"));
loadTags(blockTags, data.getCompoundTag("block_tags"));
loadTags(itemTags, data.getCompoundTag("item_tags"));
loadTags(fluidTags, data.getCompoundTag("fluid_tags"));
CompoundTag legacyEnchantments = data.get("legacy_enchantments");
CompoundTag legacyEnchantments = data.getCompoundTag("legacy_enchantments");
loadEnchantments(oldEnchantmentsIds, legacyEnchantments);
// Map minecraft:snow[layers=1] of 1.12 to minecraft:snow[layers=2] in 1.13

Datei anzeigen

@ -18,10 +18,10 @@
package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets.WorldPackets;
import java.util.ArrayList;

Datei anzeigen

@ -20,7 +20,6 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.viaversion.viaversion.util.Key;
import java.util.Optional;
public class SpawnEggRewriter {

Datei anzeigen

@ -18,6 +18,7 @@
package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
@ -26,7 +27,6 @@ import com.viaversion.viaversion.api.type.types.version.Types1_13;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.metadata.MetadataRewriter1_13To1_12_2;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
public class EntityPackets {

Datei anzeigen

@ -21,7 +21,6 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
import com.github.steveice10.opennbt.tag.builtin.ShortTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.google.common.base.Joiner;
@ -284,85 +283,117 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
// Invert banner/shield color id
boolean banner = item.identifier() == 425;
if (banner || item.identifier() == 442) {
if (tag.get("BlockEntityTag") instanceof CompoundTag) {
CompoundTag blockEntityTag = tag.get("BlockEntityTag");
if (blockEntityTag.get("Base") instanceof IntTag) {
IntTag base = blockEntityTag.get("Base");
CompoundTag blockEntityTag = tag.getCompoundTag("BlockEntityTag");
if (blockEntityTag != null) {
NumberTag baseTag = blockEntityTag.getNumberTag("Base");
if (baseTag != null) {
// Set banner item id according to nbt
if (banner) {
rawId = 6800 + base.asInt();
rawId = 6800 + baseTag.asInt();
}
base.setValue(15 - base.asInt());
blockEntityTag.putInt("Base", 15 - baseTag.asInt());
}
if (blockEntityTag.get("Patterns") instanceof ListTag) {
for (Tag pattern : (ListTag) blockEntityTag.get("Patterns")) {
if (pattern instanceof CompoundTag) {
Tag c = ((CompoundTag) pattern).get("Color");
if (c instanceof NumberTag) {
// Invert color id
((CompoundTag) pattern).put("Color",
new IntTag(15 - ((NumberTag) c).asInt()));
}
ListTag patternsTag = blockEntityTag.getListTag("Patterns");
if (patternsTag != null) {
for (Tag pattern : patternsTag) {
if (!(pattern instanceof CompoundTag)) {
continue;
}
CompoundTag patternTag = (CompoundTag) pattern;
NumberTag colorTag = patternTag.getNumberTag("Color");
if (colorTag == null) {
continue;
}
// Invert color id
patternTag.putInt("Color", 15 - colorTag.asInt());
}
}
}
}
// Display Name now uses JSON
if (tag.get("display") instanceof CompoundTag) {
CompoundTag display = tag.get("display");
if (display.get("Name") instanceof StringTag) {
StringTag name = display.get("Name");
display.put(NBT_TAG_NAME + "|Name", new StringTag(name.getValue()));
CompoundTag display = tag.getCompoundTag("display");
if (display != null) {
StringTag name = display.getStringTag("Name");
if (name != null) {
display.putString(NBT_TAG_NAME + "|Name", name.getValue());
name.setValue(ComponentUtil.legacyToJsonString(name.getValue(), true));
}
}
// ench is now Enchantments and now uses identifiers
if (tag.get("ench") instanceof ListTag) {
ListTag ench = tag.get("ench");
ListTag ench = tag.getListTag("ench");
if (ench != null) {
ListTag enchantments = new ListTag(CompoundTag.class);
for (Tag enchEntry : ench) {
NumberTag idTag;
if (enchEntry instanceof CompoundTag && (idTag = ((CompoundTag) enchEntry).get("id")) != null) {
CompoundTag enchantmentEntry = new CompoundTag();
short oldId = idTag.asShort();
String newId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().get(oldId);
if (newId == null) {
newId = "viaversion:legacy/" + oldId;
}
enchantmentEntry.put("id", new StringTag(newId));
enchantmentEntry.put("lvl", new ShortTag(((NumberTag) ((CompoundTag) enchEntry).get("lvl")).asShort()));
enchantments.add(enchantmentEntry);
if (!(enchEntry instanceof CompoundTag)) {
continue;
}
CompoundTag entryTag = (CompoundTag) enchEntry;
NumberTag idTag = entryTag.getNumberTag("id");
if (idTag == null) {
continue;
}
CompoundTag enchantmentEntry = new CompoundTag();
short oldId = idTag.asShort();
String newId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().get(oldId);
if (newId == null) {
newId = "viaversion:legacy/" + oldId;
}
enchantmentEntry.putString("id", newId);
NumberTag levelTag = entryTag.getNumberTag("lvl");
if (levelTag != null) {
enchantmentEntry.putShort("lvl", levelTag.asShort());
}
enchantments.add(enchantmentEntry);
}
tag.remove("ench");
tag.put("Enchantments", enchantments);
}
if (tag.get("StoredEnchantments") instanceof ListTag) {
ListTag storedEnch = tag.get("StoredEnchantments");
ListTag storedEnch = tag.getListTag("StoredEnchantments");
if (storedEnch != null) {
ListTag newStoredEnch = new ListTag(CompoundTag.class);
for (Tag enchEntry : storedEnch) {
if (enchEntry instanceof CompoundTag) {
CompoundTag enchantmentEntry = new CompoundTag();
short oldId = ((NumberTag) ((CompoundTag) enchEntry).get("id")).asShort();
String newId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().get(oldId);
if (newId == null) {
newId = "viaversion:legacy/" + oldId;
}
enchantmentEntry.put("id", new StringTag(newId));
enchantmentEntry.put("lvl", new ShortTag(((NumberTag) ((CompoundTag) enchEntry).get("lvl")).asShort()));
newStoredEnch.add(enchantmentEntry);
if (!(enchEntry instanceof CompoundTag)) {
continue;
}
CompoundTag entryTag = (CompoundTag) enchEntry;
NumberTag idTag = entryTag.getNumberTag("id");
if (idTag == null) {
continue;
}
CompoundTag enchantmentEntry = new CompoundTag();
short oldId = idTag.asShort();
String newId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().get(oldId);
if (newId == null) {
newId = "viaversion:legacy/" + oldId;
}
enchantmentEntry.putString("id", newId);
NumberTag levelTag = entryTag.getNumberTag("lvl");
if (levelTag != null) {
enchantmentEntry.putShort("lvl", levelTag.asShort());
}
newStoredEnch.add(enchantmentEntry);
}
tag.remove("StoredEnchantments");
tag.put("StoredEnchantments", newStoredEnch);
}
if (tag.get("CanPlaceOn") instanceof ListTag) {
ListTag old = tag.get("CanPlaceOn");
ListTag canPlaceOnTag = tag.getListTag("CanPlaceOn");
if (canPlaceOnTag != null) {
ListTag newCanPlaceOn = new ListTag(StringTag.class);
tag.put(NBT_TAG_NAME + "|CanPlaceOn", old.copy());
for (Tag oldTag : old) {
tag.put(NBT_TAG_NAME + "|CanPlaceOn", canPlaceOnTag.copy());
for (Tag oldTag : canPlaceOnTag) {
Object value = oldTag.getValue();
String oldId = Key.stripMinecraftNamespace(value.toString());
String numberConverted = BlockIdData.numberIdToString.get(Ints.tryParse(oldId));
@ -380,11 +411,12 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
}
tag.put("CanPlaceOn", newCanPlaceOn);
}
if (tag.get("CanDestroy") instanceof ListTag) {
ListTag old = tag.get("CanDestroy");
ListTag canDestroyTag = tag.getListTag("CanDestroy");
if (canDestroyTag != null) {
ListTag newCanDestroy = new ListTag(StringTag.class);
tag.put(NBT_TAG_NAME + "|CanDestroy", old.copy());
for (Tag oldTag : old) {
tag.put(NBT_TAG_NAME + "|CanDestroy", canDestroyTag.copy());
for (Tag oldTag : canDestroyTag) {
Object value = oldTag.getValue();
String oldId = Key.stripMinecraftNamespace(value.toString());
String numberConverted = BlockIdData.numberIdToString.get(Ints.tryParse(oldId));
@ -404,17 +436,18 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
}
// Handle SpawnEggs
if (item.identifier() == 383) {
if (tag.get("EntityTag") instanceof CompoundTag) {
CompoundTag entityTag = tag.get("EntityTag");
if (entityTag.get("id") instanceof StringTag) {
StringTag identifier = entityTag.get("id");
rawId = SpawnEggRewriter.getSpawnEggId(identifier.getValue());
CompoundTag entityTag = tag.getCompoundTag("EntityTag");
if (entityTag != null) {
StringTag idTag = entityTag.getStringTag("id");
if (idTag != null) {
rawId = SpawnEggRewriter.getSpawnEggId(idTag.getValue());
if (rawId == -1) {
rawId = 25100288; // Bat fallback
} else {
entityTag.remove("id");
if (entityTag.isEmpty())
if (entityTag.isEmpty()) {
tag.remove("EntityTag");
}
}
} else {
// Fallback to bat
@ -492,8 +525,9 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
// Use tag to get original ID and data
if (tag != null) {
// Check for valid tag
if (tag.get(NBT_TAG_NAME) instanceof IntTag) {
rawId = ((NumberTag) tag.get(NBT_TAG_NAME)).asInt();
NumberTag viaTag = tag.getNumberTag(NBT_TAG_NAME);
if (viaTag != null) {
rawId = viaTag.asInt();
// Remove the tag
tag.remove(NBT_TAG_NAME);
gotRawIdFromTag = true;
@ -533,97 +567,130 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
// NBT changes
if (tag != null) {
if (isDamageable(item.identifier())) {
if (tag.get("Damage") instanceof IntTag) {
NumberTag damageTag = tag.getNumberTag("Damage");
if (damageTag != null) {
if (!gotRawIdFromTag) {
item.setData((short) (int) tag.get("Damage").getValue());
item.setData(damageTag.asShort());
}
tag.remove("Damage");
}
}
if (item.identifier() == 358) { // map
if (tag.get("map") instanceof IntTag) {
NumberTag mapTag = tag.getNumberTag("map");
if (mapTag != null) {
if (!gotRawIdFromTag) {
item.setData((short) (int) tag.get("map").getValue());
item.setData(mapTag.asShort());
}
tag.remove("map");
}
}
if (item.identifier() == 442 || item.identifier() == 425) { // shield / banner
if (tag.get("BlockEntityTag") instanceof CompoundTag) {
CompoundTag blockEntityTag = tag.get("BlockEntityTag");
if (blockEntityTag.get("Base") instanceof IntTag) {
IntTag base = blockEntityTag.get("Base");
base.setValue(15 - base.asInt()); // invert color id
CompoundTag blockEntityTag = tag.getCompoundTag("BlockEntityTag");
if (blockEntityTag != null) {
NumberTag baseTag = blockEntityTag.getNumberTag("Base");
if (baseTag != null) {
blockEntityTag.putInt("Base", 15 - baseTag.asInt()); // invert color id
}
if (blockEntityTag.get("Patterns") instanceof ListTag) {
for (Tag pattern : (ListTag) blockEntityTag.get("Patterns")) {
if (pattern instanceof CompoundTag) {
IntTag c = ((CompoundTag) pattern).get("Color");
c.setValue(15 - c.asInt()); // Invert color id
ListTag patternsTag = blockEntityTag.getListTag("Patterns");
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
}
}
}
}
// Display Name now uses JSON
if (tag.get("display") instanceof CompoundTag) {
CompoundTag display = tag.get("display");
if (display.get("Name") instanceof StringTag) {
StringTag name = display.get("Name");
StringTag via = display.remove(NBT_TAG_NAME + "|Name");
name.setValue(via != null ? via.getValue() : ComponentUtil.jsonToLegacy(name.getValue()));
CompoundTag display = tag.getCompoundTag("display");
if (display != null) {
StringTag name = display.getStringTag("Name");
if (name != null) {
Tag via = display.remove(NBT_TAG_NAME + "|Name");
name.setValue(via instanceof StringTag ? (String) via.getValue() : ComponentUtil.jsonToLegacy(name.getValue()));
}
}
// ench is now Enchantments and now uses identifiers
if (tag.get("Enchantments") instanceof ListTag) {
ListTag enchantments = tag.get("Enchantments");
ListTag enchantments = tag.getListTag("Enchantments");
if (enchantments != null) {
ListTag ench = new ListTag(CompoundTag.class);
for (Tag enchantmentEntry : enchantments) {
if (enchantmentEntry instanceof CompoundTag) {
CompoundTag enchEntry = new CompoundTag();
String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue();
Short oldId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().inverse().get(newId);
if (oldId == null && newId.startsWith("viaversion:legacy/")) {
oldId = Short.valueOf(newId.substring(18));
}
if (oldId != null) {
enchEntry.put("id", new ShortTag(oldId));
enchEntry.put("lvl", new ShortTag(((NumberTag) ((CompoundTag) enchantmentEntry).get("lvl")).asShort()));
ench.add(enchEntry);
if (!(enchantmentEntry instanceof CompoundTag)) {
continue;
}
CompoundTag entryTag = (CompoundTag) enchantmentEntry;
StringTag idTag = entryTag.getStringTag("id");
if (idTag == null) {
continue;
}
CompoundTag enchEntry = new CompoundTag();
String newId = idTag.getValue();
Short oldId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().inverse().get(newId);
if (oldId == null && newId.startsWith("viaversion:legacy/")) {
oldId = Short.valueOf(newId.substring(18));
}
if (oldId != null) {
enchEntry.putShort("id", oldId);
NumberTag levelTag = entryTag.getNumberTag("lvl");
if (levelTag != null) {
enchEntry.putShort("lvl", levelTag.asShort());
}
ench.add(enchEntry);
}
}
tag.remove("Enchantments");
tag.put("ench", ench);
}
if (tag.get("StoredEnchantments") instanceof ListTag) {
ListTag storedEnch = tag.get("StoredEnchantments");
ListTag storedEnch = tag.getListTag("StoredEnchantments");
if (storedEnch != null) {
ListTag newStoredEnch = new ListTag(CompoundTag.class);
for (Tag enchantmentEntry : storedEnch) {
if (enchantmentEntry instanceof CompoundTag) {
CompoundTag enchEntry = new CompoundTag();
String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue();
Short oldId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().inverse().get(newId);
if (oldId == null && newId.startsWith("viaversion:legacy/")) {
oldId = Short.valueOf(newId.substring(18));
}
if (oldId != null) {
enchEntry.put("id", new ShortTag(oldId));
enchEntry.put("lvl", new ShortTag(((NumberTag) ((CompoundTag) enchantmentEntry).get("lvl")).asShort()));
newStoredEnch.add(enchEntry);
}
if (!(enchantmentEntry instanceof CompoundTag)) {
continue;
}
CompoundTag entryTag = (CompoundTag) enchantmentEntry;
StringTag idTag = entryTag.getStringTag("id");
if (idTag == null) {
continue;
}
CompoundTag enchEntry = new CompoundTag();
String newId = idTag.getValue();
Short oldId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().inverse().get(newId);
if (oldId == null && newId.startsWith("viaversion:legacy/")) {
oldId = Short.valueOf(newId.substring(18));
}
if (oldId == null) {
continue;
}
enchEntry.putShort("id", oldId);
NumberTag levelTag = entryTag.getNumberTag("lvl");
if (levelTag != null) {
enchEntry.putShort("lvl", levelTag.asShort());
}
newStoredEnch.add(enchEntry);
}
tag.remove("StoredEnchantments");
tag.put("StoredEnchantments", newStoredEnch);
}
if (tag.get(NBT_TAG_NAME + "|CanPlaceOn") instanceof ListTag) {
if (tag.getListTag(NBT_TAG_NAME + "|CanPlaceOn") != null) {
tag.put("CanPlaceOn", tag.remove(NBT_TAG_NAME + "|CanPlaceOn"));
} else if (tag.get("CanPlaceOn") instanceof ListTag) {
ListTag old = tag.get("CanPlaceOn");
} else if (tag.getListTag("CanPlaceOn") != null) {
ListTag old = tag.getListTag("CanPlaceOn");
ListTag newCanPlaceOn = new ListTag(StringTag.class);
for (Tag oldTag : old) {
Object value = oldTag.getValue();
@ -640,10 +707,10 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
}
tag.put("CanPlaceOn", newCanPlaceOn);
}
if (tag.get(NBT_TAG_NAME + "|CanDestroy") instanceof ListTag) {
if (tag.getListTag(NBT_TAG_NAME + "|CanDestroy") != null) {
tag.put("CanDestroy", tag.remove(NBT_TAG_NAME + "|CanDestroy"));
} else if (tag.get("CanDestroy") instanceof ListTag) {
ListTag old = tag.get("CanDestroy");
} else if (tag.getListTag("CanDestroy") != null) {
ListTag old = tag.getListTag("CanDestroy");
ListTag newCanDestroy = new ListTag(StringTag.class);
for (Tag oldTag : old) {
Object value = oldTag.getValue();

Datei anzeigen

@ -18,9 +18,7 @@
package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
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;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
@ -50,7 +48,6 @@ import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.BlockSto
import com.viaversion.viaversion.util.Key;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
import java.util.Iterator;
import java.util.Optional;
@ -428,9 +425,9 @@ public class WorldPackets {
CompoundTag tag = iterator.next();
int newId = provider.transform(wrapper.user(), null, tag, false);
if (newId != -1) {
int x = ((NumberTag) tag.get("x")).asInt();
int y = ((NumberTag) tag.get("y")).asInt();
int z = ((NumberTag) tag.get("z")).asInt();
int x = tag.getNumberTag("x").asInt();
int y = tag.getNumberTag("y").asInt();
int z = tag.getNumberTag("z").asInt();
Position position = new Position(x, (short) y, z);
// Store the replacement blocks for blockupdates
@ -442,10 +439,10 @@ public class WorldPackets {
chunk.getSections()[y >> 4].palette(PaletteType.BLOCKS).setIdAt(x & 0xF, y & 0xF, z & 0xF, newId);
}
final Tag idTag = tag.get("id");
if (idTag instanceof StringTag) {
final StringTag idTag = tag.getStringTag("id");
if (idTag != null) {
// No longer block entities
final String id = Key.namespaced(((StringTag) idTag).getValue());
final String id = Key.namespaced(idTag.getValue());
if (id.equals("minecraft:noteblock") || id.equals("minecraft:flower_pot")) {
iterator.remove();
}

Datei anzeigen

@ -18,7 +18,7 @@
package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
@ -59,14 +59,13 @@ public class BlockEntityProvider implements Provider {
* @throws Exception Gotta throw that exception
*/
public int transform(UserConnection user, Position position, CompoundTag tag, boolean sendUpdate) throws Exception {
Tag idTag = tag.get("id");
StringTag idTag = tag.getStringTag("id");
if (idTag == null) return -1;
String id = (String) idTag.getValue();
BlockEntityHandler handler = handlers.get(id);
BlockEntityHandler handler = handlers.get(idTag.getValue());
if (handler == null) {
if (Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Unhandled BlockEntity " + id + " full tag: " + tag);
Via.getPlatform().getLogger().warning("Unhandled BlockEntity " + idTag.getValue() + " full tag: " + tag);
}
return -1;
}

Datei anzeigen

@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers;
import com.viaversion.viaversion.api.platform.providers.Provider;
import com.viaversion.viaversion.util.Key;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

Datei anzeigen

@ -18,7 +18,6 @@
package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.blockentities;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
@ -40,7 +39,7 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler {
@Override
public int transform(UserConnection user, CompoundTag tag) {
BlockStorage storage = user.get(BlockStorage.class);
Position position = new Position((int) getLong(tag.get("x")), (short) getLong(tag.get("y")), (int) getLong(tag.get("z")));
Position position = new Position(tag.getNumberTag("x").asInt(), tag.getNumberTag("y").asShort(), tag.getNumberTag("z").asInt());
if (!storage.contains(position)) {
Via.getPlatform().getLogger().warning("Received an banner color update packet, but there is no banner! O_o " + tag);
@ -49,11 +48,8 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler {
int blockId = storage.get(position).getOriginal();
Tag base = tag.get("Base");
int color = 0;
if (base instanceof NumberTag) {
color = ((NumberTag) base).asInt();
}
NumberTag base = tag.getNumberTag("Base");
int color = base != null ? base.asInt() : 0;
// Standing banner
if (blockId >= BANNER_START && blockId <= BANNER_STOP) {
blockId += ((15 - color) * 16);
@ -64,27 +60,26 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler {
Via.getPlatform().getLogger().warning("Why does this block have the banner block entity? :(" + tag);
}
Tag patterns = tag.get("Patterns");
if (patterns instanceof ListTag) {
for (Tag pattern : (ListTag) patterns) {
if (pattern instanceof CompoundTag) {
Tag c = ((CompoundTag) pattern).get("Color");
if (c instanceof IntTag) {
((IntTag) c).setValue(15 - (int) c.getValue()); // Invert color id
}
ListTag patterns = tag.getListTag("Patterns");
if (patterns != null) {
for (Tag pattern : patterns) {
if (!(pattern instanceof CompoundTag)) {
continue;
}
CompoundTag patternTag = (CompoundTag) pattern;
NumberTag colorTag = patternTag.getNumberTag("Color");
if (colorTag != null) {
patternTag.putInt("Color", 15 - colorTag.asInt()); // Invert color id
}
}
}
Tag name = tag.get("CustomName");
if (name instanceof StringTag) {
((StringTag) name).setValue(ComponentUtil.legacyToJsonString(((StringTag) name).getValue()));
StringTag name = tag.getStringTag("CustomName");
if (name != null) {
name.setValue(ComponentUtil.legacyToJsonString(name.getValue()));
}
return blockId;
}
private long getLong(NumberTag tag) {
return tag.asLong();
}
}

Datei anzeigen

@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.block
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
@ -31,7 +30,7 @@ public class BedHandler implements BlockEntityProvider.BlockEntityHandler {
@Override
public int transform(UserConnection user, CompoundTag tag) {
BlockStorage storage = user.get(BlockStorage.class);
Position position = new Position((int) getLong(tag.get("x")), (short) getLong(tag.get("y")), (int) getLong(tag.get("z")));
Position position = new Position(tag.getNumberTag("x").asInt(), tag.getNumberTag("y").asShort(), tag.getNumberTag("z").asInt());
if (!storage.contains(position)) {
Via.getPlatform().getLogger().warning("Received an bed color update packet, but there is no bed! O_o " + tag);
@ -41,15 +40,11 @@ public class BedHandler implements BlockEntityProvider.BlockEntityHandler {
// RED_BED + FIRST_BED
int blockId = storage.get(position).getOriginal() - 972 + 748;
Tag color = tag.get("color");
if (color instanceof NumberTag) {
blockId += (((NumberTag) color).asInt() * 16);
NumberTag color = tag.getNumberTag("color");
if (color != null) {
blockId += (color.asInt() * 16);
}
return blockId;
}
private long getLong(NumberTag tag) {
return tag.asLong();
}
}

Datei anzeigen

@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.block
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.viaversion.viaversion.api.Via;
@ -34,15 +33,16 @@ public class CommandBlockHandler implements BlockEntityProvider.BlockEntityHandl
@Override
public int transform(UserConnection user, CompoundTag tag) {
Tag name = tag.get("CustomName");
if (name instanceof StringTag) {
((StringTag) name).setValue(ComponentUtil.legacyToJsonString(((StringTag) name).getValue()));
StringTag name = tag.getStringTag("CustomName");
if (name != null) {
name.setValue(ComponentUtil.legacyToJsonString(name.getValue()));
}
Tag out = tag.get("LastOutput");
if (out instanceof StringTag) {
JsonElement value = JsonParser.parseString(((StringTag) out).getValue());
StringTag out = tag.getStringTag("LastOutput");
if (out != null) {
JsonElement value = JsonParser.parseString(out.getValue());
protocol.getComponentRewriter().processText(value);
((StringTag) out).setValue(value.toString());
out.setValue(value.toString());
}
return -1;
}

Datei anzeigen

@ -22,7 +22,6 @@ import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider;
import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.util.Pair;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

Datei anzeigen

@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.block
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
@ -33,7 +32,7 @@ public class SkullHandler implements BlockEntityProvider.BlockEntityHandler {
@Override
public int transform(UserConnection user, CompoundTag tag) {
BlockStorage storage = user.get(BlockStorage.class);
Position position = new Position((int) getLong(tag.get("x")), (short) getLong(tag.get("y")), (int) getLong(tag.get("z")));
Position position = new Position(tag.getNumberTag("x").asInt(), tag.getNumberTag("y").asShort(), tag.getNumberTag("z").asInt());
if (!storage.contains(position)) {
Via.getPlatform().getLogger().warning("Received an head update packet, but there is no head! O_o " + tag);
@ -42,13 +41,14 @@ public class SkullHandler implements BlockEntityProvider.BlockEntityHandler {
int id = storage.get(position).getOriginal();
if (id >= SKULL_WALL_START && id <= SKULL_END) {
Tag skullType = tag.get("SkullType");
if (skullType instanceof NumberTag) {
id += ((NumberTag) skullType).asInt() * 20;
NumberTag skullType = tag.getNumberTag("SkullType");
if (skullType != null) {
id += skullType.asInt() * 20;
}
Tag rot = tag.get("Rot");
if (rot instanceof NumberTag) {
id += ((NumberTag) rot).asInt();
NumberTag rot = tag.getNumberTag("Rot");
if (rot != null) {
id += rot.asInt();
}
} else {
Via.getPlatform().getLogger().warning("Why does this block have the skull block entity? " + tag);
@ -57,8 +57,4 @@ public class SkullHandler implements BlockEntityProvider.BlockEntityHandler {
return id;
}
private long getLong(NumberTag tag) {
return tag.asLong();
}
}

Datei anzeigen

@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.block
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.EntityNameRewriter;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider;
@ -27,13 +26,12 @@ import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.BlockE
public class SpawnerHandler implements BlockEntityProvider.BlockEntityHandler {
@Override
public int transform(UserConnection user, CompoundTag tag) {
Tag data = tag.get("SpawnData");
if (data instanceof CompoundTag) {
Tag id = ((CompoundTag) data).get("id");
if (id instanceof StringTag) {
((StringTag) id).setValue(EntityNameRewriter.rewrite(((StringTag) id).getValue()));
CompoundTag data = tag.getCompoundTag("SpawnData");
if (data != null) {
StringTag id = data.getStringTag("id");
if (id != null) {
id.setValue(EntityNameRewriter.rewrite(id.getValue()));
}
}
// Always return -1 because the block is still the same id

Datei anzeigen

@ -20,13 +20,12 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage;
import com.google.common.collect.EvictingQueue;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.viaversion.api.minecraft.Position;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import com.viaversion.viaversion.api.minecraft.Position;
import org.checkerframework.checker.nullness.qual.Nullable;
public class BlockConnectionStorage implements StorableObject {

Datei anzeigen

@ -18,6 +18,7 @@
package com.viaversion.viaversion.protocols.protocol1_14to1_13_2;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
@ -33,7 +34,6 @@ import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.packets.Inventor
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.packets.PlayerPackets;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.packets.WorldPackets;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.rewriter.CommandRewriter;
import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.rewriter.SoundRewriter;

Datei anzeigen

@ -36,11 +36,11 @@ public class MappingData extends MappingDataBase {
@Override
public void loadExtras(final CompoundTag data) {
final CompoundTag heightmap = MappingDataLoader.loadNBT("heightmap-1.14.nbt");
final IntArrayTag motionBlocking = heightmap.get("motionBlocking");
final IntArrayTag motionBlocking = heightmap.getIntArrayTag("motionBlocking");
this.motionBlocking = new IntOpenHashSet(motionBlocking.getValue());
if (Via.getConfig().isNonFullBlockLightFix()) {
final IntArrayTag nonFullBlocks = heightmap.get("nonFullBlocks");
final IntArrayTag nonFullBlocks = heightmap.getIntArrayTag("nonFullBlocks");
this.nonFullBlocks = new IntOpenHashSet(nonFullBlocks.getValue());
}
}

Datei anzeigen

@ -242,12 +242,10 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
if (item.tag() == null) return item;
// Display Lore now uses JSON
Tag displayTag = item.tag().get("display");
if (displayTag instanceof CompoundTag) {
CompoundTag display = (CompoundTag) displayTag;
Tag loreTag = display.get("Lore");
if (loreTag instanceof ListTag) {
ListTag lore = (ListTag) loreTag;
CompoundTag display = item.tag().getCompoundTag("display");
if (display != null) {
ListTag lore = display.getListTag("Lore");
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) {
@ -268,15 +266,13 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
if (item.tag() == null) return item;
// Display Name now uses JSON
Tag displayTag = item.tag().get("display");
if (displayTag instanceof CompoundTag) {
CompoundTag display = (CompoundTag) displayTag;
Tag loreTag = display.get("Lore");
if (loreTag instanceof ListTag) {
ListTag lore = (ListTag) loreTag;
ListTag savedLore = display.remove(NBT_TAG_NAME + "|Lore");
if (savedLore != null) {
display.put("Lore", new ListTag(savedLore.getValue()));
CompoundTag display = item.tag().getCompoundTag("display");
if (display != null) {
ListTag lore = display.getListTag("Lore");
if (lore != null) {
Tag savedLore = display.remove(NBT_TAG_NAME + "|Lore");
if (savedLore instanceof ListTag) {
display.put("Lore", new ListTag(((ListTag) savedLore).getValue()));
} else {
for (Tag loreEntry : lore) {
if (loreEntry instanceof StringTag) {

Datei anzeigen

@ -20,7 +20,6 @@ package com.viaversion.viaversion.protocols.protocol1_14to1_13_2.packets;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
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.Position;
import com.viaversion.viaversion.api.minecraft.item.Item;
@ -58,7 +57,7 @@ public class PlayerPackets {
CompoundTag tag = item.tag();
if (tag == null) return;
Tag pages = tag.get("pages");
ListTag pages = tag.getListTag("pages");
// Fix for https://github.com/ViaVersion/ViaVersion/issues/2660
if (pages == null) {
@ -66,10 +65,9 @@ public class PlayerPackets {
}
// 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 instanceof ListTag) {
ListTag listTag = (ListTag) pages;
if (listTag.size() > 50) {
listTag.setValue(listTag.getValue().subList(0, 50));
if (Via.getConfig().isTruncate1_14Books() && pages != null) {
if (pages.size() > 50) {
pages.setValue(pages.getValue().subList(0, 50));
}
}
});

Datei anzeigen

@ -22,6 +22,7 @@ import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.BlockFace;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
@ -30,13 +31,12 @@ import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_13;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_14;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_14;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.rewriter.BlockRewriter;
import com.viaversion.viaversion.util.CompactArrayUtil;
import java.util.Arrays;

Datei anzeigen

@ -23,10 +23,10 @@ import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_14_4to1_14_3.ClientboundPackets1_14_4;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_14;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_15;
import com.viaversion.viaversion.protocols.protocol1_14_4to1_14_3.ClientboundPackets1_14_4;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
import com.viaversion.viaversion.rewriter.BlockRewriter;
public final class WorldPackets {

Datei anzeigen

@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.data;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
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.data.MappingDataBase;
import com.viaversion.viaversion.api.data.MappingDataLoader;
@ -39,12 +38,12 @@ public class MappingData extends MappingDataBase {
dimensionRegistry = MappingDataLoader.loadNBTFromFile("dimension-registry-1.16.2.nbt");
// Data of each dimension
final ListTag dimensions = ((CompoundTag) dimensionRegistry.get("minecraft:dimension_type")).get("value");
final ListTag dimensions = dimensionRegistry.getCompoundTag("minecraft:dimension_type").get("value");
for (final Tag dimension : dimensions) {
final CompoundTag dimensionCompound = (CompoundTag) dimension;
// Copy with an empty name
final CompoundTag dimensionData = new CompoundTag(((CompoundTag) dimensionCompound.get("element")).getValue());
dimensionDataMap.put(((StringTag) dimensionCompound.get("name")).getValue(), dimensionData);
final CompoundTag dimensionData = dimensionCompound.getCompoundTag("element").copy();
dimensionDataMap.put(dimensionCompound.getStringTag("name").getValue(), dimensionData);
}
}

Datei anzeigen

@ -25,11 +25,11 @@ import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_16;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_16_2;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_16_2;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_16;
import com.viaversion.viaversion.rewriter.BlockRewriter;
import java.util.ArrayList;
import java.util.List;

Datei anzeigen

@ -48,7 +48,6 @@ import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;
import com.viaversion.viaversion.util.GsonUtil;
import com.viaversion.viaversion.util.Key;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

Datei anzeigen

@ -17,7 +17,13 @@
*/
package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets;
import com.github.steveice10.opennbt.tag.builtin.*;
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.FloatTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.LongTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.WorldIdentifiers;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16;
@ -33,7 +39,6 @@ import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPacke
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.metadata.MetadataRewriter1_16To1_15_2;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16;
import com.viaversion.viaversion.util.Key;
import java.util.Arrays;
import java.util.UUID;

Datei anzeigen

@ -20,7 +20,6 @@ package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets;
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.LongTag;
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
@ -147,22 +146,22 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
CompoundTag tag = item.tag();
if (item.identifier() == 771 && tag != null) {
Tag ownerTag = tag.get("SkullOwner");
if (ownerTag instanceof CompoundTag) {
CompoundTag ownerCompundTag = (CompoundTag) ownerTag;
Tag idTag = ownerCompundTag.get("Id");
if (idTag instanceof StringTag) {
UUID id = UUID.fromString((String) idTag.getValue());
ownerCompundTag.put("Id", new IntArrayTag(UUIDUtil.toIntArray(id)));
CompoundTag ownerTag = tag.getCompoundTag("SkullOwner");
if (ownerTag != null) {
StringTag idTag = ownerTag.getStringTag("Id");
if (idTag != null) {
UUID id = UUID.fromString(idTag.getValue());
ownerTag.put("Id", new IntArrayTag(UUIDUtil.toIntArray(id)));
}
}
} else if (item.identifier() == 759 && tag != null) {
Tag pages = tag.get("pages");
if (pages instanceof ListTag) {
for (Tag pageTag : (ListTag) pages) {
ListTag pages = tag.getListTag("pages");
if (pages != null) {
for (Tag pageTag : pages) {
if (!(pageTag instanceof StringTag)) {
continue;
}
StringTag page = (StringTag) pageTag;
page.setValue(protocol.getComponentRewriter().processText(page.getValue()).toString());
}
@ -182,13 +181,12 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
if (item.identifier() == 771 && item.tag() != null) {
CompoundTag tag = item.tag();
Tag ownerTag = tag.get("SkullOwner");
if (ownerTag instanceof CompoundTag) {
CompoundTag ownerCompundTag = (CompoundTag) ownerTag;
Tag idTag = ownerCompundTag.get("Id");
if (idTag instanceof IntArrayTag) {
UUID id = UUIDUtil.fromIntArray((int[]) idTag.getValue());
ownerCompundTag.put("Id", new StringTag(id.toString()));
CompoundTag ownerTag = tag.getCompoundTag("SkullOwner");
if (ownerTag != null) {
IntArrayTag idTag = ownerTag.getIntArrayTag("Id");
if (idTag != null) {
UUID id = UUIDUtil.fromIntArray(idTag.getValue());
ownerTag.putString("Id", id.toString());
}
}
}
@ -200,17 +198,19 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
public static void oldToNewAttributes(Item item) {
if (item.tag() == null) return;
ListTag attributes = item.tag().get("AttributeModifiers");
ListTag attributes = item.tag().getListTag("AttributeModifiers");
if (attributes == null) return;
for (Tag tag : attributes) {
if (!(tag instanceof CompoundTag)) continue;
CompoundTag attribute = (CompoundTag) tag;
rewriteAttributeName(attribute, "AttributeName", false);
rewriteAttributeName(attribute, "Name", false);
Tag leastTag = attribute.get("UUIDLeast");
if (leastTag != null) {
Tag mostTag = attribute.get("UUIDMost");
int[] uuidIntArray = UUIDUtil.toIntArray(((NumberTag) leastTag).asLong(), ((NumberTag) mostTag).asLong());
NumberTag leastTag = attribute.getNumberTag("UUIDLeast");
NumberTag mostTag = attribute.getNumberTag("UUIDMost");
if (leastTag != null && mostTag != null) {
int[] uuidIntArray = UUIDUtil.toIntArray(leastTag.asLong(), mostTag.asLong());
attribute.put("UUID", new IntArrayTag(uuidIntArray));
}
}
@ -219,24 +219,26 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
public static void newToOldAttributes(Item item) {
if (item.tag() == null) return;
ListTag attributes = item.tag().get("AttributeModifiers");
ListTag attributes = item.tag().getListTag("AttributeModifiers");
if (attributes == null) return;
for (Tag tag : attributes) {
if (!(tag instanceof CompoundTag)) continue;
CompoundTag attribute = (CompoundTag) tag;
rewriteAttributeName(attribute, "AttributeName", true);
rewriteAttributeName(attribute, "Name", true);
IntArrayTag uuidTag = attribute.get("UUID");
IntArrayTag uuidTag = attribute.getIntArrayTag("UUID");
if (uuidTag != null && uuidTag.getValue().length == 4) {
UUID uuid = UUIDUtil.fromIntArray(uuidTag.getValue());
attribute.put("UUIDLeast", new LongTag(uuid.getLeastSignificantBits()));
attribute.put("UUIDMost", new LongTag(uuid.getMostSignificantBits()));
attribute.putLong("UUIDLeast", uuid.getLeastSignificantBits());
attribute.putLong("UUIDMost", uuid.getMostSignificantBits());
}
}
}
public static void rewriteAttributeName(CompoundTag compoundTag, String entryName, boolean inverse) {
StringTag attributeNameTag = compoundTag.get(entryName);
StringTag attributeNameTag = compoundTag.getStringTag(entryName);
if (attributeNameTag == null) return;
String attributeName = attributeNameTag.getValue();

Datei anzeigen

@ -29,10 +29,10 @@ import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_15;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_16;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
import com.viaversion.viaversion.rewriter.BlockRewriter;
import com.viaversion.viaversion.util.CompactArrayUtil;
import com.viaversion.viaversion.util.UUIDUtil;
@ -102,7 +102,7 @@ public class WorldPackets {
}
private static void handleBlockEntity(Protocol1_16To1_15_2 protocol, CompoundTag compoundTag) {
StringTag idTag = compoundTag.get("id");
StringTag idTag = compoundTag.getStringTag("id");
if (idTag == null) return;
String id = idTag.getValue();
@ -113,11 +113,11 @@ public class WorldPackets {
// target_uuid -> Target
UUID targetUuid = UUID.fromString((String) targetUuidTag.getValue());
compoundTag.put("Target", new IntArrayTag(UUIDUtil.toIntArray(targetUuid)));
} else if (id.equals("minecraft:skull") && compoundTag.get("Owner") instanceof CompoundTag) {
} else if (id.equals("minecraft:skull") && compoundTag.getCompoundTag("Owner") != null) {
CompoundTag ownerTag = compoundTag.remove("Owner");
StringTag ownerUuidTag = ownerTag.remove("Id");
if (ownerUuidTag != null) {
UUID ownerUuid = UUID.fromString(ownerUuidTag.getValue());
Tag ownerUuidTag = ownerTag.remove("Id");
if (ownerUuidTag instanceof StringTag) {
UUID ownerUuid = UUID.fromString(((StringTag) ownerUuidTag).getValue());
ownerTag.put("Id", new IntArrayTag(UUIDUtil.toIntArray(ownerUuid)));
}
@ -129,21 +129,18 @@ public class WorldPackets {
compoundTag.put("SkullOwner", skullOwnerTag);
} else if (id.equals("minecraft:sign")) {
for (int i = 1; i <= 4; i++) {
Tag line = compoundTag.get("Text" + i);
if (line instanceof StringTag) {
JsonElement text = protocol.getComponentRewriter().processText(((StringTag) line).getValue());
compoundTag.put("Text" + i, new StringTag(text.toString()));
StringTag line = compoundTag.getStringTag("Text" + i);
if (line != null) {
JsonElement text = protocol.getComponentRewriter().processText(line.getValue());
compoundTag.putString("Text" + i, text.toString());
}
}
} else if (id.equals("minecraft:mob_spawner")) {
Tag spawnDataTag = compoundTag.get("SpawnData");
if (spawnDataTag instanceof CompoundTag) {
Tag spawnDataIdTag = ((CompoundTag) spawnDataTag).get("id");
if (spawnDataIdTag instanceof StringTag) {
StringTag spawnDataIdStringTag = ((StringTag) spawnDataIdTag);
if (spawnDataIdStringTag.getValue().equals("minecraft:zombie_pigman")) {
spawnDataIdStringTag.setValue("minecraft:zombified_piglin");
}
CompoundTag spawnDataTag = compoundTag.getCompoundTag("SpawnData");
if (spawnDataTag != null) {
StringTag spawnDataIdTag = spawnDataTag.getStringTag("id");
if (spawnDataIdTag != null && spawnDataIdTag.getValue().equals("minecraft:zombie_pigman")) {
spawnDataIdTag.setValue("minecraft:zombified_piglin");
}
}
}

Datei anzeigen

@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
@ -135,7 +134,7 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_16_
if (tag == null) {
item.setTag(tag = new CompoundTag());
}
if (!(tag.get("map") instanceof NumberTag)) {
if (tag.getNumberTag("map") == null) {
tag.put("map", new IntTag(0));
}
}

Datei anzeigen

@ -27,11 +27,11 @@ import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_16_2;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_17;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_17;
import com.viaversion.viaversion.rewriter.BlockRewriter;
import java.util.ArrayList;
import java.util.BitSet;

Datei anzeigen

@ -20,7 +20,6 @@ package com.viaversion.viaversion.protocols.protocol1_18to1_17_1.packets;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
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.data.entity.EntityTracker;
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
@ -33,12 +32,12 @@ import com.viaversion.viaversion.api.minecraft.chunks.DataPaletteImpl;
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_17_1to1_17.ClientboundPackets1_17_1;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_17;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18;
import com.viaversion.viaversion.protocols.protocol1_17_1to1_17.ClientboundPackets1_17_1;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.BlockEntityIds;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.Protocol1_18To1_17_1;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.storage.ChunkLightStorage;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18;
import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.util.MathUtil;
import java.util.ArrayList;
@ -107,10 +106,10 @@ public final class WorldPackets {
final List<BlockEntity> blockEntities = new ArrayList<>(oldChunk.getBlockEntities().size());
for (final CompoundTag tag : oldChunk.getBlockEntities()) {
final NumberTag xTag = tag.get("x");
final NumberTag yTag = tag.get("y");
final NumberTag zTag = tag.get("z");
final StringTag idTag = tag.get("id");
final NumberTag xTag = tag.getNumberTag("x");
final NumberTag yTag = tag.getNumberTag("y");
final NumberTag zTag = tag.getNumberTag("z");
final StringTag idTag = tag.getStringTag("id");
if (xTag == null || yTag == null || zTag == null || idTag == null) {
continue;
}
@ -203,8 +202,8 @@ public final class WorldPackets {
private static void handleSpawners(int typeId, final CompoundTag tag) {
if (typeId == 8) {
final Tag entity = tag.get("SpawnData");
if (entity instanceof CompoundTag) {
final CompoundTag entity = tag.getCompoundTag("SpawnData");
if (entity != null) {
final CompoundTag spawnData = new CompoundTag();
tag.put("SpawnData", spawnData);
spawnData.put("entity", entity);

Datei anzeigen

@ -222,7 +222,7 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
chatTypeStorage.clear();
final CompoundTag registry = wrapper.passthrough(Type.NAMED_COMPOUND_TAG);
final ListTag chatTypes = ((CompoundTag) registry.get("minecraft:chat_type")).get("value");
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");
@ -342,10 +342,10 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
return null;
}
CompoundTag chatData = chatType.<CompoundTag>get("element").get("chat");
CompoundTag chatData = chatType.getCompoundTag("element").getCompoundTag("chat");
boolean overlay = false;
if (chatData == null) {
chatData = chatType.<CompoundTag>get("element").get("overlay");
chatData = chatType.getCompoundTag("element").getCompoundTag("overlay");
if (chatData == null) {
// Either narration or something we don't know
return null;
@ -354,7 +354,7 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
overlay = true;
}
final CompoundTag decoration = chatData.get("decoration");
final CompoundTag decoration = chatData.getCompoundTag("decoration");
if (decoration == null) {
return new ChatDecorationResult(message, overlay);
}
@ -368,13 +368,13 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
@Nullable final JsonElement targetName,
final JsonElement message
) {
final String translationKey = (String) tag.get("translation_key").getValue();
final String translationKey = tag.getStringTag("translation_key").getValue();
final Style style = new Style();
// Add the style
final CompoundTag styleTag = tag.get("style");
final CompoundTag styleTag = tag.getCompoundTag("style");
if (styleTag != null) {
final StringTag color = styleTag.get("color");
final StringTag color = styleTag.getStringTag("color");
if (color != null) {
final TextFormatting textColor = TextFormatting.getByName(color.getValue());
if (textColor != null) {
@ -383,12 +383,12 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
}
for (final Map.Entry<String, TextFormatting> entry : TextFormatting.FORMATTINGS.entrySet()) {
final Tag formattingTag = styleTag.get(entry.getKey());
final NumberTag formattingTag = styleTag.getNumberTag(entry.getKey());
if (!(formattingTag instanceof ByteTag)) {
continue;
}
final boolean value = ((NumberTag) formattingTag).asBoolean();
final boolean value = formattingTag.asBoolean();
final TextFormatting formatting = entry.getValue();
if (formatting == TextFormatting.OBFUSCATED) {
style.setObfuscated(value);
@ -405,7 +405,7 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
}
// Add the replacements
final ListTag parameters = tag.get("parameters");
final ListTag parameters = tag.getListTag("parameters");
final List<ATextComponent> arguments = new ArrayList<>();
if (parameters != null) {
for (final Tag element : parameters) {

Datei anzeigen

@ -29,7 +29,6 @@ import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ClientboundPacke
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3;
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.Protocol1_19_3To1_19_1;
import com.viaversion.viaversion.rewriter.EntityRewriter;
import java.util.BitSet;
import java.util.UUID;

Datei anzeigen

@ -31,7 +31,6 @@ import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
@ -210,7 +209,7 @@ 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 = ((CompoundTag) tag.get("minecraft:dimension_type")).get("value");
final ListTag dimensions = tag.getCompoundTag("minecraft:dimension_type").get("value");
final Map<String, DimensionData> dimensionDataMap = new HashMap<>(dimensions.size());
final Map<CompoundTag, String> dimensionsMap = new HashMap<>(dimensions.size());
for (final Tag dimension : dimensions) {

Datei anzeigen

@ -24,8 +24,8 @@ import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18;
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.Protocol1_19To1_18_2;
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ServerboundPackets1_19;
import com.viaversion.viaversion.rewriter.BlockRewriter;

Datei anzeigen

@ -36,11 +36,11 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2;
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4;
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.rewriter.RecipeRewriter1_19_4;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.Protocol1_20_2To1_20;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundPackets1_20_2;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.util.PotionEffects;
import com.viaversion.viaversion.rewriter.BlockRewriter;
import com.viaversion.viaversion.rewriter.ItemRewriter;
@ -441,14 +441,14 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
return null;
}
final IntTag primaryEffect = tag.remove("Primary");
if (primaryEffect != null && primaryEffect.asInt() != 0) {
tag.put("primary_effect", new StringTag(PotionEffects.idToKeyOrLuck(primaryEffect.asInt())));
final Tag primaryEffect = tag.remove("Primary");
if (primaryEffect instanceof NumberTag && ((NumberTag) primaryEffect).asInt() != 0) {
tag.put("primary_effect", new StringTag(PotionEffects.idToKeyOrLuck(((NumberTag) primaryEffect).asInt())));
}
final IntTag secondaryEffect = tag.remove("Secondary");
if (secondaryEffect != null && secondaryEffect.asInt() != 0) {
tag.put("secondary_effect", new StringTag(PotionEffects.idToKeyOrLuck(secondaryEffect.asInt())));
final Tag secondaryEffect = tag.remove("Secondary");
if (secondaryEffect instanceof NumberTag && ((NumberTag) secondaryEffect).asInt() != 0) {
tag.put("secondary_effect", new StringTag(PotionEffects.idToKeyOrLuck(((NumberTag) secondaryEffect).asInt())));
}
return tag;
}

Datei anzeigen

@ -150,11 +150,11 @@ public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter<Clientboun
}
private void updatePages(final CompoundTag tag, final String key) {
if (!(tag.get(key) instanceof ListTag)) {
final ListTag pages = tag.getListTag(key);
if (pages == null) {
return;
}
final ListTag pages = tag.get(key);
for (final Tag pageTag : pages) {
if (!(pageTag instanceof StringTag)) {
continue;

Datei anzeigen

@ -22,6 +22,7 @@ import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.google.gson.JsonElement;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
@ -32,10 +33,9 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_1;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.chunks.FakeTileEntity;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_1;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ServerboundPackets1_9;
import java.util.List;

Datei anzeigen

@ -25,7 +25,6 @@ import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.util.Key;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@ -162,10 +161,10 @@ public class ItemRewriter {
if (item.identifier() == 383 && item.data() == 0) { // Monster Egg
CompoundTag tag = item.tag();
int data = 0;
if (tag != null && tag.get("EntityTag") instanceof CompoundTag) {
CompoundTag entityTag = tag.get("EntityTag");
if (entityTag.get("id") instanceof StringTag) {
StringTag id = entityTag.get("id");
if (tag != null && tag.getCompoundTag("EntityTag") != null) {
CompoundTag entityTag = tag.getCompoundTag("EntityTag");
StringTag id = entityTag.getStringTag("id");
if (id != null) {
if (ENTITY_NAME_TO_ID.containsKey(id.getValue()))
data = ENTITY_NAME_TO_ID.get(id.getValue());
}
@ -177,8 +176,8 @@ public class ItemRewriter {
if (item.identifier() == 373) { // Potion
CompoundTag tag = item.tag();
int data = 0;
if (tag != null && tag.get("Potion") instanceof StringTag) {
StringTag potion = tag.get("Potion");
if (tag != null && tag.getStringTag("Potion") != null) {
StringTag potion = tag.getStringTag("Potion");
String potionName = Key.stripMinecraftNamespace(potion.getValue());
if (POTION_NAME_TO_ID.containsKey(potionName)) {
data = POTION_NAME_TO_ID.get(potionName);
@ -193,8 +192,8 @@ public class ItemRewriter {
CompoundTag tag = item.tag();
int data = 0;
item.setIdentifier(373); // Potion
if (tag != null && tag.get("Potion") instanceof StringTag) {
StringTag potion = tag.get("Potion");
if (tag != null && tag.getStringTag("Potion") != null) {
StringTag potion = tag.getStringTag("Potion");
String potionName = Key.stripMinecraftNamespace(potion.getValue());
if (POTION_NAME_TO_ID.containsKey(potionName)) {
data = POTION_NAME_TO_ID.get(potionName) + 8192;
@ -220,11 +219,13 @@ public class ItemRewriter {
if (id != 387) {
return;
}
CompoundTag tag = item.tag();
ListTag pages = tag.get("pages");
if (pages == null) { // is this even possible?
ListTag pages = tag.getListTag("pages");
if (pages == null) {
return;
}
for (int i = 0; i < pages.size(); i++) {
Tag pageTag = pages.get(i);
if (!(pageTag instanceof StringTag)) {
@ -287,7 +288,8 @@ public class ItemRewriter {
if (tag == null) {
tag = new CompoundTag();
}
ListTag pages = tag.get("pages");
ListTag pages = tag.getListTag("pages");
if (pages == null) {
pages = new ListTag(Collections.singletonList(new StringTag(Protocol1_9To1_8.fixJson("").toString())));
tag.put("pages", pages);

Datei anzeigen

@ -32,9 +32,23 @@ import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
import com.viaversion.viaversion.protocols.protocol1_8.ServerboundPackets1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.metadata.MetadataRewriter1_9To1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.packets.*;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.*;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.*;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.packets.EntityPackets;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.packets.InventoryPackets;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.packets.PlayerPackets;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.packets.SpawnPackets;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.packets.WorldPackets;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.BossBarProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.CommandBlockProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.CompressionProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.EntityIdProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MainHandProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.ClientChunks;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.CommandBlockStorage;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.InventoryTracker;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker;
import com.viaversion.viaversion.util.GsonUtil;
public class Protocol1_9To1_8 extends AbstractProtocol<ClientboundPackets1_8, ClientboundPackets1_9, ServerboundPackets1_8, ServerboundPackets1_9> {

Datei anzeigen

@ -17,8 +17,8 @@
*/
package com.viaversion.viaversion.protocols.protocol1_9to1_8.metadata;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_8;
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9;
import com.viaversion.viaversion.util.Pair;

Datei anzeigen

@ -36,8 +36,11 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.metadata.MetadataRew
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
import com.viaversion.viaversion.util.Pair;
import com.viaversion.viaversion.util.Triple;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class EntityPackets {
public static final ValueTransformer<Byte, Short> toNewShort = new ValueTransformer<Byte, Short>(Type.SHORT) {

Datei anzeigen

@ -21,6 +21,7 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.BlockFace;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
@ -30,10 +31,11 @@ import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.BulkChunkType1_8;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_8;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_1;
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
import com.viaversion.viaversion.protocols.protocol1_8.ServerboundPackets1_8;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_1;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
@ -43,8 +45,6 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.sounds.Effect;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.sounds.SoundEffect;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.ClientChunks;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_8;
import com.viaversion.viaversion.api.type.types.chunk.BulkChunkType1_8;
import java.util.ArrayList;
import java.util.Optional;
@ -215,14 +215,15 @@ public class WorldPackets {
if (action == 1) { // Update Spawner
CompoundTag tag = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
if (tag != null) {
if (tag.contains("EntityId")) {
String entity = (String) tag.get("EntityId").getValue();
StringTag entityId = tag.getStringTag("EntityId");
if (entityId != null) {
String entity = entityId.getValue();
CompoundTag spawn = new CompoundTag();
spawn.put("id", new StringTag(entity));
spawn.putString("id", entity);
tag.put("SpawnData", spawn);
} else { // EntityID does not exist
CompoundTag spawn = new CompoundTag();
spawn.put("id", new StringTag("AreaEffectCloud")); //Make spawners show up as empty when no EntityId is given.
spawn.putString("id", "AreaEffectCloud"); //Make spawners show up as empty when no EntityId is given.
tag.put("SpawnData", spawn);
}
}

Datei anzeigen

@ -26,7 +26,6 @@ import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_8.ServerboundPackets1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker;
import java.util.logging.Level;
public class MovementTransmitterProvider implements Provider {

Datei anzeigen

@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.protocol1_9to1_8.storage;
import com.google.common.collect.Sets;
import com.viaversion.viaversion.api.connection.StorableObject;
import java.util.Set;
public class ClientChunks implements StorableObject {

Datei anzeigen

@ -267,24 +267,24 @@ public class ComponentRewriter<C extends ClientboundPacketType> {
}
protected void processCompoundTag(final CompoundTag tag) {
final Tag translate = tag.get("translate");
if (translate instanceof StringTag) {
handleTranslate(tag, ((StringTag) translate));
final StringTag translate = tag.getStringTag("translate");
if (translate != null) {
handleTranslate(tag, translate);
final Tag with = tag.get("with");
if (with instanceof ListTag) {
processListTag((ListTag) with);
final ListTag with = tag.getListTag("with");
if (with != null) {
processListTag(with);
}
}
final Tag extra = tag.get("extra");
if (extra instanceof ListTag) {
processListTag((ListTag) extra);
final ListTag extra = tag.getListTag("extra");
if (extra != null) {
processListTag(extra);
}
final Tag hoverEvent = tag.get("hoverEvent");
if (hoverEvent instanceof CompoundTag) {
handleHoverEvent((CompoundTag) hoverEvent);
final CompoundTag hoverEvent = tag.getCompoundTag("hoverEvent");
if (hoverEvent != null) {
handleHoverEvent(hoverEvent);
}
}
@ -294,19 +294,19 @@ public class ComponentRewriter<C extends ClientboundPacketType> {
protected void handleHoverEvent(final CompoundTag hoverEventTag) {
// To override if needed (don't forget to call super)
final Tag actionTag = hoverEventTag.get("action");
if (!(actionTag instanceof StringTag)) {
final StringTag actionTag = hoverEventTag.getStringTag("action");
if (actionTag == null) {
return;
}
final String action = ((StringTag) actionTag).getValue();
final String action = actionTag.getValue();
if (action.equals("show_text")) {
final Tag value = hoverEventTag.get("value");
processTag(value != null ? value : hoverEventTag.get("contents"));
} else if (action.equals("show_entity")) {
final Tag contents = hoverEventTag.get("contents");
if (contents instanceof CompoundTag) {
processTag(((CompoundTag) contents).get("name"));
final CompoundTag contents = hoverEventTag.getCompoundTag("contents");
if (contents != null) {
processTag(contents.get("name"));
}
}
}

Datei anzeigen

@ -18,10 +18,9 @@
package com.viaversion.viaversion.rewriter;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
@ -393,17 +392,17 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
EntityTracker tracker = tracker(wrapper.user());
CompoundTag registryData = wrapper.get(Type.NAMED_COMPOUND_TAG, nbtIndex);
Tag height = registryData.get("height");
if (height instanceof IntTag) {
int blockHeight = ((IntTag) height).asInt();
NumberTag height = registryData.getNumberTag("height");
if (height != null) {
int blockHeight = height.asInt();
tracker.setCurrentWorldSectionHeight(blockHeight >> 4);
} else {
Via.getPlatform().getLogger().warning("Height missing in dimension data: " + registryData);
}
Tag minY = registryData.get("min_y");
if (minY instanceof IntTag) {
tracker.setCurrentMinY(((IntTag) minY).asInt());
NumberTag minY = registryData.getNumberTag("min_y");
if (minY != null) {
tracker.setCurrentMinY(minY.asInt());
} else {
Via.getPlatform().getLogger().warning("Min Y missing in dimension data: " + registryData);
}
@ -466,12 +465,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 = ((CompoundTag) registry.get("minecraft:dimension_type")).get("value");
final ListTag dimensions = registry.getCompoundTag("minecraft:dimension_type").get("value");
final Map<String, DimensionData> dimensionDataMap = new HashMap<>(dimensions.size());
for (final Tag dimension : dimensions) {
final CompoundTag dimensionCompound = (CompoundTag) dimension;
final CompoundTag element = dimensionCompound.get("element");
final String name = (String) dimensionCompound.get("name").getValue();
final String name = dimensionCompound.getStringTag("name").getValue();
dimensionDataMap.put(name, new DimensionDataImpl(element));
}
tracker(connection).setDimensions(dimensionDataMap);

Datei anzeigen

@ -21,9 +21,8 @@ import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.entity.TrackedEntity;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable;
public interface MetaHandlerEvent {

Datei anzeigen

@ -21,7 +21,6 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.util.GsonUtil;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@ -29,7 +28,6 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Locale;
import java.util.UUID;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class UpdateUtil {

Datei anzeigen

@ -17,12 +17,12 @@
*/
package com.viaversion.viaversion.common.entities;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_15;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16_2;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_17;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import java.util.function.Function;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Datei anzeigen

@ -5,7 +5,7 @@ metadata.format.version = "1.1"
gson = "2.10.1"
fastutil = "8.5.12"
flare = "2.0.1"
vianbt = "4.0.1"
vianbt = "4.2.0"
mcstructs = "2.4.2-SNAPSHOT"
# Common provided