3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-10-03 08:51:05 +02:00

Update nbt usage

Dieser Commit ist enthalten in:
KennyTV 2021-03-14 18:24:37 +01:00
Ursprung 35ced30047
Commit 44ae5c8c1b
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
19 geänderte Dateien mit 187 neuen und 183 gelöschten Zeilen

Datei anzeigen

@ -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.protocols.protocol1_13to1_12_2.ChatRewriter;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; 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.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.ShortTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag; import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.Tag; import us.myles.viaversion.libs.opennbt.tag.builtin.Tag;
@ -77,42 +78,42 @@ public class EnchantmentRewriter {
if (remappedName != null) { if (remappedName != null) {
if (!changed) { if (!changed) {
// Backup original before doing modifications // Backup original before doing modifications
itemRewriter.saveListTag(tag, enchantments); itemRewriter.saveListTag(tag, enchantments, key);
changed = true; changed = true;
} }
iterator.remove(); iterator.remove();
Number level = (Number) enchantmentEntry.get("lvl").getValue(); int level = ((NumberTag) enchantmentEntry.get("lvl")).asInt();
String loreValue = remappedName + " " + getRomanNumber(level.intValue()); String loreValue = remappedName + " " + getRomanNumber(level);
if (jsonFormat) { if (jsonFormat) {
loreValue = ChatRewriter.legacyTextToJsonString(loreValue); loreValue = ChatRewriter.legacyTextToJsonString(loreValue);
} }
loreToAdd.add(new StringTag("", loreValue)); loreToAdd.add(new StringTag(loreValue));
} }
} }
if (!loreToAdd.isEmpty()) { if (!loreToAdd.isEmpty()) {
// Add dummy enchant for the glow effect if there are no actual enchantments left // Add dummy enchant for the glow effect if there are no actual enchantments left
if (!storedEnchant && enchantments.size() == 0) { if (!storedEnchant && enchantments.size() == 0) {
CompoundTag dummyEnchantment = new CompoundTag(""); CompoundTag dummyEnchantment = new CompoundTag();
dummyEnchantment.put(new StringTag("id", "")); dummyEnchantment.put("id", new StringTag());
dummyEnchantment.put(new ShortTag("lvl", (short) 0)); dummyEnchantment.put("lvl", new ShortTag((short) 0));
enchantments.add(dummyEnchantment); enchantments.add(dummyEnchantment);
} }
CompoundTag display = tag.get("display"); CompoundTag display = tag.get("display");
if (display == null) { if (display == null) {
tag.put(display = new CompoundTag("display")); tag.put("display", display = new CompoundTag());
} }
ListTag loreTag = display.get("Lore"); ListTag loreTag = display.get("Lore");
if (loreTag == null) { if (loreTag == null) {
display.put(loreTag = new ListTag("Lore", StringTag.class)); display.put("Lore", loreTag = new ListTag(StringTag.class));
} else { } else {
// Save original lore // Save original lore
itemRewriter.saveListTag(display, loreTag); itemRewriter.saveListTag(display, loreTag, "Lore");
} }
loreToAdd.addAll(loreTag.getValue()); loreToAdd.addAll(loreTag.getValue());

Datei anzeigen

@ -267,7 +267,7 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends Re
CompoundTag registryData = wrapper.get(Type.NBT, nbtIndex); CompoundTag registryData = wrapper.get(Type.NBT, nbtIndex);
Tag height = registryData.get("height"); Tag height = registryData.get("height");
if (height instanceof IntTag) { if (height instanceof IntTag) {
int blockHeight = ((IntTag) height).getValue(); int blockHeight = ((IntTag) height).asInt();
tracker.setCurrentWorldSectionHeight(blockHeight >> 4); tracker.setCurrentWorldSectionHeight(blockHeight >> 4);
} else { } else {
ViaBackwards.getPlatform().getLogger().warning("Height missing in dimension data: " + registryData); ViaBackwards.getPlatform().getLogger().warning("Height missing in dimension data: " + registryData);
@ -275,7 +275,7 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends Re
Tag minY = registryData.get("min_y"); Tag minY = registryData.get("min_y");
if (minY instanceof IntTag) { if (minY instanceof IntTag) {
tracker.setCurrentMinY(((IntTag) minY).getValue()); tracker.setCurrentMinY(((IntTag) minY).asInt());
} else { } else {
ViaBackwards.getPlatform().getLogger().warning("Min Y missing in dimension data: " + registryData); ViaBackwards.getPlatform().getLogger().warning("Min Y missing in dimension data: " + registryData);
} }

Datei anzeigen

@ -32,7 +32,7 @@ public abstract class ItemRewriter<T extends BackwardsProtocol> extends ItemRewr
if (name != null) { if (name != null) {
String newValue = translatableRewriter.processText(name.getValue()).toString(); String newValue = translatableRewriter.processText(name.getValue()).toString();
if (!newValue.equals(name.getValue())) { if (!newValue.equals(name.getValue())) {
saveStringTag(display, name); saveStringTag(display, name, "Name");
} }
name.setValue(newValue); name.setValue(newValue);
@ -49,7 +49,7 @@ public abstract class ItemRewriter<T extends BackwardsProtocol> extends ItemRewr
if (!changed && !newValue.equals(loreEntry.getValue())) { if (!changed && !newValue.equals(loreEntry.getValue())) {
// Backup original lore before doing any modifications // Backup original lore before doing any modifications
changed = true; changed = true;
saveListTag(display, lore); saveListTag(display, lore, "Lore");
} }
loreEntry.setValue(newValue); loreEntry.setValue(newValue);
@ -64,20 +64,20 @@ public abstract class ItemRewriter<T extends BackwardsProtocol> extends ItemRewr
} }
if (item.getTag() == null) { if (item.getTag() == null) {
item.setTag(new CompoundTag("")); item.setTag(new CompoundTag());
} }
// Save original id, set remapped id // 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()); item.setIdentifier(data.getId());
// Set custom name - only done if there is no original one // Set custom name - only done if there is no original one
if (display == null) { if (display == null) {
item.getTag().put(display = new CompoundTag("display")); item.getTag().put("display", display = new CompoundTag());
} }
if (!display.contains("Name")) { if (!display.contains("Name")) {
display.put(new StringTag("Name", data.getJsonName())); display.put("Name", new StringTag(data.getJsonName()));
display.put(new ByteTag(nbtTagName + "|customName")); display.put(nbtTagName + "|customName", new ByteTag());
} }
return item; return item;
} }
@ -91,7 +91,7 @@ public abstract class ItemRewriter<T extends BackwardsProtocol> extends ItemRewr
if (item.getTag() != null) { if (item.getTag() != null) {
IntTag originalId = item.getTag().remove(nbtTagName + "|id"); IntTag originalId = item.getTag().remove(nbtTagName + "|id");
if (originalId != null) { if (originalId != null) {
item.setIdentifier(originalId.getValue()); item.setIdentifier(originalId.asInt());
} }
} }
return item; return item;

Datei anzeigen

@ -42,25 +42,25 @@ public abstract class ItemRewriterBase<T extends BackwardsProtocol> extends Rewr
return displayTag.contains(nbtTagName + "|o" + tagName); 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 // Multiple places might try to backup data
String name = nbtTagName + "|o" + original.getName(); String backupName = nbtTagName + "|o" + name;
if (!displayTag.contains(name)) { if (!displayTag.contains(backupName)) {
displayTag.put(new StringTag(name, original.getValue())); 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 // Multiple places might try to backup data
String name = nbtTagName + "|o" + original.getName(); String backupName = nbtTagName + "|o" + name;
if (!displayTag.contains(name)) { if (!displayTag.contains(backupName)) {
// Clone all tag entries // Clone all tag entries
ListTag listTag = new ListTag(name); ListTag listTag = new ListTag();
for (Tag tag : original.getValue()) { for (Tag tag : original.getValue()) {
listTag.add(tag.clone()); listTag.add(tag.clone());
} }
displayTag.put(listTag); displayTag.put(backupName, listTag);
} }
} }
@ -84,14 +84,14 @@ public abstract class ItemRewriterBase<T extends BackwardsProtocol> extends Rewr
protected void restoreStringTag(CompoundTag tag, String tagName) { protected void restoreStringTag(CompoundTag tag, String tagName) {
StringTag original = tag.remove(nbtTagName + "|o" + tagName); StringTag original = tag.remove(nbtTagName + "|o" + tagName);
if (original != null) { if (original != null) {
tag.put(new StringTag(tagName, original.getValue())); tag.put(tagName, new StringTag(original.getValue()));
} }
} }
protected void restoreListTag(CompoundTag tag, String tagName) { protected void restoreListTag(CompoundTag tag, String tagName) {
ListTag original = tag.remove(nbtTagName + "|o" + tagName); ListTag original = tag.remove(nbtTagName + "|o" + tagName);
if (original != null) { if (original != null) {
tag.put(new ListTag(tagName, original.getValue())); tag.put(tagName, new ListTag(original.getValue()));
} }
} }

Datei anzeigen

@ -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.ByteTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; 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.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.StringTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.Tag; import us.myles.viaversion.libs.opennbt.tag.builtin.Tag;
@ -103,24 +104,24 @@ public abstract class LegacyBlockItemRewriter<T extends BackwardsProtocol> exten
// Set display name // Set display name
if (data.getName() != null) { if (data.getName() != null) {
if (item.getTag() == null) { if (item.getTag() == null) {
item.setTag(new CompoundTag("")); item.setTag(new CompoundTag());
} }
CompoundTag display = item.getTag().get("display"); CompoundTag display = item.getTag().get("display");
if (display == null) { if (display == null) {
item.getTag().put(display = new CompoundTag("display")); item.getTag().put("display", display = new CompoundTag());
} }
StringTag nameTag = display.get("Name"); StringTag nameTag = display.get("Name");
if (nameTag == null) { if (nameTag == null) {
display.put(nameTag = new StringTag("Name", data.getName())); display.put("Name", nameTag = new StringTag(data.getName()));
display.put(new ByteTag(nbtTagName + "|customName")); display.put(nbtTagName + "|customName", new ByteTag());
} }
// Handle colors // Handle colors
String value = nameTag.getValue(); String value = nameTag.getValue();
if (value.contains("%vb_color%")) { 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; return item;
@ -161,9 +162,9 @@ public abstract class LegacyBlockItemRewriter<T extends BackwardsProtocol> exten
} }
Pos pos = new Pos( Pos pos = new Pos(
(int) xTag.getValue() & 0xF, ((NumberTag) xTag).asInt() & 0xF,
(int) yTag.getValue(), ((NumberTag) yTag).asInt(),
(int) zTag.getValue() & 0xF); ((NumberTag) zTag).asInt() & 0xF);
tags.put(pos, tag); tags.put(pos, tag);
// Handle given Block Entities // Handle given Block Entities
@ -223,10 +224,10 @@ public abstract class LegacyBlockItemRewriter<T extends BackwardsProtocol> exten
// Already handled above // Already handled above
if (tags.containsKey(pos)) continue; if (tags.containsKey(pos)) continue;
CompoundTag tag = new CompoundTag(""); CompoundTag tag = new CompoundTag();
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)));
settings.getBlockEntityHandler().handleOrNewCompoundTag(block, tag); settings.getBlockEntityHandler().handleOrNewCompoundTag(block, tag);
chunk.getBlockEntities().add(tag); chunk.getBlockEntities().add(tag);
@ -237,10 +238,10 @@ public abstract class LegacyBlockItemRewriter<T extends BackwardsProtocol> exten
} }
protected CompoundTag getNamedTag(String text) { protected CompoundTag getNamedTag(String text) {
CompoundTag tag = new CompoundTag(""); CompoundTag tag = new CompoundTag();
tag.put(new CompoundTag("display")); tag.put("display", new CompoundTag());
text = "§r" + text; 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; return tag;
} }

Datei anzeigen

@ -21,55 +21,55 @@ public class LegacyEnchantmentRewriter {
public void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnchant) { public void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnchant) {
String key = storedEnchant ? "StoredEnchantments" : "ench"; String key = storedEnchant ? "StoredEnchantments" : "ench";
ListTag enchantments = tag.get(key); ListTag enchantments = tag.get(key);
ListTag remappedEnchantments = new ListTag(nbtTagName + "|" + key, CompoundTag.class); ListTag remappedEnchantments = new ListTag( CompoundTag.class);
List<Tag> lore = new ArrayList<>(); List<Tag> lore = new ArrayList<>();
for (Tag enchantmentEntry : enchantments.clone()) { for (Tag enchantmentEntry : enchantments.clone()) {
Tag idTag = ((CompoundTag) enchantmentEntry).get("id"); Tag idTag = ((CompoundTag) enchantmentEntry).get("id");
if (idTag == null) continue; if (idTag == null) continue;
short newId = ((Number) idTag.getValue()).shortValue(); short newId = ((NumberTag) idTag).asShort();
String enchantmentName = enchantmentMappings.get(newId); String enchantmentName = enchantmentMappings.get(newId);
if (enchantmentName != null) { if (enchantmentName != null) {
enchantments.remove(enchantmentEntry); 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)) { if (hideLevelForEnchants != null && hideLevelForEnchants.contains(newId)) {
lore.add(new StringTag("", enchantmentName)); lore.add(new StringTag(enchantmentName));
} else { } else {
lore.add(new StringTag("", enchantmentName + " " + EnchantmentRewriter.getRomanNumber(level.shortValue()))); lore.add(new StringTag(enchantmentName + " " + EnchantmentRewriter.getRomanNumber(level)));
} }
remappedEnchantments.add(enchantmentEntry); remappedEnchantments.add(enchantmentEntry);
} }
} }
if (!lore.isEmpty()) { if (!lore.isEmpty()) {
if (!storedEnchant && enchantments.size() == 0) { if (!storedEnchant && enchantments.size() == 0) {
CompoundTag dummyEnchantment = new CompoundTag(""); CompoundTag dummyEnchantment = new CompoundTag();
dummyEnchantment.put(new ShortTag("id", (short) 0)); dummyEnchantment.put("id", new ShortTag((short) 0));
dummyEnchantment.put(new ShortTag("lvl", (short) 0)); dummyEnchantment.put("lvl", new ShortTag((short) 0));
enchantments.add(dummyEnchantment); enchantments.add(dummyEnchantment);
tag.put(new ByteTag(nbtTagName + "|dummyEnchant")); tag.put(nbtTagName + "|dummyEnchant", new ByteTag());
IntTag hideFlags = tag.get("HideFlags"); IntTag hideFlags = tag.get("HideFlags");
if (hideFlags == null) { if (hideFlags == null) {
hideFlags = new IntTag("HideFlags"); hideFlags = new IntTag();
} else { } 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); hideFlags.setValue(flags);
tag.put(hideFlags); tag.put("HideFlags", hideFlags);
} }
tag.put(remappedEnchantments); tag.put(nbtTagName + "|" + key,remappedEnchantments);
CompoundTag display = tag.get("display"); CompoundTag display = tag.get("display");
if (display == null) { if (display == null) {
tag.put(display = new CompoundTag("display")); tag.put("display", display = new CompoundTag());
} }
ListTag loreTag = display.get("Lore"); ListTag loreTag = display.get("Lore");
if (loreTag == null) { if (loreTag == null) {
display.put(loreTag = new ListTag("Lore", StringTag.class)); display.put("Lore", loreTag = new ListTag(StringTag.class));
} }
lore.addAll(loreTag.getValue()); lore.addAll(loreTag.getValue());
@ -79,16 +79,16 @@ public class LegacyEnchantmentRewriter {
public void rewriteEnchantmentsToServer(CompoundTag tag, boolean storedEnchant) { public void rewriteEnchantmentsToServer(CompoundTag tag, boolean storedEnchant) {
String key = storedEnchant ? "StoredEnchantments" : "ench"; String key = storedEnchant ? "StoredEnchantments" : "ench";
ListTag remappedEnchantments = tag.get(nbtTagName + "|" + key); ListTag remappedEnchantments = tag.remove(nbtTagName + "|" + key);
ListTag enchantments = tag.get(key); ListTag enchantments = tag.get(key);
if (enchantments == null) { if (enchantments == null) {
enchantments = new ListTag(key, CompoundTag.class); enchantments = new ListTag(CompoundTag.class);
} }
if (!storedEnchant && tag.remove(nbtTagName + "|dummyEnchant") != null) { if (!storedEnchant && tag.remove(nbtTagName + "|dummyEnchant") != null) {
for (Tag enchantment : enchantments.clone()) { for (Tag enchantment : enchantments.clone()) {
Short id = (Short) ((CompoundTag) enchantment).get("id").getValue(); short id = ((NumberTag) ((CompoundTag) enchantment).get("id")).asShort();
Short level = (Short) ((CompoundTag) enchantment).get("lvl").getValue(); short level = ((NumberTag) ((CompoundTag) enchantment).get("lvl")).asShort();
if (id == 0 && level == 0) { if (id == 0 && level == 0) {
enchantments.remove(enchantment); enchantments.remove(enchantment);
} }
@ -96,7 +96,7 @@ public class LegacyEnchantmentRewriter {
IntTag hideFlags = tag.remove(nbtTagName + "|oldHideFlags"); IntTag hideFlags = tag.remove(nbtTagName + "|oldHideFlags");
if (hideFlags != null) { if (hideFlags != null) {
tag.put(new IntTag("HideFlags", hideFlags.getValue())); tag.put("HideFlags", new IntTag(hideFlags.asByte()));
} else { } else {
tag.remove("HideFlags"); tag.remove("HideFlags");
} }
@ -117,8 +117,8 @@ public class LegacyEnchantmentRewriter {
tag.remove("display"); tag.remove("display");
} }
} }
tag.put(enchantments);
tag.remove(remappedEnchantments.getName()); tag.put(key, enchantments);
} }
public void setHideLevelForEnchants(int... enchants) { public void setHideLevelForEnchants(int... enchants) {

Datei anzeigen

@ -33,6 +33,7 @@ import us.myles.viaversion.libs.opennbt.tag.builtin.LongArrayTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.Tag; import us.myles.viaversion.libs.opennbt.tag.builtin.Tag;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map;
public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<Protocol1_11_1To1_12> { public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<Protocol1_11_1To1_12> {
@ -260,9 +261,9 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<Protocol1_11_1
super.handleItemToClient(item); super.handleItemToClient(item);
if (item.getTag() != null) { if (item.getTag() != null) {
CompoundTag backupTag = new CompoundTag("Via|LongArrayTags"); CompoundTag backupTag = new CompoundTag();
if (handleNbtToClient(item.getTag(), backupTag)) { if (handleNbtToClient(item.getTag(), backupTag)) {
item.getTag().put(backupTag); item.getTag().put("Via|LongArrayTags", backupTag);
} }
} }
@ -272,16 +273,16 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<Protocol1_11_1
private boolean handleNbtToClient(CompoundTag compoundTag, CompoundTag backupTag) { private boolean handleNbtToClient(CompoundTag compoundTag, CompoundTag backupTag) {
// Long array tags were introduced in 1.12 - just remove them // Long array tags were introduced in 1.12 - just remove them
// Only save the removed tags instead of blindly copying the entire nbt again // Only save the removed tags instead of blindly copying the entire nbt again
Iterator<Tag> iterator = compoundTag.iterator(); Iterator<Map.Entry<String, Tag>> iterator = compoundTag.iterator();
boolean hasLongArrayTag = false; boolean hasLongArrayTag = false;
while (iterator.hasNext()) { while (iterator.hasNext()) {
Tag tag = iterator.next(); Map.Entry<String, Tag> entry = iterator.next();
if (tag instanceof CompoundTag) { if (entry.getValue() instanceof CompoundTag) {
CompoundTag nestedBackupTag = new CompoundTag(tag.getName()); CompoundTag nestedBackupTag = new CompoundTag();
backupTag.put(nestedBackupTag); backupTag.put(entry.getKey(), nestedBackupTag);
hasLongArrayTag |= handleNbtToClient((CompoundTag) tag, nestedBackupTag); hasLongArrayTag |= handleNbtToClient((CompoundTag) entry.getValue(), nestedBackupTag);
} else if (tag instanceof LongArrayTag) { } else if (entry.getValue() instanceof LongArrayTag) {
backupTag.put(fromLongArrayTag((LongArrayTag) tag)); backupTag.put(entry.getKey(), fromLongArrayTag((LongArrayTag) entry.getValue()));
iterator.remove(); iterator.remove();
hasLongArrayTag = true; hasLongArrayTag = true;
} }
@ -306,12 +307,12 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<Protocol1_11_1
private void handleNbtToServer(CompoundTag compoundTag, CompoundTag backupTag) { private void handleNbtToServer(CompoundTag compoundTag, CompoundTag backupTag) {
// Restore the removed long array tags // Restore the removed long array tags
for (Tag tag : backupTag) { for (Map.Entry<String, Tag> entry: backupTag) {
if (tag instanceof CompoundTag) { if (entry.getValue() instanceof CompoundTag) {
CompoundTag nestedTag = compoundTag.get(tag.getName()); CompoundTag nestedTag = compoundTag.get(entry.getKey());
handleNbtToServer(nestedTag, (CompoundTag) tag); handleNbtToServer(nestedTag, (CompoundTag) entry.getValue());
} else { } else {
compoundTag.put(fromIntArrayTag((IntArrayTag) tag)); compoundTag.put(entry.getKey(), fromIntArrayTag((IntArrayTag) entry.getValue()));
} }
} }
} }
@ -324,7 +325,7 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<Protocol1_11_1
intArray[i++] = (int) (l >> 32); intArray[i++] = (int) (l >> 32);
intArray[i++] = (int) l; intArray[i++] = (int) l;
} }
return new IntArrayTag(tag.getName(), intArray); return new IntArrayTag(intArray);
} }
private LongArrayTag fromIntArrayTag(IntArrayTag tag) { private LongArrayTag fromIntArrayTag(IntArrayTag tag) {
@ -333,6 +334,6 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<Protocol1_11_1
for (int i = 0, j = 0; i < intArray.length; i += 2, j++) { for (int i = 0, j = 0; i < intArray.length; i += 2, j++) {
longArray[j] = (long) intArray[i] << 32 | ((long) intArray[i + 1] & 0xFFFFFFFFL); longArray[j] = (long) intArray[i] << 32 | ((long) intArray[i + 1] & 0xFFFFFFFFL);
} }
return new LongArrayTag(tag.getName(), longArray); return new LongArrayTag(longArray);
} }
} }

Datei anzeigen

@ -30,12 +30,12 @@ public class BannerHandler implements BackwardsBlockEntityHandler {
// Normal banners // Normal banners
if (blockId >= BANNER_START && blockId <= BANNER_STOP) { if (blockId >= BANNER_START && blockId <= BANNER_STOP) {
int color = (blockId - BANNER_START) >> 4; int color = (blockId - BANNER_START) >> 4;
tag.put(new IntTag("Base", (15 - color))); tag.put("Base", new IntTag((15 - color)));
} }
// Wall banners // Wall banners
else if (blockId >= WALL_BANNER_START && blockId <= WALL_BANNER_STOP) { else if (blockId >= WALL_BANNER_START && blockId <= WALL_BANNER_STOP) {
int color = (blockId - WALL_BANNER_START) >> 2; int color = (blockId - WALL_BANNER_START) >> 2;
tag.put(new IntTag("Base", (15 - color))); tag.put("Base", new IntTag((15 - color)));
} else { } else {
ViaBackwards.getPlatform().getLogger().warning("Why does this block have the banner block entity? :(" + tag); 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; if (!(pattern instanceof CompoundTag)) continue;
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
} }
} }

Datei anzeigen

@ -22,7 +22,7 @@ public class BedHandler implements BackwardsBlockEntityProvider.BackwardsBlockEn
int offset = blockId - 748; int offset = blockId - 748;
int color = offset >> 4; int color = offset >> 4;
tag.put(new IntTag("color", color)); tag.put("color", new IntTag(color));
return tag; return tag;
} }

Datei anzeigen

@ -67,8 +67,8 @@ public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsB
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) { public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
Pair<String, Byte> item = getOrDefault(blockId); Pair<String, Byte> item = getOrDefault(blockId);
tag.put(new StringTag("Item", item.getKey())); tag.put("Item", new StringTag(item.getKey()));
tag.put(new IntTag("Data", item.getValue())); tag.put("Data", new IntTag(item.getValue()));
return tag; return tag;
} }

Datei anzeigen

@ -79,8 +79,8 @@ public class PistonHandler implements BackwardsBlockEntityProvider.BackwardsBloc
return tag; return tag;
} }
tag.put(new IntTag("blockId", id >> 4)); tag.put("blockId", new IntTag(id >> 4));
tag.put(new IntTag("blockData", id & 15)); tag.put("blockData", new IntTag(id & 15));
return tag; return tag;
} }
@ -93,9 +93,9 @@ public class PistonHandler implements BackwardsBlockEntityProvider.BackwardsBloc
if (properties == null) return name.getValue(); if (properties == null) return name.getValue();
StringJoiner joiner = new StringJoiner(",", name.getValue() + "[", "]"); StringJoiner joiner = new StringJoiner(",", name.getValue() + "[", "]");
for (Tag property : properties) { for (Map.Entry<String, Tag> entry : properties) {
if (!(property instanceof StringTag)) continue; if (!(entry.getValue() instanceof StringTag)) continue;
joiner.add(property.getName() + "=" + ((StringTag) property).getValue()); joiner.add(entry.getKey() + "=" + ((StringTag) entry.getValue()).getValue());
} }
return joiner.toString(); return joiner.toString();
} }

Datei anzeigen

@ -25,7 +25,7 @@ public class SkullHandler implements BackwardsBlockEntityHandler {
byte type = (byte) Math.floor(diff / 20f); byte type = (byte) Math.floor(diff / 20f);
// Set type // Set type
tag.put(new ByteTag("SkullType", type)); tag.put("SkullType", new ByteTag(type));
// Remove wall skulls // Remove wall skulls
if (pos < 4) { if (pos < 4) {
@ -33,7 +33,7 @@ public class SkullHandler implements BackwardsBlockEntityHandler {
} }
// Add rotation for normal skulls // 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; return tag;
} }

Datei anzeigen

@ -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.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.IntTag; 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.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.ShortTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag; import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.Tag; 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 // Ignore if we don't handle it
if (!provider.isHandled(id)) continue; 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]; ChunkSection section = chunk.getSections()[sectionIndex];
int x = (int) tag.get("x").getValue(); int x = ((NumberTag) tag.get("x")).asInt();
int y = (int) tag.get("y").getValue(); int y = ((NumberTag) tag.get("y")).asInt();
int z = (int) tag.get("z").getValue(); int z = ((NumberTag) tag.get("z")).asInt();
Position position = new Position(x, (short) y, z); Position position = new Position(x, (short) y, z);
int block = section.getFlatBlock(x & 0xF, y & 0xF, z & 0xF); 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 // Use tag to get original ID and data
Tag originalIdTag; Tag originalIdTag;
if (tag != null && (originalIdTag = tag.remove(extraNbtTag)) != null) { if (tag != null && (originalIdTag = tag.remove(extraNbtTag)) != null) {
rawId = (Integer) originalIdTag.getValue(); rawId = ((NumberTag) originalIdTag).asInt();
gotRawIdFromTag = true; gotRawIdFromTag = true;
} }
@ -575,7 +576,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
if (display != null) { if (display != null) {
StringTag name = display.get("Name"); StringTag name = display.get("Name");
if (name != null) { 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())); name.setValue(ChatRewriter.jsonToLegacyText(name.getValue()));
} }
} }
@ -594,12 +595,12 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
Optional<String> eggEntityId = SpawnEggRewriter.getEntityId(oldId); Optional<String> eggEntityId = SpawnEggRewriter.getEntityId(oldId);
if (eggEntityId.isPresent()) { if (eggEntityId.isPresent()) {
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);
} }
return 0x17f0000; // 383 << 16; return 0x17f0000; // 383 << 16;
} }
@ -613,21 +614,21 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
ListTag blockTag = tag.get(tagName); ListTag blockTag = tag.get(tagName);
if (blockTag == null) return; if (blockTag == null) return;
ListTag newCanPlaceOn = new ListTag(tagName, StringTag.class); ListTag newCanPlaceOn = new ListTag(StringTag.class);
tag.put(ConverterRegistry.convertToTag(extraNbtTag + "|" + tagName, ConverterRegistry.convertToValue(blockTag))); tag.put(extraNbtTag + "|" + tagName, ConverterRegistry.convertToTag(ConverterRegistry.convertToValue(blockTag)));
for (Tag oldTag : blockTag) { for (Tag oldTag : blockTag) {
Object value = oldTag.getValue(); Object value = oldTag.getValue();
String[] newValues = value instanceof String ? String[] newValues = value instanceof String ?
BlockIdData.fallbackReverseMapping.get(((String) value).replace("minecraft:", "")) : null; BlockIdData.fallbackReverseMapping.get(((String) value).replace("minecraft:", "")) : 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(tagName, newCanPlaceOn);
} }
//TODO un-ugly all of this //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); ListTag enchantments = tag.get(key);
if (enchantments == null) return; if (enchantments == null) return;
ListTag noMapped = new ListTag(extraNbtTag + "|" + key, CompoundTag.class); ListTag noMapped = new ListTag(CompoundTag.class);
ListTag newEnchantments = new ListTag(storedEnch ? key : "ench", CompoundTag.class); ListTag newEnchantments = new ListTag(CompoundTag.class);
List<Tag> lore = new ArrayList<>(); List<Tag> lore = new ArrayList<>();
boolean hasValidEnchants = false; boolean hasValidEnchants = false;
for (Tag enchantmentEntryTag : enchantments.clone()) { 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; if (!(idTag instanceof StringTag)) continue;
String newId = (String) idTag.getValue(); String newId = (String) idTag.getValue();
Number levelValue = (Number) enchantmentEntry.get("lvl").getValue(); int levelValue = ((NumberTag) enchantmentEntry.get("lvl")).asInt();
int intValue = levelValue.intValue(); short level = levelValue < Short.MAX_VALUE ? (short) levelValue : Short.MAX_VALUE;
short level = intValue < Short.MAX_VALUE ? levelValue.shortValue() : Short.MAX_VALUE;
String mappedEnchantmentId = enchantmentMappings.get(newId); String mappedEnchantmentId = enchantmentMappings.get(newId);
if (mappedEnchantmentId != null) { if (mappedEnchantmentId != null) {
lore.add(new StringTag("", mappedEnchantmentId + " " + EnchantmentRewriter.getRomanNumber(level))); lore.add(new StringTag(mappedEnchantmentId + " " + EnchantmentRewriter.getRomanNumber(level)));
noMapped.add(enchantmentEntry); noMapped.add(enchantmentEntry);
} else if (!newId.isEmpty()) { } else if (!newId.isEmpty()) {
Short oldId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().inverse().get(newId); 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); 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()) { if (Via.getManager().isDebug()) {
@ -686,9 +686,9 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
hasValidEnchants = true; hasValidEnchants = true;
} }
CompoundTag newEntry = new CompoundTag(""); CompoundTag newEntry = new CompoundTag();
newEntry.put(new ShortTag("id", oldId)); newEntry.put("id", new ShortTag(oldId));
newEntry.put(new ShortTag("lvl", level)); newEntry.put("lvl", new ShortTag(level));
newEnchantments.add(newEntry); newEnchantments.add(newEntry);
} }
} }
@ -697,43 +697,43 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
if (!storedEnch && !hasValidEnchants) { if (!storedEnch && !hasValidEnchants) {
IntTag hideFlags = tag.get("HideFlags"); IntTag hideFlags = tag.get("HideFlags");
if (hideFlags == null) { if (hideFlags == null) {
hideFlags = new IntTag("HideFlags"); hideFlags = new IntTag();
tag.put(new ByteTag(extraNbtTag + "|DummyEnchant")); tag.put(extraNbtTag + "|DummyEnchant", new ByteTag());
} else { } else {
tag.put(new IntTag(extraNbtTag + "|OldHideFlags", hideFlags.getValue())); tag.put(extraNbtTag + "|OldHideFlags", new IntTag(hideFlags.asByte()));
} }
if (newEnchantments.size() == 0) { if (newEnchantments.size() == 0) {
CompoundTag enchEntry = new CompoundTag(""); CompoundTag enchEntry = new CompoundTag();
enchEntry.put(new ShortTag("id", (short) 0)); enchEntry.put("id", new ShortTag((short) 0));
enchEntry.put(new ShortTag("lvl", (short) 0)); enchEntry.put("lvl", new ShortTag((short) 0));
newEnchantments.add(enchEntry); newEnchantments.add(enchEntry);
} }
int value = hideFlags.getValue() | 1; int value = hideFlags.asByte() | 1;
hideFlags.setValue(value); hideFlags.setValue(value);
tag.put(hideFlags); tag.put("HideFlags", hideFlags);
} }
if (noMapped.size() != 0) { if (noMapped.size() != 0) {
tag.put(noMapped); tag.put(extraNbtTag + "|" + key, noMapped);
if (!lore.isEmpty()) { if (!lore.isEmpty()) {
CompoundTag display = tag.get("display"); CompoundTag display = tag.get("display");
if (display == null) { if (display == null) {
tag.put(display = new CompoundTag("display")); tag.put("display", display = new CompoundTag());
} }
ListTag loreTag = display.get("Lore"); ListTag loreTag = display.get("Lore");
if (loreTag == null) { if (loreTag == null) {
display.put(loreTag = new ListTag("Lore", StringTag.class)); display.put("Lore", loreTag = new ListTag(StringTag.class));
tag.put(new ByteTag(extraNbtTag + "|DummyLore")); tag.put(extraNbtTag + "|DummyLore", new ByteTag());
} else if (loreTag.size() != 0) { } else if (loreTag.size() != 0) {
ListTag oldLore = new ListTag(extraNbtTag + "|OldLore", StringTag.class); ListTag oldLore = new ListTag(StringTag.class);
for (Tag value : loreTag) { for (Tag value : loreTag) {
oldLore.add(value.clone()); oldLore.add(value.clone());
} }
tag.put(oldLore); tag.put(extraNbtTag + "|OldLore", oldLore);
lore.addAll(loreTag.getValue()); lore.addAll(loreTag.getValue());
} }
@ -743,7 +743,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
} }
tag.remove("Enchantments"); tag.remove("Enchantments");
tag.put(newEnchantments); tag.put(storedEnch ? key : "ench", newEnchantments);
} }
@Override @Override
@ -758,12 +758,12 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
// 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
@ -827,8 +827,8 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
int newId = -1; int newId = -1;
if (!protocol.getMappingData().getItemMappings().inverse().containsKey(rawId)) { if (!protocol.getMappingData().getItemMappings().inverse().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(extraNbtTag, originalId)); // Data will be lost, saving original id tag.put(extraNbtTag, new IntTag(originalId)); // Data will be lost, saving original id
} }
if (item.getIdentifier() == 229) { // purple shulker box 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; if (!(tag.get(tagName) instanceof ListTag)) return;
ListTag blockTag = tag.remove(extraNbtTag + "|" + tagName); ListTag blockTag = tag.remove(extraNbtTag + "|" + tagName);
if (blockTag != null) { 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) { } else if ((blockTag = tag.get(tagName)) != null) {
ListTag newCanPlaceOn = new ListTag(tagName, StringTag.class); ListTag newCanPlaceOn = new ListTag(StringTag.class);
for (Tag oldTag : blockTag) { for (Tag oldTag : blockTag) {
Object value = oldTag.getValue(); Object value = oldTag.getValue();
String oldId = value.toString().replace("minecraft:", ""); 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); String[] newValues = BlockIdData.blockIdMapping.get(lowerCaseId);
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("", 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"); ListTag enchantments = tag.get(storedEnch ? key : "ench");
if (enchantments == null) return; if (enchantments == null) return;
ListTag newEnchantments = new ListTag(key, CompoundTag.class); ListTag newEnchantments = new ListTag(CompoundTag.class);
boolean dummyEnchant = false; boolean dummyEnchant = false;
if (!storedEnch) { if (!storedEnch) {
IntTag hideFlags = tag.remove(extraNbtTag + "|OldHideFlags"); IntTag hideFlags = tag.remove(extraNbtTag + "|OldHideFlags");
if (hideFlags != null) { if (hideFlags != null) {
tag.put(new IntTag("HideFlags", hideFlags.getValue())); tag.put("HideFlags", new IntTag(hideFlags.asByte()));
dummyEnchant = true; dummyEnchant = true;
} else if (tag.remove(extraNbtTag + "|DummyEnchant") != null) { } else if (tag.remove(extraNbtTag + "|DummyEnchant") != null) {
tag.remove("HideFlags"); tag.remove("HideFlags");
@ -903,9 +903,9 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
} }
for (Tag enchEntry : enchantments) { for (Tag enchEntry : enchantments) {
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();
short level = ((Number) ((CompoundTag) enchEntry).get("lvl").getValue()).shortValue(); short level = ((NumberTag) ((CompoundTag) enchEntry).get("lvl")).asShort();
if (dummyEnchant && oldId == 0 && level == 0) { if (dummyEnchant && oldId == 0 && level == 0) {
continue; //Skip dummy enchatment continue; //Skip dummy enchatment
} }
@ -913,9 +913,9 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
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", level)); enchantmentEntry.put("lvl", new ShortTag(level));
newEnchantments.add(enchantmentEntry); newEnchantments.add(enchantmentEntry);
} }
@ -928,14 +928,14 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
CompoundTag display = tag.get("display"); CompoundTag display = tag.get("display");
if (display == null) { if (display == null) {
tag.put(display = new CompoundTag("display")); tag.put("display", display = new CompoundTag());
} }
ListTag oldLore = tag.remove(extraNbtTag + "|OldLore"); ListTag oldLore = tag.remove(extraNbtTag + "|OldLore");
if (oldLore != null) { if (oldLore != null) {
ListTag lore = display.get("Lore"); ListTag lore = display.get("Lore");
if (lore == null) { if (lore == null) {
tag.put(lore = new ListTag("Lore")); tag.put("Lore", lore = new ListTag());
} }
lore.setValue(oldLore.getValue()); lore.setValue(oldLore.getValue());
@ -949,7 +949,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
if (!storedEnch) { if (!storedEnch) {
tag.remove("ench"); tag.remove("ench");
} }
tag.put(newEnchantments); tag.put(key, newEnchantments);
} }
private void invertShieldAndBannerId(Item item, CompoundTag tag) { 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"); Tag base = blockEntityCompoundTag.get("Base");
if (base instanceof IntTag) { if (base instanceof IntTag) {
IntTag baseTag = (IntTag) base; 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"); 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; if (!(pattern instanceof CompoundTag)) continue;
IntTag colorTag = ((CompoundTag) pattern).get("Color"); IntTag colorTag = ((CompoundTag) pattern).get("Color");
colorTag.setValue(15 - colorTag.getValue()); // Invert color id colorTag.setValue(15 - colorTag.asInt()); // Invert color id
} }
} }
} }

Datei anzeigen

@ -83,11 +83,11 @@ public class BackwardsBlockEntityProvider implements Provider {
* @param id The block entity id * @param id The block entity id
*/ */
public CompoundTag transform(UserConnection user, Position position, String id) throws Exception { public CompoundTag transform(UserConnection user, Position position, String id) throws Exception {
CompoundTag tag = new CompoundTag(""); CompoundTag tag = new CompoundTag();
tag.put(new StringTag("id", id)); tag.put("id", new StringTag(id));
tag.put(new IntTag("x", Math.toIntExact(position.getX()))); tag.put("x", new IntTag(Math.toIntExact(position.getX())));
tag.put(new IntTag("y", Math.toIntExact(position.getY()))); tag.put("y", new IntTag(Math.toIntExact(position.getY())));
tag.put(new IntTag("z", Math.toIntExact(position.getZ()))); tag.put("z", new IntTag(Math.toIntExact(position.getZ())));
return this.transform(user, position, tag); return this.transform(user, position, tag);
} }

Datei anzeigen

@ -534,7 +534,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
if (tag != null && (display = tag.get("display")) != null) { if (tag != null && (display = tag.get("display")) != null) {
ListTag lore = display.get("Lore"); ListTag lore = display.get("Lore");
if (lore != null) { if (lore != null) {
saveListTag(display, lore); saveListTag(display, lore, "Lore");
for (Tag loreEntry : lore) { for (Tag loreEntry : lore) {
if (!(loreEntry instanceof StringTag)) continue; if (!(loreEntry instanceof StringTag)) continue;

Datei anzeigen

@ -38,7 +38,7 @@ public class TagSerializer {
*/ */
public static JsonObject toJson(CompoundTag tag) { public static JsonObject toJson(CompoundTag tag) {
JsonObject object = new JsonObject(); JsonObject object = new JsonObject();
for (Map.Entry<String, Tag> entry : tag.getValue().entrySet()) { for (Map.Entry<String, Tag> entry : tag.entrySet()) {
object.add(entry.getKey(), toJson(entry.getValue())); object.add(entry.getKey(), toJson(entry.getValue()));
} }
return object; return object;

Datei anzeigen

@ -30,6 +30,7 @@ import us.myles.viaversion.libs.opennbt.tag.builtin.Tag;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.ItemRewriter<Protocol1_15_2To1_16> { public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.ItemRewriter<Protocol1_15_2To1_16> {
@ -146,7 +147,7 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It
} }
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.iterateCompactArrayWithPadding(9, heightMapData.length, heightMap.getValue(), (i, v) -> heightMapData[i] = v); 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 // Target -> target_uuid
UUID targetUuid = UUIDIntArrayType.uuidFromIntArray((int[]) targetUuidTag.getValue()); 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")) { } else if (id.equals("minecraft:skull")) {
Tag skullOwnerTag = tag.remove("SkullOwner"); Tag skullOwnerTag = tag.remove("SkullOwner");
if (!(skullOwnerTag instanceof CompoundTag)) return; 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"); Tag ownerUuidTag = skullOwnerCompoundTag.remove("Id");
if (ownerUuidTag instanceof IntArrayTag) { if (ownerUuidTag instanceof IntArrayTag) {
UUID ownerUuid = UUIDIntArrayType.uuidFromIntArray((int[]) ownerUuidTag.getValue()); UUID ownerUuid = UUIDIntArrayType.uuidFromIntArray((int[]) ownerUuidTag.getValue());
skullOwnerCompoundTag.put(new StringTag("Id", ownerUuid.toString())); skullOwnerCompoundTag.put("Id", new StringTag(ownerUuid.toString()));
} }
// SkullOwner -> Owner // SkullOwner -> Owner
CompoundTag ownerTag = new CompoundTag("Owner"); CompoundTag ownerTag = new CompoundTag();
for (Tag t : skullOwnerCompoundTag) { for (Map.Entry<String, Tag> entry : skullOwnerCompoundTag) {
ownerTag.put(t); 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"); Tag idTag = ownerCompundTag.get("Id");
if (idTag instanceof IntArrayTag) { if (idTag instanceof IntArrayTag) {
UUID ownerUuid = UUIDIntArrayType.uuidFromIntArray((int[]) idTag.getValue()); 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"); Tag idTag = ownerCompundTag.get("Id");
if (idTag instanceof StringTag) { if (idTag instanceof StringTag) {
UUID ownerUuid = UUID.fromString((String) idTag.getValue()); UUID ownerUuid = UUID.fromString((String) idTag.getValue());
ownerCompundTag.put(new IntArrayTag("Id", UUIDIntArrayType.uuidToIntArray(ownerUuid))); ownerCompundTag.put("Id", new IntArrayTag(UUIDIntArrayType.uuidToIntArray(ownerUuid)));
} }
} }
} }

Datei anzeigen

@ -89,7 +89,7 @@ public class BlockItemPackets1_16_2 extends nl.matsv.viabackwards.api.rewriters.
IntTag y = blockEntity.get("y"); IntTag y = blockEntity.get("y");
IntTag z = blockEntity.get("z"); IntTag z = blockEntity.get("z");
if (x != null && y != null && z != null) { 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 // Make the client cache the skinprofile over this uuid
int hashCode = first.get("Value").getValue().hashCode(); int hashCode = first.get("Value").getValue().hashCode();
int[] uuidIntArray = {hashCode, 0, 0, 0}; //TODO split texture in 4 for a lower collision chance 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));
} }
} }
} }

Datei anzeigen

@ -193,14 +193,14 @@ public class EntityPackets1_17 extends EntityRewriter<Protocol1_16_4To1_17> {
IntTag minY = tag.get("min_y"); IntTag minY = tag.get("min_y");
IntTag height = tag.get("height"); IntTag height = tag.get("height");
IntTag logicalHeight = tag.get("logical_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) { 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("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())); height.setValue(Math.min(256, height.asInt()));
logicalHeight.setValue(Math.min(256, logicalHeight.getValue())); logicalHeight.setValue(Math.min(256, logicalHeight.asInt()));
} }
} }
} }