From 44ae5c8c1b2a04d68e50fea577ece137e9bad0eb Mon Sep 17 00:00:00 2001 From: KennyTV Date: Sun, 14 Mar 2021 18:24:37 +0100 Subject: [PATCH] Update nbt usage --- .../api/rewriters/EnchantmentRewriter.java | 21 +-- .../api/rewriters/EntityRewriterBase.java | 4 +- .../api/rewriters/ItemRewriter.java | 16 +-- .../api/rewriters/ItemRewriterBase.java | 22 ++-- .../rewriters/LegacyBlockItemRewriter.java | 31 ++--- .../rewriters/LegacyEnchantmentRewriter.java | 46 +++---- .../packets/BlockItemPackets1_12.java | 35 ++--- .../block_entity_handlers/BannerHandler.java | 6 +- .../block_entity_handlers/BedHandler.java | 2 +- .../FlowerPotHandler.java | 4 +- .../block_entity_handlers/PistonHandler.java | 10 +- .../block_entity_handlers/SkullHandler.java | 4 +- .../packets/BlockItemPackets1_13.java | 124 +++++++++--------- .../BackwardsBlockEntityProvider.java | 10 +- .../packets/BlockItemPackets1_14.java | 2 +- .../chat/TagSerializer.java | 2 +- .../packets/BlockItemPackets1_16.java | 19 +-- .../packets/BlockItemPackets1_16_2.java | 4 +- .../packets/EntityPackets1_17.java | 8 +- 19 files changed, 187 insertions(+), 183 deletions(-) diff --git a/common/src/main/java/nl/matsv/viabackwards/api/rewriters/EnchantmentRewriter.java b/common/src/main/java/nl/matsv/viabackwards/api/rewriters/EnchantmentRewriter.java index fe784c5a..f69415e4 100644 --- a/common/src/main/java/nl/matsv/viabackwards/api/rewriters/EnchantmentRewriter.java +++ b/common/src/main/java/nl/matsv/viabackwards/api/rewriters/EnchantmentRewriter.java @@ -4,6 +4,7 @@ import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; import us.myles.viaversion.libs.opennbt.tag.builtin.ListTag; +import us.myles.viaversion.libs.opennbt.tag.builtin.NumberTag; import us.myles.viaversion.libs.opennbt.tag.builtin.ShortTag; import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag; import us.myles.viaversion.libs.opennbt.tag.builtin.Tag; @@ -77,42 +78,42 @@ public class EnchantmentRewriter { if (remappedName != null) { if (!changed) { // Backup original before doing modifications - itemRewriter.saveListTag(tag, enchantments); + itemRewriter.saveListTag(tag, enchantments, key); changed = true; } iterator.remove(); - Number level = (Number) enchantmentEntry.get("lvl").getValue(); - String loreValue = remappedName + " " + getRomanNumber(level.intValue()); + int level = ((NumberTag) enchantmentEntry.get("lvl")).asInt(); + String loreValue = remappedName + " " + getRomanNumber(level); if (jsonFormat) { loreValue = ChatRewriter.legacyTextToJsonString(loreValue); } - loreToAdd.add(new StringTag("", loreValue)); + loreToAdd.add(new StringTag(loreValue)); } } if (!loreToAdd.isEmpty()) { // Add dummy enchant for the glow effect if there are no actual enchantments left if (!storedEnchant && enchantments.size() == 0) { - CompoundTag dummyEnchantment = new CompoundTag(""); - dummyEnchantment.put(new StringTag("id", "")); - dummyEnchantment.put(new ShortTag("lvl", (short) 0)); + CompoundTag dummyEnchantment = new CompoundTag(); + dummyEnchantment.put("id", new StringTag()); + dummyEnchantment.put("lvl", new ShortTag((short) 0)); enchantments.add(dummyEnchantment); } CompoundTag display = tag.get("display"); if (display == null) { - tag.put(display = new CompoundTag("display")); + tag.put("display", display = new CompoundTag()); } ListTag loreTag = display.get("Lore"); if (loreTag == null) { - display.put(loreTag = new ListTag("Lore", StringTag.class)); + display.put("Lore", loreTag = new ListTag(StringTag.class)); } else { // Save original lore - itemRewriter.saveListTag(display, loreTag); + itemRewriter.saveListTag(display, loreTag, "Lore"); } loreToAdd.addAll(loreTag.getValue()); diff --git a/common/src/main/java/nl/matsv/viabackwards/api/rewriters/EntityRewriterBase.java b/common/src/main/java/nl/matsv/viabackwards/api/rewriters/EntityRewriterBase.java index 0eb4fd0f..0a601708 100644 --- a/common/src/main/java/nl/matsv/viabackwards/api/rewriters/EntityRewriterBase.java +++ b/common/src/main/java/nl/matsv/viabackwards/api/rewriters/EntityRewriterBase.java @@ -267,7 +267,7 @@ public abstract class EntityRewriterBase extends Re CompoundTag registryData = wrapper.get(Type.NBT, nbtIndex); Tag height = registryData.get("height"); if (height instanceof IntTag) { - int blockHeight = ((IntTag) height).getValue(); + int blockHeight = ((IntTag) height).asInt(); tracker.setCurrentWorldSectionHeight(blockHeight >> 4); } else { ViaBackwards.getPlatform().getLogger().warning("Height missing in dimension data: " + registryData); @@ -275,7 +275,7 @@ public abstract class EntityRewriterBase extends Re Tag minY = registryData.get("min_y"); if (minY instanceof IntTag) { - tracker.setCurrentMinY(((IntTag) minY).getValue()); + tracker.setCurrentMinY(((IntTag) minY).asInt()); } else { ViaBackwards.getPlatform().getLogger().warning("Min Y missing in dimension data: " + registryData); } diff --git a/common/src/main/java/nl/matsv/viabackwards/api/rewriters/ItemRewriter.java b/common/src/main/java/nl/matsv/viabackwards/api/rewriters/ItemRewriter.java index f58f4f96..8629b78f 100644 --- a/common/src/main/java/nl/matsv/viabackwards/api/rewriters/ItemRewriter.java +++ b/common/src/main/java/nl/matsv/viabackwards/api/rewriters/ItemRewriter.java @@ -32,7 +32,7 @@ public abstract class ItemRewriter extends ItemRewr if (name != null) { String newValue = translatableRewriter.processText(name.getValue()).toString(); if (!newValue.equals(name.getValue())) { - saveStringTag(display, name); + saveStringTag(display, name, "Name"); } name.setValue(newValue); @@ -49,7 +49,7 @@ public abstract class ItemRewriter extends ItemRewr if (!changed && !newValue.equals(loreEntry.getValue())) { // Backup original lore before doing any modifications changed = true; - saveListTag(display, lore); + saveListTag(display, lore, "Lore"); } loreEntry.setValue(newValue); @@ -64,20 +64,20 @@ public abstract class ItemRewriter extends ItemRewr } if (item.getTag() == null) { - item.setTag(new CompoundTag("")); + item.setTag(new CompoundTag()); } // Save original id, set remapped id - item.getTag().put(new IntTag(nbtTagName + "|id", item.getIdentifier())); + item.getTag().put(nbtTagName + "|id", new IntTag(item.getIdentifier())); item.setIdentifier(data.getId()); // Set custom name - only done if there is no original one if (display == null) { - item.getTag().put(display = new CompoundTag("display")); + item.getTag().put("display", display = new CompoundTag()); } if (!display.contains("Name")) { - display.put(new StringTag("Name", data.getJsonName())); - display.put(new ByteTag(nbtTagName + "|customName")); + display.put("Name", new StringTag(data.getJsonName())); + display.put(nbtTagName + "|customName", new ByteTag()); } return item; } @@ -91,7 +91,7 @@ public abstract class ItemRewriter extends ItemRewr if (item.getTag() != null) { IntTag originalId = item.getTag().remove(nbtTagName + "|id"); if (originalId != null) { - item.setIdentifier(originalId.getValue()); + item.setIdentifier(originalId.asInt()); } } return item; diff --git a/common/src/main/java/nl/matsv/viabackwards/api/rewriters/ItemRewriterBase.java b/common/src/main/java/nl/matsv/viabackwards/api/rewriters/ItemRewriterBase.java index 9ecf58ec..51742756 100644 --- a/common/src/main/java/nl/matsv/viabackwards/api/rewriters/ItemRewriterBase.java +++ b/common/src/main/java/nl/matsv/viabackwards/api/rewriters/ItemRewriterBase.java @@ -42,25 +42,25 @@ public abstract class ItemRewriterBase extends Rewr return displayTag.contains(nbtTagName + "|o" + tagName); } - protected void saveStringTag(CompoundTag displayTag, StringTag original) { + protected void saveStringTag(CompoundTag displayTag, StringTag original, String name) { // Multiple places might try to backup data - String name = nbtTagName + "|o" + original.getName(); - if (!displayTag.contains(name)) { - displayTag.put(new StringTag(name, original.getValue())); + String backupName = nbtTagName + "|o" + name; + if (!displayTag.contains(backupName)) { + displayTag.put(backupName, new StringTag(original.getValue())); } } - protected void saveListTag(CompoundTag displayTag, ListTag original) { + protected void saveListTag(CompoundTag displayTag, ListTag original, String name) { // Multiple places might try to backup data - String name = nbtTagName + "|o" + original.getName(); - if (!displayTag.contains(name)) { + String backupName = nbtTagName + "|o" + name; + if (!displayTag.contains(backupName)) { // Clone all tag entries - ListTag listTag = new ListTag(name); + ListTag listTag = new ListTag(); for (Tag tag : original.getValue()) { listTag.add(tag.clone()); } - displayTag.put(listTag); + displayTag.put(backupName, listTag); } } @@ -84,14 +84,14 @@ public abstract class ItemRewriterBase extends Rewr protected void restoreStringTag(CompoundTag tag, String tagName) { StringTag original = tag.remove(nbtTagName + "|o" + tagName); if (original != null) { - tag.put(new StringTag(tagName, original.getValue())); + tag.put(tagName, new StringTag(original.getValue())); } } protected void restoreListTag(CompoundTag tag, String tagName) { ListTag original = tag.remove(nbtTagName + "|o" + tagName); if (original != null) { - tag.put(new ListTag(tagName, original.getValue())); + tag.put(tagName, new ListTag(original.getValue())); } } diff --git a/common/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyBlockItemRewriter.java b/common/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyBlockItemRewriter.java index c3011037..31ddccfe 100644 --- a/common/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyBlockItemRewriter.java +++ b/common/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyBlockItemRewriter.java @@ -28,6 +28,7 @@ import us.myles.viaversion.libs.gson.JsonPrimitive; import us.myles.viaversion.libs.opennbt.tag.builtin.ByteTag; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; import us.myles.viaversion.libs.opennbt.tag.builtin.IntTag; +import us.myles.viaversion.libs.opennbt.tag.builtin.NumberTag; import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag; import us.myles.viaversion.libs.opennbt.tag.builtin.Tag; @@ -103,24 +104,24 @@ public abstract class LegacyBlockItemRewriter exten // Set display name if (data.getName() != null) { if (item.getTag() == null) { - item.setTag(new CompoundTag("")); + item.setTag(new CompoundTag()); } CompoundTag display = item.getTag().get("display"); if (display == null) { - item.getTag().put(display = new CompoundTag("display")); + item.getTag().put("display", display = new CompoundTag()); } StringTag nameTag = display.get("Name"); if (nameTag == null) { - display.put(nameTag = new StringTag("Name", data.getName())); - display.put(new ByteTag(nbtTagName + "|customName")); + display.put("Name", nameTag = new StringTag(data.getName())); + display.put(nbtTagName + "|customName", new ByteTag()); } // Handle colors String value = nameTag.getValue(); if (value.contains("%vb_color%")) { - display.put(new StringTag("Name", value.replace("%vb_color%", BlockColors.get(originalData)))); + display.put("Name", new StringTag(value.replace("%vb_color%", BlockColors.get(originalData)))); } } return item; @@ -161,9 +162,9 @@ public abstract class LegacyBlockItemRewriter exten } Pos pos = new Pos( - (int) xTag.getValue() & 0xF, - (int) yTag.getValue(), - (int) zTag.getValue() & 0xF); + ((NumberTag) xTag).asInt() & 0xF, + ((NumberTag) yTag).asInt(), + ((NumberTag) zTag).asInt() & 0xF); tags.put(pos, tag); // Handle given Block Entities @@ -223,10 +224,10 @@ public abstract class LegacyBlockItemRewriter exten // Already handled above if (tags.containsKey(pos)) continue; - CompoundTag tag = new CompoundTag(""); - tag.put(new IntTag("x", x + (chunk.getX() << 4))); - tag.put(new IntTag("y", y + (i << 4))); - tag.put(new IntTag("z", z + (chunk.getZ() << 4))); + CompoundTag tag = new CompoundTag(); + tag.put("x", new IntTag(x + (chunk.getX() << 4))); + tag.put("y", new IntTag(y + (i << 4))); + tag.put("z", new IntTag(z + (chunk.getZ() << 4))); settings.getBlockEntityHandler().handleOrNewCompoundTag(block, tag); chunk.getBlockEntities().add(tag); @@ -237,10 +238,10 @@ public abstract class LegacyBlockItemRewriter exten } protected CompoundTag getNamedTag(String text) { - CompoundTag tag = new CompoundTag(""); - tag.put(new CompoundTag("display")); + CompoundTag tag = new CompoundTag(); + tag.put("display", new CompoundTag()); text = "§r" + text; - ((CompoundTag) tag.get("display")).put(new StringTag("Name", jsonNameFormat ? ChatRewriter.legacyTextToJsonString(text) : text)); + ((CompoundTag) tag.get("display")).put("Name", new StringTag(jsonNameFormat ? ChatRewriter.legacyTextToJsonString(text) : text)); return tag; } diff --git a/common/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyEnchantmentRewriter.java b/common/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyEnchantmentRewriter.java index 30a4f31a..3b92970b 100644 --- a/common/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyEnchantmentRewriter.java +++ b/common/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyEnchantmentRewriter.java @@ -21,55 +21,55 @@ public class LegacyEnchantmentRewriter { public void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnchant) { String key = storedEnchant ? "StoredEnchantments" : "ench"; ListTag enchantments = tag.get(key); - ListTag remappedEnchantments = new ListTag(nbtTagName + "|" + key, CompoundTag.class); + ListTag remappedEnchantments = new ListTag( CompoundTag.class); List lore = new ArrayList<>(); for (Tag enchantmentEntry : enchantments.clone()) { Tag idTag = ((CompoundTag) enchantmentEntry).get("id"); if (idTag == null) continue; - short newId = ((Number) idTag.getValue()).shortValue(); + short newId = ((NumberTag) idTag).asShort(); String enchantmentName = enchantmentMappings.get(newId); if (enchantmentName != null) { enchantments.remove(enchantmentEntry); - Number level = (Number) ((CompoundTag) enchantmentEntry).get("lvl").getValue(); + short level = ((NumberTag) ((CompoundTag) enchantmentEntry).get("lvl")).asShort(); if (hideLevelForEnchants != null && hideLevelForEnchants.contains(newId)) { - lore.add(new StringTag("", enchantmentName)); + lore.add(new StringTag(enchantmentName)); } else { - lore.add(new StringTag("", enchantmentName + " " + EnchantmentRewriter.getRomanNumber(level.shortValue()))); + lore.add(new StringTag(enchantmentName + " " + EnchantmentRewriter.getRomanNumber(level))); } remappedEnchantments.add(enchantmentEntry); } } if (!lore.isEmpty()) { if (!storedEnchant && enchantments.size() == 0) { - CompoundTag dummyEnchantment = new CompoundTag(""); - dummyEnchantment.put(new ShortTag("id", (short) 0)); - dummyEnchantment.put(new ShortTag("lvl", (short) 0)); + CompoundTag dummyEnchantment = new CompoundTag(); + dummyEnchantment.put("id", new ShortTag((short) 0)); + dummyEnchantment.put("lvl", new ShortTag((short) 0)); enchantments.add(dummyEnchantment); - tag.put(new ByteTag(nbtTagName + "|dummyEnchant")); + tag.put(nbtTagName + "|dummyEnchant", new ByteTag()); IntTag hideFlags = tag.get("HideFlags"); if (hideFlags == null) { - hideFlags = new IntTag("HideFlags"); + hideFlags = new IntTag(); } else { - tag.put(new IntTag(nbtTagName + "|oldHideFlags", hideFlags.getValue())); + tag.put(nbtTagName + "|oldHideFlags", new IntTag(hideFlags.asByte())); } - int flags = hideFlags.getValue() | 1; + int flags = hideFlags.asByte() | 1; hideFlags.setValue(flags); - tag.put(hideFlags); + tag.put("HideFlags", hideFlags); } - tag.put(remappedEnchantments); + tag.put(nbtTagName + "|" + key,remappedEnchantments); CompoundTag display = tag.get("display"); if (display == null) { - tag.put(display = new CompoundTag("display")); + tag.put("display", display = new CompoundTag()); } ListTag loreTag = display.get("Lore"); if (loreTag == null) { - display.put(loreTag = new ListTag("Lore", StringTag.class)); + display.put("Lore", loreTag = new ListTag(StringTag.class)); } lore.addAll(loreTag.getValue()); @@ -79,16 +79,16 @@ public class LegacyEnchantmentRewriter { public void rewriteEnchantmentsToServer(CompoundTag tag, boolean storedEnchant) { String key = storedEnchant ? "StoredEnchantments" : "ench"; - ListTag remappedEnchantments = tag.get(nbtTagName + "|" + key); + ListTag remappedEnchantments = tag.remove(nbtTagName + "|" + key); ListTag enchantments = tag.get(key); if (enchantments == null) { - enchantments = new ListTag(key, CompoundTag.class); + enchantments = new ListTag(CompoundTag.class); } if (!storedEnchant && tag.remove(nbtTagName + "|dummyEnchant") != null) { for (Tag enchantment : enchantments.clone()) { - Short id = (Short) ((CompoundTag) enchantment).get("id").getValue(); - Short level = (Short) ((CompoundTag) enchantment).get("lvl").getValue(); + short id = ((NumberTag) ((CompoundTag) enchantment).get("id")).asShort(); + short level = ((NumberTag) ((CompoundTag) enchantment).get("lvl")).asShort(); if (id == 0 && level == 0) { enchantments.remove(enchantment); } @@ -96,7 +96,7 @@ public class LegacyEnchantmentRewriter { IntTag hideFlags = tag.remove(nbtTagName + "|oldHideFlags"); if (hideFlags != null) { - tag.put(new IntTag("HideFlags", hideFlags.getValue())); + tag.put("HideFlags", new IntTag(hideFlags.asByte())); } else { tag.remove("HideFlags"); } @@ -117,8 +117,8 @@ public class LegacyEnchantmentRewriter { tag.remove("display"); } } - tag.put(enchantments); - tag.remove(remappedEnchantments.getName()); + + tag.put(key, enchantments); } public void setHideLevelForEnchants(int... enchants) { diff --git a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/BlockItemPackets1_12.java b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/BlockItemPackets1_12.java index 37580147..c6f19324 100644 --- a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/BlockItemPackets1_12.java +++ b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/BlockItemPackets1_12.java @@ -33,6 +33,7 @@ import us.myles.viaversion.libs.opennbt.tag.builtin.LongArrayTag; import us.myles.viaversion.libs.opennbt.tag.builtin.Tag; import java.util.Iterator; +import java.util.Map; public class BlockItemPackets1_12 extends LegacyBlockItemRewriter { @@ -260,9 +261,9 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter iterator = compoundTag.iterator(); + Iterator> iterator = compoundTag.iterator(); boolean hasLongArrayTag = false; while (iterator.hasNext()) { - Tag tag = iterator.next(); - if (tag instanceof CompoundTag) { - CompoundTag nestedBackupTag = new CompoundTag(tag.getName()); - backupTag.put(nestedBackupTag); - hasLongArrayTag |= handleNbtToClient((CompoundTag) tag, nestedBackupTag); - } else if (tag instanceof LongArrayTag) { - backupTag.put(fromLongArrayTag((LongArrayTag) tag)); + Map.Entry entry = iterator.next(); + if (entry.getValue() instanceof CompoundTag) { + CompoundTag nestedBackupTag = new CompoundTag(); + backupTag.put(entry.getKey(), nestedBackupTag); + hasLongArrayTag |= handleNbtToClient((CompoundTag) entry.getValue(), nestedBackupTag); + } else if (entry.getValue() instanceof LongArrayTag) { + backupTag.put(entry.getKey(), fromLongArrayTag((LongArrayTag) entry.getValue())); iterator.remove(); hasLongArrayTag = true; } @@ -306,12 +307,12 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter entry: backupTag) { + if (entry.getValue() instanceof CompoundTag) { + CompoundTag nestedTag = compoundTag.get(entry.getKey()); + handleNbtToServer(nestedTag, (CompoundTag) entry.getValue()); } else { - compoundTag.put(fromIntArrayTag((IntArrayTag) tag)); + compoundTag.put(entry.getKey(), fromIntArrayTag((IntArrayTag) entry.getValue())); } } } @@ -324,7 +325,7 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter> 32); intArray[i++] = (int) l; } - return new IntArrayTag(tag.getName(), intArray); + return new IntArrayTag(intArray); } private LongArrayTag fromIntArrayTag(IntArrayTag tag) { @@ -333,6 +334,6 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter= BANNER_START && blockId <= BANNER_STOP) { int color = (blockId - BANNER_START) >> 4; - tag.put(new IntTag("Base", (15 - color))); + tag.put("Base", new IntTag((15 - color))); } // Wall banners else if (blockId >= WALL_BANNER_START && blockId <= WALL_BANNER_STOP) { int color = (blockId - WALL_BANNER_START) >> 2; - tag.put(new IntTag("Base", (15 - color))); + tag.put("Base", new IntTag((15 - color))); } else { ViaBackwards.getPlatform().getLogger().warning("Why does this block have the banner block entity? :(" + tag); } @@ -47,7 +47,7 @@ public class BannerHandler implements BackwardsBlockEntityHandler { if (!(pattern instanceof CompoundTag)) continue; IntTag c = ((CompoundTag) pattern).get("Color"); - c.setValue(15 - c.getValue()); // Invert color id + c.setValue(15 - c.asInt()); // Invert color id } } diff --git a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BedHandler.java b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BedHandler.java index b05f7809..44a43f4f 100644 --- a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BedHandler.java +++ b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BedHandler.java @@ -22,7 +22,7 @@ public class BedHandler implements BackwardsBlockEntityProvider.BackwardsBlockEn int offset = blockId - 748; int color = offset >> 4; - tag.put(new IntTag("color", color)); + tag.put("color", new IntTag(color)); return tag; } diff --git a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/FlowerPotHandler.java b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/FlowerPotHandler.java index 24c5d57b..b2101281 100644 --- a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/FlowerPotHandler.java +++ b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/FlowerPotHandler.java @@ -67,8 +67,8 @@ public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsB public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) { Pair item = getOrDefault(blockId); - tag.put(new StringTag("Item", item.getKey())); - tag.put(new IntTag("Data", item.getValue())); + tag.put("Item", new StringTag(item.getKey())); + tag.put("Data", new IntTag(item.getValue())); return tag; } diff --git a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/PistonHandler.java b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/PistonHandler.java index 935479c0..c58dbde0 100644 --- a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/PistonHandler.java +++ b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/PistonHandler.java @@ -79,8 +79,8 @@ public class PistonHandler implements BackwardsBlockEntityProvider.BackwardsBloc return tag; } - tag.put(new IntTag("blockId", id >> 4)); - tag.put(new IntTag("blockData", id & 15)); + tag.put("blockId", new IntTag(id >> 4)); + tag.put("blockData", new IntTag(id & 15)); return tag; } @@ -93,9 +93,9 @@ public class PistonHandler implements BackwardsBlockEntityProvider.BackwardsBloc if (properties == null) return name.getValue(); StringJoiner joiner = new StringJoiner(",", name.getValue() + "[", "]"); - for (Tag property : properties) { - if (!(property instanceof StringTag)) continue; - joiner.add(property.getName() + "=" + ((StringTag) property).getValue()); + for (Map.Entry entry : properties) { + if (!(entry.getValue() instanceof StringTag)) continue; + joiner.add(entry.getKey() + "=" + ((StringTag) entry.getValue()).getValue()); } return joiner.toString(); } diff --git a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SkullHandler.java b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SkullHandler.java index ea8ad321..37d289de 100644 --- a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SkullHandler.java +++ b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SkullHandler.java @@ -25,7 +25,7 @@ public class SkullHandler implements BackwardsBlockEntityHandler { byte type = (byte) Math.floor(diff / 20f); // Set type - tag.put(new ByteTag("SkullType", type)); + tag.put("SkullType", new ByteTag(type)); // Remove wall skulls if (pos < 4) { @@ -33,7 +33,7 @@ public class SkullHandler implements BackwardsBlockEntityHandler { } // Add rotation for normal skulls - tag.put(new ByteTag("Rot", (byte) ((pos - 4) & 255))); + tag.put("Rot", new ByteTag((byte) ((pos - 4) & 255))); return tag; } diff --git a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java index 76dc9e5b..b835ed89 100644 --- a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java +++ b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java @@ -43,6 +43,7 @@ import us.myles.viaversion.libs.opennbt.tag.builtin.ByteTag; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; import us.myles.viaversion.libs.opennbt.tag.builtin.IntTag; import us.myles.viaversion.libs.opennbt.tag.builtin.ListTag; +import us.myles.viaversion.libs.opennbt.tag.builtin.NumberTag; import us.myles.viaversion.libs.opennbt.tag.builtin.ShortTag; import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag; import us.myles.viaversion.libs.opennbt.tag.builtin.Tag; @@ -295,12 +296,12 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It // Ignore if we don't handle it if (!provider.isHandled(id)) continue; - int sectionIndex = ((int) tag.get("y").getValue()) >> 4; + int sectionIndex = ((NumberTag) tag.get("y")).asInt() >> 4; ChunkSection section = chunk.getSections()[sectionIndex]; - int x = (int) tag.get("x").getValue(); - int y = (int) tag.get("y").getValue(); - int z = (int) tag.get("z").getValue(); + int x = ((NumberTag) tag.get("x")).asInt(); + int y = ((NumberTag) tag.get("y")).asInt(); + int z = ((NumberTag) tag.get("z")).asInt(); Position position = new Position(x, (short) y, z); int block = section.getFlatBlock(x & 0xF, y & 0xF, z & 0xF); @@ -519,7 +520,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It // Use tag to get original ID and data Tag originalIdTag; if (tag != null && (originalIdTag = tag.remove(extraNbtTag)) != null) { - rawId = (Integer) originalIdTag.getValue(); + rawId = ((NumberTag) originalIdTag).asInt(); gotRawIdFromTag = true; } @@ -575,7 +576,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It if (display != null) { StringTag name = display.get("Name"); if (name != null) { - display.put(new StringTag(extraNbtTag + "|Name", name.getValue())); + display.put(extraNbtTag + "|Name", new StringTag(name.getValue())); name.setValue(ChatRewriter.jsonToLegacyText(name.getValue())); } } @@ -594,12 +595,12 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It Optional eggEntityId = SpawnEggRewriter.getEntityId(oldId); if (eggEntityId.isPresent()) { if (tag == null) { - item.setTag(tag = new CompoundTag("tag")); + item.setTag(tag = new CompoundTag()); } if (!tag.contains("EntityTag")) { - CompoundTag entityTag = new CompoundTag("EntityTag"); - entityTag.put(new StringTag("id", eggEntityId.get())); - tag.put(entityTag); + CompoundTag entityTag = new CompoundTag(); + entityTag.put("id", new StringTag(eggEntityId.get())); + tag.put("EntityTag", entityTag); } return 0x17f0000; // 383 << 16; } @@ -613,21 +614,21 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It ListTag blockTag = tag.get(tagName); if (blockTag == null) return; - ListTag newCanPlaceOn = new ListTag(tagName, StringTag.class); - tag.put(ConverterRegistry.convertToTag(extraNbtTag + "|" + tagName, ConverterRegistry.convertToValue(blockTag))); + ListTag newCanPlaceOn = new ListTag(StringTag.class); + tag.put(extraNbtTag + "|" + tagName, ConverterRegistry.convertToTag(ConverterRegistry.convertToValue(blockTag))); for (Tag oldTag : blockTag) { Object value = oldTag.getValue(); String[] newValues = value instanceof String ? BlockIdData.fallbackReverseMapping.get(((String) value).replace("minecraft:", "")) : null; if (newValues != null) { for (String newValue : newValues) { - newCanPlaceOn.add(new StringTag("", newValue)); + newCanPlaceOn.add(new StringTag(newValue)); } } else { newCanPlaceOn.add(oldTag); } } - tag.put(newCanPlaceOn); + tag.put(tagName, newCanPlaceOn); } //TODO un-ugly all of this @@ -636,8 +637,8 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It ListTag enchantments = tag.get(key); if (enchantments == null) return; - ListTag noMapped = new ListTag(extraNbtTag + "|" + key, CompoundTag.class); - ListTag newEnchantments = new ListTag(storedEnch ? key : "ench", CompoundTag.class); + ListTag noMapped = new ListTag(CompoundTag.class); + ListTag newEnchantments = new ListTag(CompoundTag.class); List lore = new ArrayList<>(); boolean hasValidEnchants = false; for (Tag enchantmentEntryTag : enchantments.clone()) { @@ -646,13 +647,12 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It if (!(idTag instanceof StringTag)) continue; String newId = (String) idTag.getValue(); - Number levelValue = (Number) enchantmentEntry.get("lvl").getValue(); - int intValue = levelValue.intValue(); - short level = intValue < Short.MAX_VALUE ? levelValue.shortValue() : Short.MAX_VALUE; + int levelValue = ((NumberTag) enchantmentEntry.get("lvl")).asInt(); + short level = levelValue < Short.MAX_VALUE ? (short) levelValue : Short.MAX_VALUE; String mappedEnchantmentId = enchantmentMappings.get(newId); if (mappedEnchantmentId != null) { - lore.add(new StringTag("", mappedEnchantmentId + " " + EnchantmentRewriter.getRomanNumber(level))); + lore.add(new StringTag(mappedEnchantmentId + " " + EnchantmentRewriter.getRomanNumber(level))); noMapped.add(enchantmentEntry); } else if (!newId.isEmpty()) { Short oldId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().inverse().get(newId); @@ -670,7 +670,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It } name = "§7" + Character.toUpperCase(name.charAt(0)) + name.substring(1).toLowerCase(Locale.ENGLISH); - lore.add(new StringTag("", name + " " + EnchantmentRewriter.getRomanNumber(level))); + lore.add(new StringTag(name + " " + EnchantmentRewriter.getRomanNumber(level))); } if (Via.getManager().isDebug()) { @@ -686,9 +686,9 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It hasValidEnchants = true; } - CompoundTag newEntry = new CompoundTag(""); - newEntry.put(new ShortTag("id", oldId)); - newEntry.put(new ShortTag("lvl", level)); + CompoundTag newEntry = new CompoundTag(); + newEntry.put("id", new ShortTag(oldId)); + newEntry.put("lvl", new ShortTag(level)); newEnchantments.add(newEntry); } } @@ -697,43 +697,43 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It if (!storedEnch && !hasValidEnchants) { IntTag hideFlags = tag.get("HideFlags"); if (hideFlags == null) { - hideFlags = new IntTag("HideFlags"); - tag.put(new ByteTag(extraNbtTag + "|DummyEnchant")); + hideFlags = new IntTag(); + tag.put(extraNbtTag + "|DummyEnchant", new ByteTag()); } else { - tag.put(new IntTag(extraNbtTag + "|OldHideFlags", hideFlags.getValue())); + tag.put(extraNbtTag + "|OldHideFlags", new IntTag(hideFlags.asByte())); } if (newEnchantments.size() == 0) { - CompoundTag enchEntry = new CompoundTag(""); - enchEntry.put(new ShortTag("id", (short) 0)); - enchEntry.put(new ShortTag("lvl", (short) 0)); + CompoundTag enchEntry = new CompoundTag(); + enchEntry.put("id", new ShortTag((short) 0)); + enchEntry.put("lvl", new ShortTag((short) 0)); newEnchantments.add(enchEntry); } - int value = hideFlags.getValue() | 1; + int value = hideFlags.asByte() | 1; hideFlags.setValue(value); - tag.put(hideFlags); + tag.put("HideFlags", hideFlags); } if (noMapped.size() != 0) { - tag.put(noMapped); + tag.put(extraNbtTag + "|" + key, noMapped); if (!lore.isEmpty()) { CompoundTag display = tag.get("display"); if (display == null) { - tag.put(display = new CompoundTag("display")); + tag.put("display", display = new CompoundTag()); } ListTag loreTag = display.get("Lore"); if (loreTag == null) { - display.put(loreTag = new ListTag("Lore", StringTag.class)); - tag.put(new ByteTag(extraNbtTag + "|DummyLore")); + display.put("Lore", loreTag = new ListTag(StringTag.class)); + tag.put(extraNbtTag + "|DummyLore", new ByteTag()); } else if (loreTag.size() != 0) { - ListTag oldLore = new ListTag(extraNbtTag + "|OldLore", StringTag.class); + ListTag oldLore = new ListTag(StringTag.class); for (Tag value : loreTag) { oldLore.add(value.clone()); } - tag.put(oldLore); + tag.put(extraNbtTag + "|OldLore", oldLore); lore.addAll(loreTag.getValue()); } @@ -743,7 +743,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It } tag.remove("Enchantments"); - tag.put(newEnchantments); + tag.put(storedEnch ? key : "ench", newEnchantments); } @Override @@ -758,12 +758,12 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It // NBT Additions if (isDamageable(item.getIdentifier())) { - if (tag == null) item.setTag(tag = new CompoundTag("tag")); - tag.put(new IntTag("Damage", item.getData())); + if (tag == null) item.setTag(tag = new CompoundTag()); + tag.put("Damage", new IntTag(item.getData())); } if (item.getIdentifier() == 358) { // map - if (tag == null) item.setTag(tag = new CompoundTag("tag")); - tag.put(new IntTag("map", item.getData())); + if (tag == null) item.setTag(tag = new CompoundTag()); + tag.put("map", new IntTag(item.getData())); } // NBT Changes @@ -827,8 +827,8 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It int newId = -1; if (!protocol.getMappingData().getItemMappings().inverse().containsKey(rawId)) { if (!isDamageable(item.getIdentifier()) && item.getIdentifier() != 358) { // Map - if (tag == null) item.setTag(tag = new CompoundTag("tag")); - tag.put(new IntTag(extraNbtTag, originalId)); // Data will be lost, saving original id + if (tag == null) item.setTag(tag = new CompoundTag()); + tag.put(extraNbtTag, new IntTag(originalId)); // Data will be lost, saving original id } if (item.getIdentifier() == 229) { // purple shulker box @@ -858,9 +858,9 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It if (!(tag.get(tagName) instanceof ListTag)) return; ListTag blockTag = tag.remove(extraNbtTag + "|" + tagName); if (blockTag != null) { - tag.put(ConverterRegistry.convertToTag(tagName, ConverterRegistry.convertToValue(blockTag))); + tag.put(tagName, ConverterRegistry.convertToTag(ConverterRegistry.convertToValue(blockTag))); } else if ((blockTag = tag.get(tagName)) != null) { - ListTag newCanPlaceOn = new ListTag(tagName, StringTag.class); + ListTag newCanPlaceOn = new ListTag(StringTag.class); for (Tag oldTag : blockTag) { Object value = oldTag.getValue(); String oldId = value.toString().replace("minecraft:", ""); @@ -874,13 +874,13 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It String[] newValues = BlockIdData.blockIdMapping.get(lowerCaseId); if (newValues != null) { for (String newValue : newValues) { - newCanPlaceOn.add(new StringTag("", newValue)); + newCanPlaceOn.add(new StringTag(newValue)); } } else { - newCanPlaceOn.add(new StringTag("", lowerCaseId)); + newCanPlaceOn.add(new StringTag(lowerCaseId)); } } - tag.put(newCanPlaceOn); + tag.put(tagName, newCanPlaceOn); } } @@ -889,12 +889,12 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It ListTag enchantments = tag.get(storedEnch ? key : "ench"); if (enchantments == null) return; - ListTag newEnchantments = new ListTag(key, CompoundTag.class); + ListTag newEnchantments = new ListTag(CompoundTag.class); boolean dummyEnchant = false; if (!storedEnch) { IntTag hideFlags = tag.remove(extraNbtTag + "|OldHideFlags"); if (hideFlags != null) { - tag.put(new IntTag("HideFlags", hideFlags.getValue())); + tag.put("HideFlags", new IntTag(hideFlags.asByte())); dummyEnchant = true; } else if (tag.remove(extraNbtTag + "|DummyEnchant") != null) { tag.remove("HideFlags"); @@ -903,9 +903,9 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It } for (Tag enchEntry : enchantments) { - CompoundTag enchantmentEntry = new CompoundTag(""); - short oldId = ((Number) ((CompoundTag) enchEntry).get("id").getValue()).shortValue(); - short level = ((Number) ((CompoundTag) enchEntry).get("lvl").getValue()).shortValue(); + CompoundTag enchantmentEntry = new CompoundTag(); + short oldId = ((NumberTag) ((CompoundTag) enchEntry).get("id")).asShort(); + short level = ((NumberTag) ((CompoundTag) enchEntry).get("lvl")).asShort(); if (dummyEnchant && oldId == 0 && level == 0) { continue; //Skip dummy enchatment } @@ -913,9 +913,9 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It if (newId == null) { newId = "viaversion:legacy/" + oldId; } - enchantmentEntry.put(new StringTag("id", newId)); + enchantmentEntry.put("id", new StringTag(newId)); - enchantmentEntry.put(new ShortTag("lvl", level)); + enchantmentEntry.put("lvl", new ShortTag(level)); newEnchantments.add(enchantmentEntry); } @@ -928,14 +928,14 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It CompoundTag display = tag.get("display"); if (display == null) { - tag.put(display = new CompoundTag("display")); + tag.put("display", display = new CompoundTag()); } ListTag oldLore = tag.remove(extraNbtTag + "|OldLore"); if (oldLore != null) { ListTag lore = display.get("Lore"); if (lore == null) { - tag.put(lore = new ListTag("Lore")); + tag.put("Lore", lore = new ListTag()); } lore.setValue(oldLore.getValue()); @@ -949,7 +949,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It if (!storedEnch) { tag.remove("ench"); } - tag.put(newEnchantments); + tag.put(key, newEnchantments); } private void invertShieldAndBannerId(Item item, CompoundTag tag) { @@ -962,7 +962,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It Tag base = blockEntityCompoundTag.get("Base"); if (base instanceof IntTag) { IntTag baseTag = (IntTag) base; - baseTag.setValue(15 - baseTag.getValue()); // invert color id + baseTag.setValue(15 - baseTag.asInt()); // invert color id } Tag patterns = blockEntityCompoundTag.get("Patterns"); @@ -972,7 +972,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It if (!(pattern instanceof CompoundTag)) continue; IntTag colorTag = ((CompoundTag) pattern).get("Color"); - colorTag.setValue(15 - colorTag.getValue()); // Invert color id + colorTag.setValue(15 - colorTag.asInt()); // Invert color id } } } diff --git a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/providers/BackwardsBlockEntityProvider.java b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/providers/BackwardsBlockEntityProvider.java index 6fceac23..c4b115a4 100644 --- a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/providers/BackwardsBlockEntityProvider.java +++ b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/providers/BackwardsBlockEntityProvider.java @@ -83,11 +83,11 @@ public class BackwardsBlockEntityProvider implements Provider { * @param id The block entity id */ public CompoundTag transform(UserConnection user, Position position, String id) throws Exception { - CompoundTag tag = new CompoundTag(""); - tag.put(new StringTag("id", id)); - tag.put(new IntTag("x", Math.toIntExact(position.getX()))); - tag.put(new IntTag("y", Math.toIntExact(position.getY()))); - tag.put(new IntTag("z", Math.toIntExact(position.getZ()))); + CompoundTag tag = new CompoundTag(); + tag.put("id", new StringTag(id)); + tag.put("x", new IntTag(Math.toIntExact(position.getX()))); + tag.put("y", new IntTag(Math.toIntExact(position.getY()))); + tag.put("z", new IntTag(Math.toIntExact(position.getZ()))); return this.transform(user, position, tag); } diff --git a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java index fa48fb78..fc8746f4 100644 --- a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java +++ b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java @@ -534,7 +534,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It if (tag != null && (display = tag.get("display")) != null) { ListTag lore = display.get("Lore"); if (lore != null) { - saveListTag(display, lore); + saveListTag(display, lore, "Lore"); for (Tag loreEntry : lore) { if (!(loreEntry instanceof StringTag)) continue; diff --git a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/chat/TagSerializer.java b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/chat/TagSerializer.java index 1478e5e6..c5cb415f 100644 --- a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/chat/TagSerializer.java +++ b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/chat/TagSerializer.java @@ -38,7 +38,7 @@ public class TagSerializer { */ public static JsonObject toJson(CompoundTag tag) { JsonObject object = new JsonObject(); - for (Map.Entry entry : tag.getValue().entrySet()) { + for (Map.Entry entry : tag.entrySet()) { object.add(entry.getKey(), toJson(entry.getValue())); } return object; diff --git a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java index 44b6a342..c700a421 100644 --- a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java +++ b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java @@ -30,6 +30,7 @@ import us.myles.viaversion.libs.opennbt.tag.builtin.Tag; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.UUID; public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.ItemRewriter { @@ -146,7 +147,7 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It } CompoundTag heightMaps = chunk.getHeightMap(); - for (Tag heightMapTag : heightMaps) { + for (Tag heightMapTag : heightMaps.values()) { LongArrayTag heightMap = (LongArrayTag) heightMapTag; int[] heightMapData = new int[256]; CompactArrayUtil.iterateCompactArrayWithPadding(9, heightMapData.length, heightMap.getValue(), (i, v) -> heightMapData[i] = v); @@ -270,7 +271,7 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It // Target -> target_uuid UUID targetUuid = UUIDIntArrayType.uuidFromIntArray((int[]) targetUuidTag.getValue()); - tag.put(new StringTag("target_uuid", targetUuid.toString())); + tag.put("target_uuid", new StringTag(targetUuid.toString())); } else if (id.equals("minecraft:skull")) { Tag skullOwnerTag = tag.remove("SkullOwner"); if (!(skullOwnerTag instanceof CompoundTag)) return; @@ -279,15 +280,15 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It Tag ownerUuidTag = skullOwnerCompoundTag.remove("Id"); if (ownerUuidTag instanceof IntArrayTag) { UUID ownerUuid = UUIDIntArrayType.uuidFromIntArray((int[]) ownerUuidTag.getValue()); - skullOwnerCompoundTag.put(new StringTag("Id", ownerUuid.toString())); + skullOwnerCompoundTag.put("Id", new StringTag(ownerUuid.toString())); } // SkullOwner -> Owner - CompoundTag ownerTag = new CompoundTag("Owner"); - for (Tag t : skullOwnerCompoundTag) { - ownerTag.put(t); + CompoundTag ownerTag = new CompoundTag(); + for (Map.Entry entry : skullOwnerCompoundTag) { + ownerTag.put(entry.getKey(), entry.getValue()); } - tag.put(ownerTag); + tag.put("Owner", ownerTag); } } @@ -311,7 +312,7 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It Tag idTag = ownerCompundTag.get("Id"); if (idTag instanceof IntArrayTag) { UUID ownerUuid = UUIDIntArrayType.uuidFromIntArray((int[]) idTag.getValue()); - ownerCompundTag.put(new StringTag("Id", ownerUuid.toString())); + ownerCompundTag.put("Id", new StringTag(ownerUuid.toString())); } } } @@ -336,7 +337,7 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It Tag idTag = ownerCompundTag.get("Id"); if (idTag instanceof StringTag) { UUID ownerUuid = UUID.fromString((String) idTag.getValue()); - ownerCompundTag.put(new IntArrayTag("Id", UUIDIntArrayType.uuidToIntArray(ownerUuid))); + ownerCompundTag.put("Id", new IntArrayTag(UUIDIntArrayType.uuidToIntArray(ownerUuid))); } } } diff --git a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java index 4f603c13..ce791d0c 100644 --- a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java +++ b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java @@ -89,7 +89,7 @@ public class BlockItemPackets1_16_2 extends nl.matsv.viabackwards.api.rewriters. IntTag y = blockEntity.get("y"); IntTag z = blockEntity.get("z"); if (x != null && y != null && z != null) { - handleBlockEntity(blockEntity, new Position(x.getValue(), y.getValue().shortValue(), z.getValue())); + handleBlockEntity(blockEntity, new Position(x.asInt(), y.asShort(), z.asInt())); } } }); @@ -169,7 +169,7 @@ public class BlockItemPackets1_16_2 extends nl.matsv.viabackwards.api.rewriters. // Make the client cache the skinprofile over this uuid int hashCode = first.get("Value").getValue().hashCode(); int[] uuidIntArray = {hashCode, 0, 0, 0}; //TODO split texture in 4 for a lower collision chance - skullOwnerCompoundTag.put(new IntArrayTag("Id", uuidIntArray)); + skullOwnerCompoundTag.put("Id", new IntArrayTag(uuidIntArray)); } } } diff --git a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java index 33eb616f..4f584f41 100644 --- a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java +++ b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java @@ -193,14 +193,14 @@ public class EntityPackets1_17 extends EntityRewriter { IntTag minY = tag.get("min_y"); IntTag height = tag.get("height"); IntTag logicalHeight = tag.get("logical_height"); - if (minY.getValue() != 0 || height.getValue() > 256 || logicalHeight.getValue() > 256) { + if (minY.asInt() != 0 || height.asInt() > 256 || logicalHeight.asInt() > 256) { if (warn) { ViaBackwards.getPlatform().getLogger().severe("Custom worlds heights are NOT SUPPORTED for 1.16 players and older and may lead to errors!"); - ViaBackwards.getPlatform().getLogger().severe("You have min/max set to " + minY.getValue() + "/" + height.getValue()); + ViaBackwards.getPlatform().getLogger().severe("You have min/max set to " + minY.asInt() + "/" + height.asInt()); } - height.setValue(Math.min(256, height.getValue())); - logicalHeight.setValue(Math.min(256, logicalHeight.getValue())); + height.setValue(Math.min(256, height.asInt())); + logicalHeight.setValue(Math.min(256, logicalHeight.asInt())); } } }