Update nbt usage

This commit is contained in:
KennyTV 2021-03-14 16:57:37 +01:00 committed by Nassim
parent 2f7de53e9b
commit 388eb73782
24 changed files with 212 additions and 242 deletions

View File

@ -3,7 +3,7 @@ object Versions {
const val adventure = "4.6.0" const val adventure = "4.6.0"
const val gson = "2.8.6" const val gson = "2.8.6"
const val fastUtil = "8.3.1" const val fastUtil = "8.3.1"
const val openNBT = "1.2-SNAPSHOT" const val openNBT = "2.0-SNAPSHOT"
const val javassist = "3.27.0-GA" const val javassist = "3.27.0-GA"
// Common provided // Common provided

View File

@ -10,7 +10,7 @@ blossom {
dependencies { dependencies {
api(project(":adventure", "shadow")) api(project(":adventure", "shadow"))
api("it.unimi.dsi", "fastutil", Versions.fastUtil) api("it.unimi.dsi", "fastutil", Versions.fastUtil)
api("com.github.steveice10", "opennbt", Versions.openNBT) api("com.viaversion", "opennbt", Versions.openNBT)
api("com.google.code.gson", "gson", Versions.gson) api("com.google.code.gson", "gson", Versions.gson)
compileOnlyApi("org.yaml", "snakeyaml", Versions.snakeYaml) compileOnlyApi("org.yaml", "snakeyaml", Versions.snakeYaml)

View File

@ -23,7 +23,6 @@
*/ */
package us.myles.ViaVersion.api.minecraft.nbt; package us.myles.ViaVersion.api.minecraft.nbt;
import com.github.steveice10.opennbt.tag.TagRegistry;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -109,12 +108,12 @@ public final class BinaryTagIO {
@NotNull @NotNull
public static CompoundTag readDataInput(final @NotNull DataInput input) throws IOException { public static CompoundTag readDataInput(final @NotNull DataInput input) throws IOException {
byte type = input.readByte(); byte type = input.readByte();
if (type != TagRegistry.getIdFor(CompoundTag.class)) { if (type != CompoundTag.ID) {
throw new IOException(String.format("Expected root tag to be a CompoundTag, was %s", type)); throw new IOException(String.format("Expected root tag to be a CompoundTag, was %s", type));
} }
input.skipBytes(input.readUnsignedShort()); // read empty name input.skipBytes(input.readUnsignedShort()); // read empty name
final CompoundTag compoundTag = new CompoundTag(""); final CompoundTag compoundTag = new CompoundTag();
compoundTag.read(input); compoundTag.read(input);
return compoundTag; return compoundTag;
} }
@ -175,7 +174,7 @@ public final class BinaryTagIO {
* @throws IOException if an exception was encountered while writing the compound tag * @throws IOException if an exception was encountered while writing the compound tag
*/ */
public static void writeDataOutput(final @NotNull CompoundTag tag, final @NotNull DataOutput output) throws IOException { public static void writeDataOutput(final @NotNull CompoundTag tag, final @NotNull DataOutput output) throws IOException {
output.writeByte(TagRegistry.getIdFor(CompoundTag.class)); output.writeByte(CompoundTag.ID);
output.writeUTF(""); // write empty name output.writeUTF(""); // write empty name
tag.write(output); tag.write(output);
} }

View File

@ -33,11 +33,11 @@ import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.LongArrayTag; import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
import com.github.steveice10.opennbt.tag.builtin.LongTag; import com.github.steveice10.opennbt.tag.builtin.LongTag;
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
import com.github.steveice10.opennbt.tag.builtin.ShortTag; import com.github.steveice10.opennbt.tag.builtin.ShortTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag; import com.github.steveice10.opennbt.tag.builtin.Tag;
import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.IntStream; import java.util.stream.IntStream;
@ -46,25 +46,15 @@ import java.util.stream.IntStream;
* See https://github.com/KyoriPowered/adventure. * See https://github.com/KyoriPowered/adventure.
*/ */
/* package */ final class TagStringReader { /* package */ final class TagStringReader {
private static final Field NAME_FIELD = getNameField();
private final CharBuffer buffer; private final CharBuffer buffer;
private static Field getNameField() {
try {
return Tag.class.getDeclaredField("name");
} catch (NoSuchFieldException e) {
e.printStackTrace();
throw new IllegalArgumentException(e);
}
}
public TagStringReader(final CharBuffer buffer) { public TagStringReader(final CharBuffer buffer) {
this.buffer = buffer; this.buffer = buffer;
} }
public CompoundTag compound() throws StringTagParseException { public CompoundTag compound() throws StringTagParseException {
this.buffer.expect(Tokens.COMPOUND_BEGIN); this.buffer.expect(Tokens.COMPOUND_BEGIN);
final CompoundTag compoundTag = new CompoundTag(""); final CompoundTag compoundTag = new CompoundTag();
if (this.buffer.peek() == Tokens.COMPOUND_END) { if (this.buffer.peek() == Tokens.COMPOUND_END) {
this.buffer.take(); this.buffer.take();
return compoundTag; return compoundTag;
@ -73,17 +63,7 @@ import java.util.stream.IntStream;
while (this.buffer.hasMore()) { while (this.buffer.hasMore()) {
final String key = this.key(); final String key = this.key();
final Tag tag = this.tag(); final Tag tag = this.tag();
// Doesn't get around this with the steveice lib :/ compoundTag.put(key, tag);
try {
if (!NAME_FIELD.isAccessible()) {
NAME_FIELD.setAccessible(true);
}
NAME_FIELD.set(tag, key);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException(e);
}
compoundTag.put(tag);
if (this.separatorOrCompleteWith(Tokens.COMPOUND_END)) { if (this.separatorOrCompleteWith(Tokens.COMPOUND_END)) {
return compoundTag; return compoundTag;
} }
@ -92,7 +72,7 @@ import java.util.stream.IntStream;
} }
public ListTag list() throws StringTagParseException { public ListTag list() throws StringTagParseException {
final ListTag listTag = new ListTag(""); final ListTag listTag = new ListTag();
this.buffer.expect(Tokens.ARRAY_BEGIN); this.buffer.expect(Tokens.ARRAY_BEGIN);
final boolean prefixedIndex = this.buffer.peek() == '0' && this.buffer.peek(1) == ':'; final boolean prefixedIndex = this.buffer.peek() == '0' && this.buffer.peek(1) == ':';
while (this.buffer.hasMore()) { while (this.buffer.hasMore()) {
@ -126,11 +106,11 @@ import java.util.stream.IntStream;
.expect(Tokens.ARRAY_SIGNATURE_SEPARATOR); .expect(Tokens.ARRAY_SIGNATURE_SEPARATOR);
if (elementType == Tokens.TYPE_BYTE) { if (elementType == Tokens.TYPE_BYTE) {
return new ByteArrayTag("", this.byteArray()); return new ByteArrayTag(this.byteArray());
} else if (elementType == Tokens.TYPE_INT) { } else if (elementType == Tokens.TYPE_INT) {
return new IntArrayTag("", this.intArray()); return new IntArrayTag(this.intArray());
} else if (elementType == Tokens.TYPE_LONG) { } else if (elementType == Tokens.TYPE_LONG) {
return new LongArrayTag("", this.longArray()); return new LongArrayTag(this.longArray());
} else { } else {
throw this.buffer.makeError("Type " + elementType + " is not a valid element type in an array!"); throw this.buffer.makeError("Type " + elementType + " is not a valid element type in an array!");
} }
@ -164,7 +144,7 @@ import java.util.stream.IntStream;
if (!(value instanceof IntTag)) { if (!(value instanceof IntTag)) {
throw this.buffer.makeError("All elements of an int array must be ints!"); throw this.buffer.makeError("All elements of an int array must be ints!");
} }
builder.add(((IntTag) value).getValue()); builder.add(((NumberTag) value).asInt());
if (this.separatorOrCompleteWith(Tokens.ARRAY_END)) { if (this.separatorOrCompleteWith(Tokens.ARRAY_END)) {
return builder.build().toArray(); return builder.build().toArray();
} }
@ -226,7 +206,7 @@ import java.util.stream.IntStream;
case Tokens.DOUBLE_QUOTE: case Tokens.DOUBLE_QUOTE:
// definitely a string tag // definitely a string tag
this.buffer.advance(); this.buffer.advance();
return new StringTag("", unescape(this.buffer.takeUntil(startToken).toString())); return new StringTag(unescape(this.buffer.takeUntil(startToken).toString()));
default: // scalar default: // scalar
return this.scalar(); return this.scalar();
} }
@ -251,19 +231,19 @@ import java.util.stream.IntStream;
switch (Character.toUpperCase(current)) { // try to read and return as a number switch (Character.toUpperCase(current)) { // try to read and return as a number
// case Tokens.TYPE_INTEGER: // handled below, ints are ~special~ // case Tokens.TYPE_INTEGER: // handled below, ints are ~special~
case Tokens.TYPE_BYTE: case Tokens.TYPE_BYTE:
result = new ByteTag("", Byte.parseByte(builder.toString())); result = new ByteTag(Byte.parseByte(builder.toString()));
break; break;
case Tokens.TYPE_SHORT: case Tokens.TYPE_SHORT:
result = new ShortTag("", (Short.parseShort(builder.toString()))); result = new ShortTag(Short.parseShort(builder.toString()));
break; break;
case Tokens.TYPE_LONG: case Tokens.TYPE_LONG:
result = new LongTag("", (Long.parseLong(builder.toString()))); result = new LongTag(Long.parseLong(builder.toString()));
break; break;
case Tokens.TYPE_FLOAT: case Tokens.TYPE_FLOAT:
result = new FloatTag("", (Float.parseFloat(builder.toString()))); result = new FloatTag(Float.parseFloat(builder.toString()));
break; break;
case Tokens.TYPE_DOUBLE: case Tokens.TYPE_DOUBLE:
result = new DoubleTag("", (Double.parseDouble(builder.toString()))); result = new DoubleTag(Double.parseDouble(builder.toString()));
break; break;
} }
} catch (final NumberFormatException ex) { } catch (final NumberFormatException ex) {
@ -288,12 +268,12 @@ import java.util.stream.IntStream;
final String built = builder.toString(); final String built = builder.toString();
if (possiblyNumeric) { if (possiblyNumeric) {
try { try {
return new IntTag("", Integer.parseInt(built)); return new IntTag(Integer.parseInt(built));
} catch (final NumberFormatException ex) { } catch (final NumberFormatException ex) {
// ignore // ignore
} }
} }
return new StringTag("", built); return new StringTag(built);
} }

View File

@ -39,6 +39,7 @@ import com.github.steveice10.opennbt.tag.builtin.Tag;
import java.io.IOException; import java.io.IOException;
import java.io.Writer; import java.io.Writer;
import java.util.Map;
/** /**
* See https://github.com/KyoriPowered/adventure. * See https://github.com/KyoriPowered/adventure.
@ -72,17 +73,17 @@ import java.io.Writer;
} else if (tag instanceof StringTag) { } else if (tag instanceof StringTag) {
return this.value(((StringTag) tag).getValue(), Tokens.EOF); return this.value(((StringTag) tag).getValue(), Tokens.EOF);
} else if (tag instanceof ByteTag) { } else if (tag instanceof ByteTag) {
return this.value(Byte.toString(((ByteTag) tag).getValue()), Tokens.TYPE_BYTE); return this.value(Byte.toString(((ByteTag) tag).asByte()), Tokens.TYPE_BYTE);
} else if (tag instanceof ShortTag) { } else if (tag instanceof ShortTag) {
return this.value(Short.toString(((ShortTag) tag).getValue()), Tokens.TYPE_SHORT); return this.value(Short.toString(((ShortTag) tag).asShort()), Tokens.TYPE_SHORT);
} else if (tag instanceof IntTag) { } else if (tag instanceof IntTag) {
return this.value(Integer.toString(((IntTag) tag).getValue()), Tokens.TYPE_INT); return this.value(Integer.toString(((IntTag) tag).asInt()), Tokens.TYPE_INT);
} else if (tag instanceof LongTag) { } else if (tag instanceof LongTag) {
return this.value(Long.toString(((LongTag) tag).getValue()), Tokens.TYPE_LONG); return this.value(Long.toString(((LongTag) tag).asLong()), Tokens.TYPE_LONG);
} else if (tag instanceof FloatTag) { } else if (tag instanceof FloatTag) {
return this.value(Float.toString(((FloatTag) tag).getValue()), Tokens.TYPE_FLOAT); return this.value(Float.toString(((FloatTag) tag).asFloat()), Tokens.TYPE_FLOAT);
} else if (tag instanceof DoubleTag) { } else if (tag instanceof DoubleTag) {
return this.value(Double.toString(((DoubleTag) tag).getValue()), Tokens.TYPE_DOUBLE); return this.value(Double.toString(((DoubleTag) tag).asDouble()), Tokens.TYPE_DOUBLE);
} else { } else {
throw new IOException("Unknown tag type: " + tag.getClass().getSimpleName()); throw new IOException("Unknown tag type: " + tag.getClass().getSimpleName());
// unknown! // unknown!
@ -91,9 +92,9 @@ import java.io.Writer;
private TagStringWriter writeCompound(final CompoundTag tag) throws IOException { private TagStringWriter writeCompound(final CompoundTag tag) throws IOException {
this.beginCompound(); this.beginCompound();
for (Tag t : tag) { for (Map.Entry<String, Tag> entry : tag.entrySet()) {
this.key(t.getName()); this.key(entry.getKey());
this.writeTag(t); this.writeTag(entry.getValue());
} }
this.endCompound(); this.endCompound();
return this; return this;

View File

@ -1,7 +1,6 @@
package us.myles.ViaVersion.api.type.types.minecraft; package us.myles.ViaVersion.api.type.types.minecraft;
import com.github.steveice10.opennbt.NBTIO; import com.github.steveice10.opennbt.NBTIO;
import com.github.steveice10.opennbt.tag.TagRegistry;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -10,17 +9,9 @@ import io.netty.buffer.ByteBufOutputStream;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import java.io.DataInput; import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput; import java.io.DataOutput;
import java.io.DataOutputStream;
public class NBTType extends Type<CompoundTag> { public class NBTType extends Type<CompoundTag> {
static {
// We don't need them
TagRegistry.unregister(60);
TagRegistry.unregister(61);
TagRegistry.unregister(65);
}
public NBTType() { public NBTType() {
super(CompoundTag.class); super(CompoundTag.class);
@ -36,7 +27,7 @@ public class NBTType extends Type<CompoundTag> {
return null; return null;
} else { } else {
buffer.readerIndex(readerIndex); buffer.readerIndex(readerIndex);
return (CompoundTag) NBTIO.readTag((DataInput) new ByteBufInputStream(buffer)); return NBTIO.readTag((DataInput) new ByteBufInputStream(buffer));
} }
} }

View File

@ -116,12 +116,12 @@ public class Protocol1_12To1_11_1 extends Protocol<ClientboundPackets1_9_3, Clie
// Is this a bed? // Is this a bed?
if (block == 26) { if (block == 26) {
// NBT -> { color:14, x:132, y:64, z:222, id:"minecraft:bed" } (Debug output) // NBT -> { color:14, x:132, y:64, z:222, id:"minecraft:bed" } (Debug output)
CompoundTag tag = new CompoundTag(""); CompoundTag tag = new CompoundTag();
tag.put(new IntTag("color", 14)); // Set color to red (Default in previous versions) tag.put("color", new IntTag(14)); // Set color to red (Default in previous versions)
tag.put(new IntTag("x", x + (chunk.getX() << 4))); tag.put("x", new IntTag(x + (chunk.getX() << 4)));
tag.put(new IntTag("y", y + (i << 4))); tag.put("y", new IntTag(y + (i << 4)));
tag.put(new IntTag("z", z + (chunk.getZ() << 4))); tag.put("z", new IntTag(z + (chunk.getZ() << 4)));
tag.put(new StringTag("id", "minecraft:bed")); tag.put("id", new StringTag("minecraft:bed"));
// Add a fake block entity // Add a fake block entity
chunk.getBlockEntities().add(tag); chunk.getBlockEntities().add(tag);

View File

@ -49,7 +49,7 @@ public class ComponentRewriter1_13 extends ComponentRewriter {
ShortTag damageTag = tag.get("Damage"); ShortTag damageTag = tag.get("Damage");
// Call item converter // Call item converter
short damage = damageTag != null ? damageTag.getValue() : 0; short damage = damageTag != null ? damageTag.asShort() : 0;
Item item = new Item(); Item item = new Item();
item.setData(damage); item.setData(damage);
item.setTag(itemTag); item.setTag(itemTag);
@ -57,10 +57,10 @@ public class ComponentRewriter1_13 extends ComponentRewriter {
// Serialize again // Serialize again
if (damage != item.getData()) { if (damage != item.getData()) {
tag.put(new ShortTag("Damage", item.getData())); tag.put("Damage", new ShortTag(item.getData()));
} }
if (itemTag != null) { if (itemTag != null) {
tag.put(itemTag); tag.put("tag", itemTag);
} }
JsonArray array = new JsonArray(); JsonArray array = new JsonArray();

View File

@ -4,6 +4,7 @@ import com.github.steveice10.opennbt.conversion.ConverterRegistry;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag; import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
import com.github.steveice10.opennbt.tag.builtin.ShortTag; import com.github.steveice10.opennbt.tag.builtin.ShortTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag; import com.github.steveice10.opennbt.tag.builtin.Tag;
@ -263,12 +264,12 @@ public class InventoryPackets {
// NBT Additions // NBT Additions
if (isDamageable(item.getIdentifier())) { if (isDamageable(item.getIdentifier())) {
if (tag == null) item.setTag(tag = new CompoundTag("tag")); if (tag == null) item.setTag(tag = new CompoundTag());
tag.put(new IntTag("Damage", item.getData())); tag.put("Damage", new IntTag(item.getData()));
} }
if (item.getIdentifier() == 358) { // map if (item.getIdentifier() == 358) { // map
if (tag == null) item.setTag(tag = new CompoundTag("tag")); if (tag == null) item.setTag(tag = new CompoundTag());
tag.put(new IntTag("map", item.getData())); tag.put("map", new IntTag(item.getData()));
} }
// NBT Changes // NBT Changes
@ -282,16 +283,16 @@ public class InventoryPackets {
IntTag base = blockEntityTag.get("Base"); IntTag base = blockEntityTag.get("Base");
// Set banner item id according to nbt // Set banner item id according to nbt
if (banner) { if (banner) {
rawId = 6800 + base.getValue(); rawId = 6800 + base.asInt();
} }
base.setValue(15 - base.getValue()); base.setValue(15 - base.asInt());
} }
if (blockEntityTag.get("Patterns") instanceof ListTag) { if (blockEntityTag.get("Patterns") instanceof ListTag) {
for (Tag pattern : (ListTag) blockEntityTag.get("Patterns")) { for (Tag pattern : (ListTag) blockEntityTag.get("Patterns")) {
if (pattern instanceof CompoundTag) { if (pattern instanceof CompoundTag) {
IntTag c = ((CompoundTag) pattern).get("Color"); IntTag c = ((CompoundTag) pattern).get("Color");
c.setValue(15 - c.getValue()); // Invert color id c.setValue(15 - c.asInt()); // Invert color id
} }
} }
} }
@ -302,55 +303,53 @@ public class InventoryPackets {
CompoundTag display = tag.get("display"); CompoundTag display = tag.get("display");
if (display.get("Name") instanceof StringTag) { if (display.get("Name") instanceof StringTag) {
StringTag name = display.get("Name"); StringTag name = display.get("Name");
display.put(new StringTag(NBT_TAG_NAME + "|Name", name.getValue())); display.put(NBT_TAG_NAME + "|Name", new StringTag(name.getValue()));
name.setValue(ChatRewriter.legacyTextToJsonString(name.getValue(), true)); name.setValue(ChatRewriter.legacyTextToJsonString(name.getValue(), true));
} }
} }
// ench is now Enchantments and now uses identifiers // ench is now Enchantments and now uses identifiers
if (tag.get("ench") instanceof ListTag) { if (tag.get("ench") instanceof ListTag) {
ListTag ench = tag.get("ench"); ListTag ench = tag.get("ench");
ListTag enchantments = new ListTag("Enchantments", CompoundTag.class); ListTag enchantments = new ListTag(CompoundTag.class);
for (Tag enchEntry : ench) { for (Tag enchEntry : ench) {
if (enchEntry instanceof CompoundTag) { if (enchEntry instanceof CompoundTag) {
CompoundTag enchantmentEntry = new CompoundTag(""); CompoundTag enchantmentEntry = new CompoundTag();
short oldId = ((Number) ((CompoundTag) enchEntry).get("id").getValue()).shortValue(); short oldId = ((NumberTag) ((CompoundTag) enchEntry).get("id")).asShort();
String newId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().get(oldId); String newId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().get(oldId);
if (newId == null) { if (newId == null) {
newId = "viaversion:legacy/" + oldId; newId = "viaversion:legacy/" + oldId;
} }
enchantmentEntry.put(new StringTag("id", newId)); enchantmentEntry.put("id", new StringTag(newId));
enchantmentEntry.put(new ShortTag("lvl", ((Number) ((CompoundTag) enchEntry).get("lvl").getValue()).shortValue())); enchantmentEntry.put("lvl", new ShortTag(((NumberTag) ((CompoundTag) enchEntry).get("lvl")).asShort()));
enchantments.add(enchantmentEntry); enchantments.add(enchantmentEntry);
} }
} }
tag.remove("ench"); tag.remove("ench");
tag.put(enchantments); tag.put("Enchantments", enchantments);
} }
if (tag.get("StoredEnchantments") instanceof ListTag) { if (tag.get("StoredEnchantments") instanceof ListTag) {
ListTag storedEnch = tag.get("StoredEnchantments"); ListTag storedEnch = tag.get("StoredEnchantments");
ListTag newStoredEnch = new ListTag("StoredEnchantments", CompoundTag.class); ListTag newStoredEnch = new ListTag(CompoundTag.class);
for (Tag enchEntry : storedEnch) { for (Tag enchEntry : storedEnch) {
if (enchEntry instanceof CompoundTag) { if (enchEntry instanceof CompoundTag) {
CompoundTag enchantmentEntry = new CompoundTag(""); CompoundTag enchantmentEntry = new CompoundTag();
short oldId = ((Number) ((CompoundTag) enchEntry).get("id").getValue()).shortValue(); short oldId = ((NumberTag) ((CompoundTag) enchEntry).get("id")).asShort();
String newId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().get(oldId); String newId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().get(oldId);
if (newId == null) { if (newId == null) {
newId = "viaversion:legacy/" + oldId; newId = "viaversion:legacy/" + oldId;
} }
enchantmentEntry.put(new StringTag("id", enchantmentEntry.put("id", new StringTag(newId));
newId enchantmentEntry.put("lvl", new ShortTag(((NumberTag) ((CompoundTag) enchEntry).get("lvl")).asShort()));
));
enchantmentEntry.put(new ShortTag("lvl", ((Number) ((CompoundTag) enchEntry).get("lvl").getValue()).shortValue()));
newStoredEnch.add(enchantmentEntry); newStoredEnch.add(enchantmentEntry);
} }
} }
tag.remove("StoredEnchantments"); tag.remove("StoredEnchantments");
tag.put(newStoredEnch); tag.put("StoredEnchantments", newStoredEnch);
} }
if (tag.get("CanPlaceOn") instanceof ListTag) { if (tag.get("CanPlaceOn") instanceof ListTag) {
ListTag old = tag.get("CanPlaceOn"); ListTag old = tag.get("CanPlaceOn");
ListTag newCanPlaceOn = new ListTag("CanPlaceOn", StringTag.class); ListTag newCanPlaceOn = new ListTag(StringTag.class);
tag.put(ConverterRegistry.convertToTag(NBT_TAG_NAME + "|CanPlaceOn", ConverterRegistry.convertToValue(old))); // There will be data losing tag.put(NBT_TAG_NAME + "|CanPlaceOn", ConverterRegistry.convertToTag(ConverterRegistry.convertToValue(old))); // There will be data losing
for (Tag oldTag : old) { for (Tag oldTag : old) {
Object value = oldTag.getValue(); Object value = oldTag.getValue();
String oldId = value.toString().replace("minecraft:", ""); String oldId = value.toString().replace("minecraft:", "");
@ -361,18 +360,18 @@ public class InventoryPackets {
String[] newValues = BlockIdData.blockIdMapping.get(oldId.toLowerCase(Locale.ROOT)); String[] newValues = BlockIdData.blockIdMapping.get(oldId.toLowerCase(Locale.ROOT));
if (newValues != null) { if (newValues != null) {
for (String newValue : newValues) { for (String newValue : newValues) {
newCanPlaceOn.add(new StringTag("", newValue)); newCanPlaceOn.add(new StringTag(newValue));
} }
} else { } else {
newCanPlaceOn.add(new StringTag("", oldId.toLowerCase(Locale.ROOT))); newCanPlaceOn.add(new StringTag(oldId.toLowerCase(Locale.ROOT)));
} }
} }
tag.put(newCanPlaceOn); tag.put("CanPlaceOn", newCanPlaceOn);
} }
if (tag.get("CanDestroy") instanceof ListTag) { if (tag.get("CanDestroy") instanceof ListTag) {
ListTag old = tag.get("CanDestroy"); ListTag old = tag.get("CanDestroy");
ListTag newCanDestroy = new ListTag("CanDestroy", StringTag.class); ListTag newCanDestroy = new ListTag(StringTag.class);
tag.put(ConverterRegistry.convertToTag(NBT_TAG_NAME + "|CanDestroy", ConverterRegistry.convertToValue(old))); // There will be data losing tag.put(NBT_TAG_NAME + "|CanDestroy", ConverterRegistry.convertToTag(ConverterRegistry.convertToValue(old))); // There will be data losing
for (Tag oldTag : old) { for (Tag oldTag : old) {
Object value = oldTag.getValue(); Object value = oldTag.getValue();
String oldId = value.toString().replace("minecraft:", ""); String oldId = value.toString().replace("minecraft:", "");
@ -383,13 +382,13 @@ public class InventoryPackets {
String[] newValues = BlockIdData.blockIdMapping.get(oldId.toLowerCase(Locale.ROOT)); String[] newValues = BlockIdData.blockIdMapping.get(oldId.toLowerCase(Locale.ROOT));
if (newValues != null) { if (newValues != null) {
for (String newValue : newValues) { for (String newValue : newValues) {
newCanDestroy.add(new StringTag("", newValue)); newCanDestroy.add(new StringTag(newValue));
} }
} else { } else {
newCanDestroy.add(new StringTag("", oldId.toLowerCase(Locale.ROOT))); newCanDestroy.add(new StringTag(oldId.toLowerCase(Locale.ROOT)));
} }
} }
tag.put(newCanDestroy); tag.put("CanDestroy", newCanDestroy);
} }
// Handle SpawnEggs // Handle SpawnEggs
if (item.getIdentifier() == 383) { if (item.getIdentifier() == 383) {
@ -421,8 +420,8 @@ public class InventoryPackets {
if (!Protocol1_13To1_12_2.MAPPINGS.getItemMappings().containsKey(rawId)) { if (!Protocol1_13To1_12_2.MAPPINGS.getItemMappings().containsKey(rawId)) {
if (!isDamageable(item.getIdentifier()) && item.getIdentifier() != 358) { // Map if (!isDamageable(item.getIdentifier()) && item.getIdentifier() != 358) { // Map
if (tag == null) item.setTag(tag = new CompoundTag("tag")); if (tag == null) item.setTag(tag = new CompoundTag());
tag.put(new IntTag(NBT_TAG_NAME, originalId)); // Data will be lost, saving original id tag.put(NBT_TAG_NAME, new IntTag(originalId)); // Data will be lost, saving original id
} }
if (item.getIdentifier() == 31 && item.getData() == 0) { // Shrub was removed if (item.getIdentifier() == 31 && item.getData() == 0) { // Shrub was removed
rawId = 32 << 4; // Dead Bush rawId = 32 << 4; // Dead Bush
@ -495,11 +494,11 @@ public class InventoryPackets {
if (eggEntityId.isPresent()) { if (eggEntityId.isPresent()) {
rawId = 383 << 16; rawId = 383 << 16;
if (tag == null) if (tag == null)
item.setTag(tag = new CompoundTag("tag")); item.setTag(tag = new CompoundTag());
if (!tag.contains("EntityTag")) { if (!tag.contains("EntityTag")) {
CompoundTag entityTag = new CompoundTag("EntityTag"); CompoundTag entityTag = new CompoundTag();
entityTag.put(new StringTag("id", eggEntityId.get())); entityTag.put("id", new StringTag(eggEntityId.get()));
tag.put(entityTag); tag.put("EntityTag", entityTag);
} }
} else { } else {
rawId = (oldId >> 4) << 16 | oldId & 0xF; rawId = (oldId >> 4) << 16 | oldId & 0xF;
@ -542,13 +541,13 @@ public class InventoryPackets {
CompoundTag blockEntityTag = tag.get("BlockEntityTag"); CompoundTag blockEntityTag = tag.get("BlockEntityTag");
if (blockEntityTag.get("Base") instanceof IntTag) { if (blockEntityTag.get("Base") instanceof IntTag) {
IntTag base = blockEntityTag.get("Base"); IntTag base = blockEntityTag.get("Base");
base.setValue(15 - base.getValue()); // invert color id base.setValue(15 - base.asInt()); // invert color id
} }
if (blockEntityTag.get("Patterns") instanceof ListTag) { if (blockEntityTag.get("Patterns") instanceof ListTag) {
for (Tag pattern : (ListTag) blockEntityTag.get("Patterns")) { for (Tag pattern : (ListTag) blockEntityTag.get("Patterns")) {
if (pattern instanceof CompoundTag) { if (pattern instanceof CompoundTag) {
IntTag c = ((CompoundTag) pattern).get("Color"); IntTag c = ((CompoundTag) pattern).get("Color");
c.setValue(15 - c.getValue()); // Invert color id c.setValue(15 - c.asInt()); // Invert color id
} }
} }
} }
@ -567,55 +566,52 @@ public class InventoryPackets {
// ench is now Enchantments and now uses identifiers // ench is now Enchantments and now uses identifiers
if (tag.get("Enchantments") instanceof ListTag) { if (tag.get("Enchantments") instanceof ListTag) {
ListTag enchantments = tag.get("Enchantments"); ListTag enchantments = tag.get("Enchantments");
ListTag ench = new ListTag("ench", CompoundTag.class); ListTag ench = new ListTag(CompoundTag.class);
for (Tag enchantmentEntry : enchantments) { for (Tag enchantmentEntry : enchantments) {
if (enchantmentEntry instanceof CompoundTag) { if (enchantmentEntry instanceof CompoundTag) {
CompoundTag enchEntry = new CompoundTag(""); CompoundTag enchEntry = new CompoundTag();
String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue(); String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue();
Short oldId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().inverse().get(newId); Short oldId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().inverse().get(newId);
if (oldId == null && newId.startsWith("viaversion:legacy/")) { if (oldId == null && newId.startsWith("viaversion:legacy/")) {
oldId = Short.valueOf(newId.substring(18)); oldId = Short.valueOf(newId.substring(18));
} }
if (oldId != null) { if (oldId != null) {
enchEntry.put(new ShortTag("id", oldId)); enchEntry.put("id", new ShortTag(oldId));
enchEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue())); enchEntry.put("lvl", new ShortTag((Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue()));
ench.add(enchEntry); ench.add(enchEntry);
} }
} }
} }
tag.remove("Enchantments"); tag.remove("Enchantments");
tag.put(ench); tag.put("ench", ench);
} }
if (tag.get("StoredEnchantments") instanceof ListTag) { if (tag.get("StoredEnchantments") instanceof ListTag) {
ListTag storedEnch = tag.get("StoredEnchantments"); ListTag storedEnch = tag.get("StoredEnchantments");
ListTag newStoredEnch = new ListTag("StoredEnchantments", CompoundTag.class); ListTag newStoredEnch = new ListTag(CompoundTag.class);
for (Tag enchantmentEntry : storedEnch) { for (Tag enchantmentEntry : storedEnch) {
if (enchantmentEntry instanceof CompoundTag) { if (enchantmentEntry instanceof CompoundTag) {
CompoundTag enchEntry = new CompoundTag(""); CompoundTag enchEntry = new CompoundTag();
String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue(); String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue();
Short oldId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().inverse().get(newId); Short oldId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().inverse().get(newId);
if (oldId == null && newId.startsWith("viaversion:legacy/")) { if (oldId == null && newId.startsWith("viaversion:legacy/")) {
oldId = Short.valueOf(newId.substring(18)); oldId = Short.valueOf(newId.substring(18));
} }
if (oldId != null) { if (oldId != null) {
enchEntry.put(new ShortTag("id", oldId)); enchEntry.put("id", new ShortTag(oldId));
enchEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue())); enchEntry.put("lvl", new ShortTag((Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue()));
newStoredEnch.add(enchEntry); newStoredEnch.add(enchEntry);
} }
} }
} }
tag.remove("StoredEnchantments"); tag.remove("StoredEnchantments");
tag.put(newStoredEnch); tag.put("StoredEnchantments", newStoredEnch);
} }
if (tag.get(NBT_TAG_NAME + "|CanPlaceOn") instanceof ListTag) { if (tag.get(NBT_TAG_NAME + "|CanPlaceOn") instanceof ListTag) {
tag.put(ConverterRegistry.convertToTag( tag.put("CanPlaceOn", ConverterRegistry.convertToTag(ConverterRegistry.convertToValue(tag.get(NBT_TAG_NAME + "|CanPlaceOn"))));
"CanPlaceOn",
ConverterRegistry.convertToValue(tag.get(NBT_TAG_NAME + "|CanPlaceOn"))
));
tag.remove(NBT_TAG_NAME + "|CanPlaceOn"); tag.remove(NBT_TAG_NAME + "|CanPlaceOn");
} else if (tag.get("CanPlaceOn") instanceof ListTag) { } else if (tag.get("CanPlaceOn") instanceof ListTag) {
ListTag old = tag.get("CanPlaceOn"); ListTag old = tag.get("CanPlaceOn");
ListTag newCanPlaceOn = new ListTag("CanPlaceOn", StringTag.class); ListTag newCanPlaceOn = new ListTag(StringTag.class);
for (Tag oldTag : old) { for (Tag oldTag : old) {
Object value = oldTag.getValue(); Object value = oldTag.getValue();
String[] newValues = BlockIdData.fallbackReverseMapping.get(value instanceof String String[] newValues = BlockIdData.fallbackReverseMapping.get(value instanceof String
@ -623,23 +619,22 @@ public class InventoryPackets {
: null); : null);
if (newValues != null) { if (newValues != null) {
for (String newValue : newValues) { for (String newValue : newValues) {
newCanPlaceOn.add(new StringTag("", newValue)); newCanPlaceOn.add(new StringTag(newValue));
} }
} else { } else {
newCanPlaceOn.add(oldTag); newCanPlaceOn.add(oldTag);
} }
} }
tag.put(newCanPlaceOn); tag.put("CanPlaceOn", newCanPlaceOn);
} }
if (tag.get(NBT_TAG_NAME + "|CanDestroy") instanceof ListTag) { if (tag.get(NBT_TAG_NAME + "|CanDestroy") instanceof ListTag) {
tag.put(ConverterRegistry.convertToTag( tag.put("CanDestroy", ConverterRegistry.convertToTag(
"CanDestroy",
ConverterRegistry.convertToValue(tag.get(NBT_TAG_NAME + "|CanDestroy")) ConverterRegistry.convertToValue(tag.get(NBT_TAG_NAME + "|CanDestroy"))
)); ));
tag.remove(NBT_TAG_NAME + "|CanDestroy"); tag.remove(NBT_TAG_NAME + "|CanDestroy");
} else if (tag.get("CanDestroy") instanceof ListTag) { } else if (tag.get("CanDestroy") instanceof ListTag) {
ListTag old = tag.get("CanDestroy"); ListTag old = tag.get("CanDestroy");
ListTag newCanDestroy = new ListTag("CanDestroy", StringTag.class); ListTag newCanDestroy = new ListTag(StringTag.class);
for (Tag oldTag : old) { for (Tag oldTag : old) {
Object value = oldTag.getValue(); Object value = oldTag.getValue();
String[] newValues = BlockIdData.fallbackReverseMapping.get(value instanceof String String[] newValues = BlockIdData.fallbackReverseMapping.get(value instanceof String
@ -647,13 +642,13 @@ public class InventoryPackets {
: null); : null);
if (newValues != null) { if (newValues != null) {
for (String newValue : newValues) { for (String newValue : newValues) {
newCanDestroy.add(new StringTag("", newValue)); newCanDestroy.add(new StringTag(newValue));
} }
} else { } else {
newCanDestroy.add(oldTag); newCanDestroy.add(oldTag);
} }
} }
tag.put(newCanDestroy); tag.put("CanDestroy", newCanDestroy);
} }
} }
} }

View File

@ -30,7 +30,7 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler {
Tag base = tag.get("Base"); Tag base = tag.get("Base");
int color = 0; int color = 0;
if (base != null) { if (base != null) {
color = ((Number) tag.get("Base").getValue()).intValue(); color = ((NumberTag) tag.get("Base")).asInt();
} }
// Standing banner // Standing banner
if (blockId >= BANNER_START && blockId <= BANNER_STOP) { if (blockId >= BANNER_START && blockId <= BANNER_STOP) {

View File

@ -1,6 +1,7 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities; package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; 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.github.steveice10.opennbt.tag.builtin.Tag;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
@ -25,13 +26,13 @@ public class BedHandler implements BlockEntityProvider.BlockEntityHandler {
Tag color = tag.get("color"); Tag color = tag.get("color");
if (color != null) { if (color != null) {
blockId += (((Number) color.getValue()).intValue() * 16); blockId += (((NumberTag) color).asInt() * 16);
} }
return blockId; return blockId;
} }
private long getLong(Tag tag) { private long getLong(NumberTag tag) {
return ((Integer) tag.getValue()).longValue(); return tag.asLong();
} }
} }

View File

@ -1,6 +1,7 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities; package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; 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.github.steveice10.opennbt.tag.builtin.Tag;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
@ -26,10 +27,10 @@ public class SkullHandler implements BlockEntityProvider.BlockEntityHandler {
if (id >= SKULL_WALL_START && id <= SKULL_END) { if (id >= SKULL_WALL_START && id <= SKULL_END) {
Tag skullType = tag.get("SkullType"); Tag skullType = tag.get("SkullType");
if (skullType != null) { if (skullType != null) {
id += ((Number) tag.get("SkullType").getValue()).intValue() * 20; id += ((NumberTag) tag.get("SkullType")).asInt() * 20;
} }
if (tag.contains("Rot")) { if (tag.contains("Rot")) {
id += ((Number) tag.get("Rot").getValue()).intValue(); id += ((NumberTag) tag.get("Rot")).asInt();
} }
} else { } else {
Via.getPlatform().getLogger().warning("Why does this block have the skull block entity? " + tag); Via.getPlatform().getLogger().warning("Why does this block have the skull block entity? " + tag);

View File

@ -217,8 +217,8 @@ public class InventoryPackets {
resyncPacket.write(Type.BYTE, (byte) 2); // 2 - Button - End left click resyncPacket.write(Type.BYTE, (byte) 2); // 2 - Button - End left click
resyncPacket.write(Type.SHORT, ((short) ThreadLocalRandom.current().nextInt())); // 3 - Action number resyncPacket.write(Type.SHORT, ((short) ThreadLocalRandom.current().nextInt())); // 3 - Action number
resyncPacket.write(Type.VAR_INT, 5); // 4 - Mode - Drag resyncPacket.write(Type.VAR_INT, 5); // 4 - Mode - Drag
CompoundTag tag = new CompoundTag(""); CompoundTag tag = new CompoundTag();
tag.put(new DoubleTag("force_resync", Double.NaN)); // Tags with NaN are not equal tag.put("force_resync", new DoubleTag(Double.NaN)); // Tags with NaN are not equal
resyncPacket.write(Type.FLAT_VAR_INT_ITEM, new Item(1, (byte) 1, (short) 0, tag)); // 5 - Clicked Item resyncPacket.write(Type.FLAT_VAR_INT_ITEM, new Item(1, (byte) 1, (short) 0, tag)); // 5 - Clicked Item
resyncPacket.sendToServer(Protocol1_14To1_13_2.class, true, false); resyncPacket.sendToServer(Protocol1_14To1_13_2.class, true, false);
} }
@ -244,7 +244,7 @@ public class InventoryPackets {
Tag loreTag = display.get("Lore"); Tag loreTag = display.get("Lore");
if (loreTag instanceof ListTag) { if (loreTag instanceof ListTag) {
ListTag lore = (ListTag) loreTag; ListTag lore = (ListTag) loreTag;
display.put(new ListTag(NBT_TAG_NAME + "|Lore", lore.clone().getValue())); // Save old lore display.put(NBT_TAG_NAME + "|Lore", new ListTag(lore.clone().getValue())); // Save old lore
for (Tag loreEntry : lore) { for (Tag loreEntry : lore) {
if (loreEntry instanceof StringTag) { if (loreEntry instanceof StringTag) {
String jsonText = ChatRewriter.legacyTextToJsonString(((StringTag) loreEntry).getValue(), true); String jsonText = ChatRewriter.legacyTextToJsonString(((StringTag) loreEntry).getValue(), true);
@ -270,7 +270,7 @@ public class InventoryPackets {
ListTag lore = (ListTag) loreTag; ListTag lore = (ListTag) loreTag;
ListTag savedLore = display.remove(NBT_TAG_NAME + "|Lore"); ListTag savedLore = display.remove(NBT_TAG_NAME + "|Lore");
if (savedLore != null) { if (savedLore != null) {
display.put(new ListTag("Lore", savedLore.getValue())); display.put("Lore", new ListTag(savedLore.getValue()));
} else { } else {
for (Tag loreEntry : lore) { for (Tag loreEntry : lore) {
if (loreEntry instanceof StringTag) { if (loreEntry instanceof StringTag) {

View File

@ -176,9 +176,9 @@ public class WorldPackets {
section.setNonAirBlocksCount(nonAirBlockCount); section.setNonAirBlocksCount(nonAirBlockCount);
} }
CompoundTag heightMap = new CompoundTag(""); CompoundTag heightMap = new CompoundTag();
heightMap.put(new LongArrayTag("MOTION_BLOCKING", encodeHeightMap(motionBlocking))); heightMap.put("MOTION_BLOCKING", new LongArrayTag(encodeHeightMap(motionBlocking)));
heightMap.put(new LongArrayTag("WORLD_SURFACE", encodeHeightMap(worldSurface))); heightMap.put("WORLD_SURFACE", new LongArrayTag(encodeHeightMap(worldSurface)));
chunk.setHeightMap(heightMap); chunk.setHeightMap(heightMap);
PacketWrapper lightPacket = wrapper.create(0x24); PacketWrapper lightPacket = wrapper.create(0x24);

View File

@ -35,7 +35,7 @@ public class MappingData extends us.myles.ViaVersion.api.data.MappingData {
for (Tag dimension : dimensions) { for (Tag dimension : dimensions) {
CompoundTag dimensionCompound = (CompoundTag) dimension; CompoundTag dimensionCompound = (CompoundTag) dimension;
// Copy with an empty name // Copy with an empty name
CompoundTag dimensionData = new CompoundTag("", ((CompoundTag) dimensionCompound.get("element")).getValue()); CompoundTag dimensionData = new CompoundTag(((CompoundTag) dimensionCompound.get("element")).getValue());
dimensionDataMap.put(((StringTag) dimensionCompound.get("name")).getValue(), dimensionData); dimensionDataMap.put(((StringTag) dimensionCompound.get("name")).getValue(), dimensionData);
} }
} }

View File

@ -46,83 +46,83 @@ public class EntityPackets {
wrapper.write(Type.STRING, dimensionName); // dimension wrapper.write(Type.STRING, dimensionName); // dimension
wrapper.write(Type.STRING, dimensionName); // world wrapper.write(Type.STRING, dimensionName); // world
}; };
public static final CompoundTag DIMENSIONS_TAG = new CompoundTag(""); public static final CompoundTag DIMENSIONS_TAG = new CompoundTag();
private static final String[] WORLD_NAMES = {"minecraft:overworld", "minecraft:the_nether", "minecraft:the_end"}; private static final String[] WORLD_NAMES = {"minecraft:overworld", "minecraft:the_nether", "minecraft:the_end"};
static { static {
ListTag list = new ListTag("dimension", CompoundTag.class); ListTag list = new ListTag(CompoundTag.class);
list.add(createOverworldEntry()); list.add(createOverworldEntry());
list.add(createOverworldCavesEntry()); list.add(createOverworldCavesEntry());
list.add(createNetherEntry()); list.add(createNetherEntry());
list.add(createEndEntry()); list.add(createEndEntry());
DIMENSIONS_TAG.put(list); DIMENSIONS_TAG.put("dimension", list);
} }
private static CompoundTag createOverworldEntry() { private static CompoundTag createOverworldEntry() {
CompoundTag tag = new CompoundTag(""); CompoundTag tag = new CompoundTag();
tag.put(new StringTag("name", "minecraft:overworld")); tag.put("name", new StringTag("minecraft:overworld"));
tag.put(new ByteTag("has_ceiling", (byte) 0)); tag.put("has_ceiling", new ByteTag((byte) 0));
addSharedOverwaldEntries(tag); addSharedOverwaldEntries(tag);
return tag; return tag;
} }
private static CompoundTag createOverworldCavesEntry() { private static CompoundTag createOverworldCavesEntry() {
CompoundTag tag = new CompoundTag(""); CompoundTag tag = new CompoundTag();
tag.put(new StringTag("name", "minecraft:overworld_caves")); tag.put("name", new StringTag("minecraft:overworld_caves"));
tag.put(new ByteTag("has_ceiling", (byte) 1)); tag.put("has_ceiling", new ByteTag((byte) 1));
addSharedOverwaldEntries(tag); addSharedOverwaldEntries(tag);
return tag; return tag;
} }
private static void addSharedOverwaldEntries(CompoundTag tag) { private static void addSharedOverwaldEntries(CompoundTag tag) {
tag.put(new ByteTag("piglin_safe", (byte) 0)); tag.put("piglin_safe", new ByteTag((byte) 0));
tag.put(new ByteTag("natural", (byte) 1)); tag.put("natural", new ByteTag((byte) 1));
tag.put(new FloatTag("ambient_light", 0)); tag.put("ambient_light", new FloatTag(0));
tag.put(new StringTag("infiniburn", "minecraft:infiniburn_overworld")); tag.put("infiniburn", new StringTag("minecraft:infiniburn_overworld"));
tag.put(new ByteTag("respawn_anchor_works", (byte) 0)); tag.put("respawn_anchor_works", new ByteTag((byte) 0));
tag.put(new ByteTag("has_skylight", (byte) 1)); tag.put("has_skylight", new ByteTag((byte) 1));
tag.put(new ByteTag("bed_works", (byte) 1)); tag.put("bed_works", new ByteTag((byte) 1));
tag.put(new ByteTag("has_raids", (byte) 1)); tag.put("has_raids", new ByteTag((byte) 1));
tag.put(new IntTag("logical_height", 256)); tag.put("logical_height", new IntTag(256));
tag.put(new ByteTag("shrunk", (byte) 0)); tag.put("shrunk", new ByteTag((byte) 0));
tag.put(new ByteTag("ultrawarm", (byte) 0)); tag.put("ultrawarm", new ByteTag((byte) 0));
} }
private static CompoundTag createNetherEntry() { private static CompoundTag createNetherEntry() {
CompoundTag tag = new CompoundTag(""); CompoundTag tag = new CompoundTag();
tag.put(new ByteTag("piglin_safe", (byte) 1)); tag.put("piglin_safe", new ByteTag((byte) 1));
tag.put(new ByteTag("natural", (byte) 0)); tag.put("natural", new ByteTag((byte) 0));
tag.put(new FloatTag("ambient_light", 0.1F)); tag.put("ambient_light",new FloatTag( 0.1F));
tag.put(new StringTag("infiniburn", "minecraft:infiniburn_nether")); tag.put("infiniburn", new StringTag("minecraft:infiniburn_nether"));
tag.put(new ByteTag("respawn_anchor_works", (byte) 1)); tag.put("respawn_anchor_works", new ByteTag((byte) 1));
tag.put(new ByteTag("has_skylight", (byte) 0)); tag.put("has_skylight", new ByteTag((byte) 0));
tag.put(new ByteTag("bed_works", (byte) 0)); tag.put("bed_works", new ByteTag((byte) 0));
tag.put(new LongTag("fixed_time", 18000)); tag.put("fixed_time", new LongTag(18000));
tag.put(new ByteTag("has_raids", (byte) 0)); tag.put("has_raids", new ByteTag((byte) 0));
tag.put(new StringTag("name", "minecraft:the_nether")); tag.put("name", new StringTag("minecraft:the_nether"));
tag.put(new IntTag("logical_height", 128)); tag.put("logical_height", new IntTag(128));
tag.put(new ByteTag("shrunk", (byte) 1)); tag.put("shrunk", new ByteTag((byte) 1));
tag.put(new ByteTag("ultrawarm", (byte) 1)); tag.put("ultrawarm", new ByteTag((byte) 1));
tag.put(new ByteTag("has_ceiling", (byte) 1)); tag.put("has_ceiling", new ByteTag((byte) 1));
return tag; return tag;
} }
private static CompoundTag createEndEntry() { private static CompoundTag createEndEntry() {
CompoundTag tag = new CompoundTag(""); CompoundTag tag = new CompoundTag();
tag.put(new ByteTag("piglin_safe", (byte) 0)); tag.put("piglin_safe", new ByteTag((byte) 0));
tag.put(new ByteTag("natural", (byte) 0)); tag.put("natural", new ByteTag((byte) 0));
tag.put(new FloatTag("ambient_light", 0)); tag.put("ambient_light", new FloatTag(0));
tag.put(new StringTag("infiniburn", "minecraft:infiniburn_end")); tag.put("infiniburn", new StringTag("minecraft:infiniburn_end"));
tag.put(new ByteTag("respawn_anchor_works", (byte) 0)); tag.put("respawn_anchor_works", new ByteTag((byte) 0));
tag.put(new ByteTag("has_skylight", (byte) 0)); tag.put("has_skylight", new ByteTag((byte) 0));
tag.put(new ByteTag("bed_works", (byte) 0)); tag.put("bed_works", new ByteTag((byte) 0));
tag.put(new LongTag("fixed_time", 6000)); tag.put("fixed_time", new LongTag(6000));
tag.put(new ByteTag("has_raids", (byte) 1)); tag.put("has_raids", new ByteTag((byte) 1));
tag.put(new StringTag("name", "minecraft:the_end")); tag.put("name", new StringTag("minecraft:the_end"));
tag.put(new IntTag("logical_height", 256)); tag.put("logical_height", new IntTag(256));
tag.put(new ByteTag("shrunk", (byte) 0)); tag.put("shrunk", new ByteTag((byte) 0));
tag.put(new ByteTag("ultrawarm", (byte) 0)); tag.put("ultrawarm", new ByteTag((byte) 0));
tag.put(new ByteTag("has_ceiling", (byte) 0)); tag.put("has_ceiling", new ByteTag((byte) 0));
return tag; return tag;
} }

View File

@ -4,6 +4,7 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag; import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.LongTag; 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.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag; import com.github.steveice10.opennbt.tag.builtin.Tag;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
@ -131,7 +132,7 @@ public class InventoryPackets {
Tag idTag = ownerCompundTag.get("Id"); Tag idTag = ownerCompundTag.get("Id");
if (idTag instanceof StringTag) { if (idTag instanceof StringTag) {
UUID id = UUID.fromString((String) idTag.getValue()); UUID id = UUID.fromString((String) idTag.getValue());
ownerCompundTag.put(new IntArrayTag("Id", UUIDIntArrayType.uuidToIntArray(id))); ownerCompundTag.put("Id", new IntArrayTag(UUIDIntArrayType.uuidToIntArray(id)));
} }
} }
} }
@ -153,7 +154,7 @@ public class InventoryPackets {
Tag idTag = ownerCompundTag.get("Id"); Tag idTag = ownerCompundTag.get("Id");
if (idTag instanceof IntArrayTag) { if (idTag instanceof IntArrayTag) {
UUID id = UUIDIntArrayType.uuidFromIntArray((int[]) idTag.getValue()); UUID id = UUIDIntArrayType.uuidFromIntArray((int[]) idTag.getValue());
ownerCompundTag.put(new StringTag("Id", id.toString())); ownerCompundTag.put("Id", new StringTag(id.toString()));
} }
} }
} }
@ -174,8 +175,8 @@ public class InventoryPackets {
Tag leastTag = attribute.get("UUIDLeast"); Tag leastTag = attribute.get("UUIDLeast");
if (leastTag != null) { if (leastTag != null) {
Tag mostTag = attribute.get("UUIDMost"); Tag mostTag = attribute.get("UUIDMost");
int[] uuidIntArray = UUIDIntArrayType.bitsToIntArray(((Number) leastTag.getValue()).longValue(), ((Number) mostTag.getValue()).longValue()); int[] uuidIntArray = UUIDIntArrayType.bitsToIntArray(((NumberTag) leastTag).asLong(), ((NumberTag) mostTag).asLong());
attribute.put(new IntArrayTag("UUID", uuidIntArray)); attribute.put("UUID", new IntArrayTag(uuidIntArray));
} }
} }
} }
@ -193,8 +194,8 @@ public class InventoryPackets {
IntArrayTag uuidTag = attribute.get("UUID"); IntArrayTag uuidTag = attribute.get("UUID");
if (uuidTag != null) { if (uuidTag != null) {
UUID uuid = UUIDIntArrayType.uuidFromIntArray(uuidTag.getValue()); UUID uuid = UUIDIntArrayType.uuidFromIntArray(uuidTag.getValue());
attribute.put(new LongTag("UUIDLeast", uuid.getLeastSignificantBits())); attribute.put("UUIDLeast", new LongTag(uuid.getLeastSignificantBits()));
attribute.put(new LongTag("UUIDMost", uuid.getMostSignificantBits())); attribute.put("UUIDMost", new LongTag(uuid.getMostSignificantBits()));
} }
} }
} }

View File

@ -18,6 +18,7 @@ import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type;
import us.myles.ViaVersion.util.CompactArrayUtil; import us.myles.ViaVersion.util.CompactArrayUtil;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
public class WorldPackets { public class WorldPackets {
@ -58,7 +59,7 @@ public class WorldPackets {
} }
CompoundTag heightMaps = chunk.getHeightMap(); CompoundTag heightMaps = chunk.getHeightMap();
for (Tag heightMapTag : heightMaps) { for (Tag heightMapTag : heightMaps.values()) {
LongArrayTag heightMap = (LongArrayTag) heightMapTag; LongArrayTag heightMap = (LongArrayTag) heightMapTag;
int[] heightMapData = new int[256]; int[] heightMapData = new int[256];
CompactArrayUtil.iterateCompactArray(9, heightMapData.length, heightMap.getValue(), (i, v) -> heightMapData[i] = v); CompactArrayUtil.iterateCompactArray(9, heightMapData.length, heightMap.getValue(), (i, v) -> heightMapData[i] = v);
@ -99,21 +100,21 @@ public class WorldPackets {
// target_uuid -> Target // target_uuid -> Target
UUID targetUuid = UUID.fromString((String) targetUuidTag.getValue()); UUID targetUuid = UUID.fromString((String) targetUuidTag.getValue());
compoundTag.put(new IntArrayTag("Target", UUIDIntArrayType.uuidToIntArray(targetUuid))); compoundTag.put("Target", new IntArrayTag(UUIDIntArrayType.uuidToIntArray(targetUuid)));
} else if (id.equals("minecraft:skull") && compoundTag.get("Owner") instanceof CompoundTag) { } else if (id.equals("minecraft:skull") && compoundTag.get("Owner") instanceof CompoundTag) {
CompoundTag ownerTag = compoundTag.remove("Owner"); CompoundTag ownerTag = compoundTag.remove("Owner");
StringTag ownerUuidTag = ownerTag.remove("Id"); StringTag ownerUuidTag = ownerTag.remove("Id");
if (ownerUuidTag != null) { if (ownerUuidTag != null) {
UUID ownerUuid = UUID.fromString(ownerUuidTag.getValue()); UUID ownerUuid = UUID.fromString(ownerUuidTag.getValue());
ownerTag.put(new IntArrayTag("Id", UUIDIntArrayType.uuidToIntArray(ownerUuid))); ownerTag.put("Id", new IntArrayTag(UUIDIntArrayType.uuidToIntArray(ownerUuid)));
} }
// Owner -> SkullOwner // Owner -> SkullOwner
CompoundTag skullOwnerTag = new CompoundTag("SkullOwner"); CompoundTag skullOwnerTag = new CompoundTag();
for (Tag tag : ownerTag) { for (Map.Entry<String, Tag> entry : ownerTag.entrySet()) {
skullOwnerTag.put(tag); skullOwnerTag.put(entry.getKey(), entry.getValue());
} }
compoundTag.put(skullOwnerTag); compoundTag.put("SkullOwner", skullOwnerTag);
} }
} }
} }

View File

@ -216,7 +216,7 @@ public class WorldPackets {
} }
private static void addNewDimensionData(CompoundTag tag) { private static void addNewDimensionData(CompoundTag tag) {
tag.put(new IntTag("min_y", 0)); tag.put("min_y", new IntTag(0));
tag.put(new IntTag("height", 256)); tag.put("height", new IntTag(256));
} }
} }

View File

@ -59,13 +59,13 @@ public class Protocol1_9_3To1_9_1_2 extends Protocol<ClientboundPackets1_9, Clie
wrapper.write(Type.UNSIGNED_BYTE, (short) 9); //Action type (9 update sign) wrapper.write(Type.UNSIGNED_BYTE, (short) 9); //Action type (9 update sign)
//Create nbt //Create nbt
CompoundTag tag = new CompoundTag(""); CompoundTag tag = new CompoundTag();
tag.put(new StringTag("id", "Sign")); tag.put("id", new StringTag("Sign"));
tag.put(new IntTag("x", position.getX())); tag.put("x", new IntTag(position.getX()));
tag.put(new IntTag("y", position.getY())); tag.put("y", new IntTag(position.getY()));
tag.put(new IntTag("z", position.getZ())); tag.put("z", new IntTag(position.getZ()));
for (int i = 0; i < lines.length; i++) { for (int i = 0; i < lines.length; i++) {
tag.put(new StringTag("Text" + (i + 1), lines[i].toString())); tag.put("Text" + (i + 1), new StringTag(lines[i].toString()));
} }
wrapper.write(Type.NBT, tag); wrapper.write(Type.NBT, tag);

View File

@ -42,8 +42,8 @@ public class FakeTileEntity {
} }
private static void register(int material, String name) { private static void register(int material, String name) {
CompoundTag comp = new CompoundTag(""); CompoundTag comp = new CompoundTag();
comp.put(new StringTag(name)); comp.put(name, new StringTag());
tileEntities.put(material, comp); tileEntities.put(material, comp);
} }
@ -61,9 +61,9 @@ public class FakeTileEntity {
CompoundTag originalTag = tileEntities.get(block); CompoundTag originalTag = tileEntities.get(block);
if (originalTag != null) { if (originalTag != null) {
CompoundTag tag = originalTag.clone(); CompoundTag tag = originalTag.clone();
tag.put(new IntTag("x", x)); tag.put("x", new IntTag(x));
tag.put(new IntTag("y", y)); tag.put("y", new IntTag(y));
tag.put(new IntTag("z", z)); tag.put("z", new IntTag(z));
return tag; return tag;
} }
return null; return null;

View File

@ -237,14 +237,14 @@ public class ItemRewriter {
if (item.getIdentifier() == 383 && item.getData() != 0) { // Monster Egg if (item.getIdentifier() == 383 && item.getData() != 0) { // Monster Egg
CompoundTag tag = item.getTag(); CompoundTag tag = item.getTag();
if (tag == null) { if (tag == null) {
tag = new CompoundTag("tag"); tag = new CompoundTag();
} }
CompoundTag entityTag = new CompoundTag("EntityTag"); CompoundTag entityTag = new CompoundTag();
String entityName = ENTTIY_ID_TO_NAME.get((int) item.getData()); String entityName = ENTTIY_ID_TO_NAME.get((int) item.getData());
if (entityName != null) { if (entityName != null) {
StringTag id = new StringTag("id", entityName); StringTag id = new StringTag(entityName);
entityTag.put(id); entityTag.put("id", id);
tag.put(entityTag); tag.put("EntityTag", entityTag);
} }
item.setTag(tag); item.setTag(tag);
item.setData((short) 0); item.setData((short) 0);
@ -252,27 +252,27 @@ public class ItemRewriter {
if (item.getIdentifier() == 373) { // Potion if (item.getIdentifier() == 373) { // Potion
CompoundTag tag = item.getTag(); CompoundTag tag = item.getTag();
if (tag == null) { if (tag == null) {
tag = new CompoundTag("tag"); tag = new CompoundTag();
} }
if (item.getData() >= 16384) { if (item.getData() >= 16384) {
item.setIdentifier(438); // splash id item.setIdentifier(438); // splash id
item.setData((short) (item.getData() - 8192)); item.setData((short) (item.getData() - 8192));
} }
String name = potionNameFromDamage(item.getData()); String name = potionNameFromDamage(item.getData());
StringTag potion = new StringTag("Potion", "minecraft:" + name); StringTag potion = new StringTag("minecraft:" + name);
tag.put(potion); tag.put("Potion", potion);
item.setTag(tag); item.setTag(tag);
item.setData((short) 0); item.setData((short) 0);
} }
if (item.getIdentifier() == 387) { // WRITTEN_BOOK if (item.getIdentifier() == 387) { // WRITTEN_BOOK
CompoundTag tag = item.getTag(); CompoundTag tag = item.getTag();
if (tag == null) { if (tag == null) {
tag = new CompoundTag("tag"); tag = new CompoundTag();
} }
ListTag pages = tag.get("pages"); ListTag pages = tag.get("pages");
if (pages == null) { if (pages == null) {
pages = new ListTag("pages", Collections.<Tag>singletonList(new StringTag(Protocol1_9To1_8.fixJson("").toString()))); pages = new ListTag(Collections.singletonList(new StringTag(Protocol1_9To1_8.fixJson("").toString())));
tag.put(pages); tag.put("pages", pages);
item.setTag(tag); item.setTag(tag);
return; return;
} }

View File

@ -186,13 +186,13 @@ public class WorldPackets {
if (tag != null) { if (tag != null) {
if (tag.contains("EntityId")) { if (tag.contains("EntityId")) {
String entity = (String) tag.get("EntityId").getValue(); String entity = (String) tag.get("EntityId").getValue();
CompoundTag spawn = new CompoundTag("SpawnData"); CompoundTag spawn = new CompoundTag();
spawn.put(new StringTag("id", entity)); spawn.put("id", new StringTag(entity));
tag.put(spawn); tag.put("SpawnData", spawn);
} else { // EntityID does not exist } else { // EntityID does not exist
CompoundTag spawn = new CompoundTag("SpawnData"); CompoundTag spawn = new CompoundTag();
spawn.put(new StringTag("id", "AreaEffectCloud")); //Make spawners show up as empty when no EntityId is given. spawn.put("id", new StringTag("AreaEffectCloud")); //Make spawners show up as empty when no EntityId is given.
tag.put(spawn); tag.put("SpawnData", spawn);
} }
} }
} }

View File

@ -58,9 +58,9 @@ public class CommandBlockStorage extends StoredObject {
return Optional.empty(); return Optional.empty();
tag = tag.clone(); tag = tag.clone();
tag.put(new ByteTag("powered", (byte) 0)); tag.put("powered", new ByteTag((byte) 0));
tag.put(new ByteTag("auto", (byte) 0)); tag.put("auto", new ByteTag((byte) 0));
tag.put(new ByteTag("conditionMet", (byte) 0)); tag.put("conditionMet", new ByteTag((byte) 0));
return Optional.of(tag); return Optional.of(tag);
} }