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

Some minor optimizations

Dieser Commit ist enthalten in:
KennyTV 2020-06-03 11:20:17 +02:00
Ursprung e25abe57e0
Commit 5988ab4c19
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
11 geänderte Dateien mit 100 neuen und 77 gelöschten Zeilen

Datei anzeigen

@ -106,7 +106,11 @@ public class EnchantmentRewriter {
public void rewriteEnchantmentsToServer(CompoundTag tag, boolean storedEnchant) { public void rewriteEnchantmentsToServer(CompoundTag tag, boolean storedEnchant) {
String key = storedEnchant ? "StoredEnchantments" : "Enchantments"; String key = storedEnchant ? "StoredEnchantments" : "Enchantments";
ListTag remappedEnchantments = tag.get(nbtTagName + "|" + key); ListTag remappedEnchantments = tag.get(nbtTagName + "|" + key);
ListTag enchantments = tag.contains(key) ? tag.get(key) : new ListTag(key, CompoundTag.class); ListTag enchantments = tag.get(key);
if (enchantments == null) {
enchantments = new ListTag(key, CompoundTag.class);
}
if (!storedEnchant && tag.contains(nbtTagName + "|dummyEnchant")) { if (!storedEnchant && tag.contains(nbtTagName + "|dummyEnchant")) {
tag.remove(nbtTagName + "|dummyEnchant"); tag.remove(nbtTagName + "|dummyEnchant");

Datei anzeigen

@ -7,6 +7,7 @@ import us.myles.viaversion.libs.opennbt.conversion.builtin.CompoundTagConverter;
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.ShortTag; import us.myles.viaversion.libs.opennbt.tag.builtin.ShortTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.Tag;
public abstract class ItemRewriterBase<T extends BackwardsProtocol> extends Rewriter<T> { public abstract class ItemRewriterBase<T extends BackwardsProtocol> extends Rewriter<T> {
@ -21,7 +22,7 @@ public abstract class ItemRewriterBase<T extends BackwardsProtocol> extends Rewr
this.toClientRewriter = toClientRewriter; this.toClientRewriter = toClientRewriter;
this.toServerRewriter = toServerRewriter; this.toServerRewriter = toServerRewriter;
this.jsonNameFormat = jsonNameFormat; this.jsonNameFormat = jsonNameFormat;
nbtTagName = "ViaBackwards|" + protocol.getClass().getSimpleName(); nbtTagName = "VB|" + protocol.getClass().getSimpleName();
} }
protected ItemRewriterBase(T protocol, boolean jsonNameFormat) { protected ItemRewriterBase(T protocol, boolean jsonNameFormat) {
@ -47,21 +48,23 @@ public abstract class ItemRewriterBase<T extends BackwardsProtocol> extends Rewr
return item; return item;
} }
CompoundTag viaTag = tag.get(nbtTagName); CompoundTag viaTag = tag.remove(nbtTagName);
if (viaTag != null) { if (viaTag != null) {
short id = (short) viaTag.get("id").getValue(); short id = (short) viaTag.get("id").getValue();
short data = (short) viaTag.get("data").getValue();
byte amount = (byte) viaTag.get("amount").getValue();
CompoundTag extras = viaTag.get("extras");
item.setIdentifier(id); item.setIdentifier(id);
Tag dataTag = viaTag.get("data");
short data = dataTag != null ? (short) dataTag.getValue() : 0;
item.setData(data); item.setData(data);
Tag amountTag = viaTag.get("amount");
byte amount = amountTag != null ? (byte) amountTag.getValue() : 1;
item.setAmount(amount); item.setAmount(amount);
CompoundTag extras = viaTag.get("extras");
if (extras != null) { if (extras != null) {
item.setTag(CONVERTER.convert("", CONVERTER.convert(extras))); item.setTag(CONVERTER.convert("", CONVERTER.convert(extras)));
} }
// Remove data tag
tag.remove(nbtTagName);
} else { } else {
// Rewrite id normally // Rewrite id normally
if (toServerRewriter != null) { if (toServerRewriter != null) {
@ -74,8 +77,12 @@ public abstract class ItemRewriterBase<T extends BackwardsProtocol> extends Rewr
protected CompoundTag createViaNBT(Item item) { protected CompoundTag createViaNBT(Item item) {
CompoundTag tag = new CompoundTag(nbtTagName); CompoundTag tag = new CompoundTag(nbtTagName);
tag.put(new ShortTag("id", (short) item.getIdentifier())); tag.put(new ShortTag("id", (short) item.getIdentifier()));
tag.put(new ShortTag("data", item.getData())); if (item.getAmount() != 1) {
tag.put(new ByteTag("amount", item.getAmount())); tag.put(new ByteTag("amount", item.getAmount()));
}
if (item.getData() != 0) {
tag.put(new ShortTag("data", item.getData()));
}
if (item.getTag() != null) { if (item.getTag() != null) {
tag.put(CONVERTER.convert("extras", CONVERTER.convert(item.getTag()))); tag.put(CONVERTER.convert("extras", CONVERTER.convert(item.getTag())));
} }

Datei anzeigen

@ -27,6 +27,7 @@ import us.myles.viaversion.libs.gson.JsonPrimitive;
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.StringTag; import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.Tag;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -50,7 +51,7 @@ public abstract class LegacyBlockItemRewriter<T extends BackwardsProtocol> exten
JsonPrimitive blockField = object.getAsJsonPrimitive("block"); JsonPrimitive blockField = object.getAsJsonPrimitive("block");
boolean block = blockField != null && blockField.getAsBoolean(); boolean block = blockField != null && blockField.getAsBoolean();
if (dataEntry.getKey().contains("-")) { if (dataEntry.getKey().indexOf('-') != -1) {
// Range of ids // Range of ids
String[] split = dataEntry.getKey().split("-", 2); String[] split = dataEntry.getKey().split("-", 2);
int from = Integer.parseInt(split[0]); int from = Integer.parseInt(split[0]);
@ -153,17 +154,23 @@ public abstract class LegacyBlockItemRewriter<T extends BackwardsProtocol> exten
// Map Block Entities // Map Block Entities
Map<Pos, CompoundTag> tags = new HashMap<>(); Map<Pos, CompoundTag> tags = new HashMap<>();
for (CompoundTag tag : chunk.getBlockEntities()) { for (CompoundTag tag : chunk.getBlockEntities()) {
if (!(tag.contains("x") && tag.contains("y") && tag.contains("z"))) Tag xTag;
Tag yTag;
Tag zTag;
if ((xTag = tag.get("x")) == null || (yTag = tag.get("y")) == null || (zTag = tag.get("z")) == null) {
continue; continue;
}
Pos pos = new Pos( Pos pos = new Pos(
(int) tag.get("x").getValue() & 0xF, (int) xTag.getValue() & 0xF,
(int) tag.get("y").getValue(), (int) yTag.getValue(),
(int) tag.get("z").getValue() & 0xF); (int) zTag.getValue() & 0xF);
tags.put(pos, tag); tags.put(pos, tag);
// Handle given Block Entities // Handle given Block Entities
ChunkSection section = chunk.getSections()[pos.getY() >> 4]; ChunkSection section = chunk.getSections()[pos.getY() >> 4];
if (section == null) continue; if (section == null) continue;
int block = section.getFlatBlock(pos.getX(), pos.getY() & 0xF, pos.getZ()); int block = section.getFlatBlock(pos.getX(), pos.getY() & 0xF, pos.getZ());
int btype = block >> 4; int btype = block >> 4;

Datei anzeigen

@ -77,10 +77,12 @@ 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.get(nbtTagName + "|" + key);
ListTag enchantments = tag.contains(key) ? tag.get(key) : new ListTag(key, CompoundTag.class); ListTag enchantments = tag.get(key);
if (!storedEnchant && tag.contains(nbtTagName + "|dummyEnchant")) { if (enchantments == null) {
tag.remove(nbtTagName + "|dummyEnchant"); enchantments = new ListTag(key, CompoundTag.class);
}
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 = (Short) ((CompoundTag) enchantment).get("id").getValue();
Short level = (Short) ((CompoundTag) enchantment).get("lvl").getValue(); Short level = (Short) ((CompoundTag) enchantment).get("lvl").getValue();

Datei anzeigen

@ -36,6 +36,7 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
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.StringTag; import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.Tag;
import java.util.Arrays; import java.util.Arrays;
import java.util.Optional; import java.util.Optional;
@ -198,14 +199,15 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
handleChunk(chunk); handleChunk(chunk);
// only patch it for signs for now, TODO-> Find all the block entities old/new to replace ids and implement in ViaVersion // only patch it for signs for now, TODO-> Find all the block entities old/new to replace ids and implement in ViaVersion
chunk.getBlockEntities().stream() for (CompoundTag tag : chunk.getBlockEntities()) {
.filter(tag -> tag.contains("id") && tag.get("id") instanceof StringTag) Tag idTag = tag.get("id");
.forEach(tag -> { if (!(idTag instanceof StringTag)) continue;
String id = (String) tag.get("id").getValue();
if (id.equals("minecraft:sign")) { String id = (String) idTag.getValue();
((StringTag) tag.get("id")).setValue("Sign"); if (id.equals("minecraft:sign")) {
} ((StringTag) idTag).setValue("Sign");
}); }
}
} }
}); });
} }

Datei anzeigen

@ -41,12 +41,13 @@ public class BannerHandler implements BackwardsBlockEntityHandler {
} }
// Invert colors // Invert colors
if (tag.contains("Patterns") && tag.get("Patterns") instanceof ListTag) { Tag patternsTag = tag.get("Patterns");
for (Tag pattern : (ListTag) tag.get("Patterns")) { if (patternsTag instanceof ListTag) {
if (pattern instanceof CompoundTag) { for (Tag pattern : (ListTag) patternsTag) {
IntTag c = ((CompoundTag) pattern).get("Color"); if (!(pattern instanceof CompoundTag)) continue;
c.setValue(15 - c.getValue()); // Invert color id
} IntTag c = ((CompoundTag) pattern).get("Color");
c.setValue(15 - c.getValue()); // Invert color id
} }
} }

Datei anzeigen

@ -55,7 +55,7 @@ public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsB
} }
public static boolean isFlowah(int id) { public static boolean isFlowah(int id) {
return flowers.containsKey(id); return id >= 5265 && id <= 5286;
} }
public Pair<String, Byte> getOrDefault(int blockId) { public Pair<String, Byte> getOrDefault(int blockId) {

Datei anzeigen

@ -72,12 +72,12 @@ public class PistonHandler implements BackwardsBlockEntityProvider.BackwardsBloc
String dataFromTag = getDataFromTag(blockState); String dataFromTag = getDataFromTag(blockState);
if (dataFromTag == null) return tag; if (dataFromTag == null) return tag;
if (!pistonIds.containsKey(dataFromTag)) { Integer id = pistonIds.get(dataFromTag);
if (id == null) {
ViaBackwards.getPlatform().getLogger().warning("Unmapped piston id: " + dataFromTag); ViaBackwards.getPlatform().getLogger().warning("Unmapped piston id: " + dataFromTag);
return tag; return tag;
} }
int id = pistonIds.get(dataFromTag);
tag.put(new IntTag("blockId", id >> 4)); tag.put(new IntTag("blockId", id >> 4));
tag.put(new IntTag("blockData", id & 15)); tag.put(new IntTag("blockData", id & 15));
return tag; return tag;

Datei anzeigen

@ -15,18 +15,21 @@ import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBl
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
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.StringTag; import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.Tag;
public class SpawnerHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler { public class SpawnerHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {
@Override @Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) { public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
if (tag.contains("SpawnData") && tag.get("SpawnData") instanceof CompoundTag) { Tag dataTag = tag.get("SpawnData");
CompoundTag data = tag.get("SpawnData"); if (dataTag instanceof CompoundTag) {
if (data.contains("id") && data.get("id") instanceof StringTag) { CompoundTag data = (CompoundTag) dataTag;
StringTag s = data.get("id"); Tag idTag = data.get("id");
if (idTag instanceof StringTag) {
StringTag s = (StringTag) idTag;
s.setValue(EntityNameRewrites.rewrite(s.getValue())); s.setValue(EntityNameRewrites.rewrite(s.getValue()));
} }
} }
return tag; return tag;
} }
} }

Datei anzeigen

@ -63,8 +63,9 @@ public class BackwardsMappings {
short hardId = -1; short hardId = -1;
if (value == null) { if (value == null) {
JsonPrimitive replacement = mapping.getAsJsonPrimitive(key); JsonPrimitive replacement = mapping.getAsJsonPrimitive(key);
if (replacement == null && key.contains("[")) { int propertyIndex;
replacement = mapping.getAsJsonPrimitive(key.substring(0, key.indexOf('['))); if (replacement == null && (propertyIndex = key.indexOf('[')) != -1) {
replacement = mapping.getAsJsonPrimitive(key.substring(0, propertyIndex));
} }
if (replacement != null) { if (replacement != null) {
if (replacement.getAsString().startsWith("id:")) { if (replacement.getAsString().startsWith("id:")) {

Datei anzeigen

@ -57,11 +57,11 @@ import java.util.Optional;
public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.ItemRewriter<Protocol1_12_2To1_13> { public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.ItemRewriter<Protocol1_12_2To1_13> {
private final Map<String, String> enchantmentMappings = new HashMap<>(); private final Map<String, String> enchantmentMappings = new HashMap<>();
private final String NBT_TAG_NAME; private final String extraNbtTag;
public BlockItemPackets1_13(Protocol1_12_2To1_13 protocol) { public BlockItemPackets1_13(Protocol1_12_2To1_13 protocol) {
super(protocol, null, id -> BackwardsMappings.itemMappings.getMappedItem(id)); super(protocol, null, id -> BackwardsMappings.itemMappings.getMappedItem(id));
NBT_TAG_NAME = "ViaBackwards|" + protocol.getClass().getSimpleName() + "|Part2"; extraNbtTag = "VB|" + protocol.getClass().getSimpleName() + "|2";
} }
public static int toOldId(int oldId) { public static int toOldId(int oldId) {
@ -96,7 +96,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
// Set Cooldown // Set Cooldown
protocol.out(State.PLAY, 0x18, 0x17, new PacketRemapper() { protocol.out(State.PLAY, 0x18, 0x17, new PacketRemapper() {
@Override @Override
public void registerMap() { //TODO is this actually the correct id conversion? public void registerMap() {
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
@ -309,14 +309,13 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
BackwardsBlockEntityProvider provider = Via.getManager().getProviders().get(BackwardsBlockEntityProvider.class); BackwardsBlockEntityProvider provider = Via.getManager().getProviders().get(BackwardsBlockEntityProvider.class);
BackwardsBlockStorage storage = wrapper.user().get(BackwardsBlockStorage.class); BackwardsBlockStorage storage = wrapper.user().get(BackwardsBlockStorage.class);
for (CompoundTag tag : chunk.getBlockEntities()) { for (CompoundTag tag : chunk.getBlockEntities()) {
if (!tag.contains("id")) Tag idTag = tag.get("id");
continue; if (idTag == null) continue;
String id = (String) tag.get("id").getValue(); String id = (String) idTag.getValue();
// Ignore if we don't handle it // Ignore if we don't handle it
if (!provider.isHandled(id)) if (!provider.isHandled(id)) continue;
continue;
int sectionIndex = ((int) tag.get("y").getValue()) >> 4; int sectionIndex = ((int) tag.get("y").getValue()) >> 4;
ChunkSection section = chunk.getSections()[sectionIndex]; ChunkSection section = chunk.getSections()[sectionIndex];
@ -550,10 +549,10 @@ 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
if (tag != null) { if (tag != null) {
// Check for valid tag // Check for valid tag
if (tag.get(NBT_TAG_NAME) instanceof IntTag) { if (tag.get(extraNbtTag) instanceof IntTag) {
rawId = (Integer) tag.get(NBT_TAG_NAME).getValue(); rawId = (Integer) tag.get(extraNbtTag).getValue();
// Remove the tag // Remove the tag
tag.remove(NBT_TAG_NAME); tag.remove(extraNbtTag);
gotRawIdFromTag = true; gotRawIdFromTag = true;
} }
} }
@ -613,7 +612,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 instanceof StringTag) { if (name instanceof StringTag) {
StringTag via = display.remove(NBT_TAG_NAME + "|Name"); StringTag via = display.remove(extraNbtTag + "|Name");
name.setValue(via != null ? via.getValue() : ChatRewriter.jsonTextToLegacy(name.getValue())); name.setValue(via != null ? via.getValue() : ChatRewriter.jsonTextToLegacy(name.getValue()));
} }
} }
@ -650,7 +649,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
if (blockTag == null) return; if (blockTag == null) return;
ListTag newCanPlaceOn = new ListTag(tagName, StringTag.class); ListTag newCanPlaceOn = new ListTag(tagName, StringTag.class);
tag.put(ConverterRegistry.convertToTag(NBT_TAG_NAME + "|" + tagName, ConverterRegistry.convertToValue(blockTag))); tag.put(ConverterRegistry.convertToTag(extraNbtTag + "|" + tagName, 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 ?
@ -671,7 +670,7 @@ 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(NBT_TAG_NAME + "|" + key, CompoundTag.class); ListTag noMapped = new ListTag(extraNbtTag + "|" + key, CompoundTag.class);
ListTag newEnchantments = new ListTag(storedEnch ? key : "ench", CompoundTag.class); ListTag newEnchantments = new ListTag(storedEnch ? key : "ench", CompoundTag.class);
List<Tag> lore = new ArrayList<>(); List<Tag> lore = new ArrayList<>();
boolean hasValidEnchants = false; boolean hasValidEnchants = false;
@ -696,8 +695,9 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
// Some custom-enchant plugins write it into the lore manually, which would double its entry // Some custom-enchant plugins write it into the lore manually, which would double its entry
if (ViaBackwards.getConfig().addCustomEnchantsToLore()) { if (ViaBackwards.getConfig().addCustomEnchantsToLore()) {
String name = newId; String name = newId;
if (name.contains(":")) { int index = name.indexOf(':') + 1;
name = name.split(":")[1]; if (index != 0 && index != name.length()) {
name = name.substring(index);
} }
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);
@ -729,9 +729,9 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
IntTag hideFlags = tag.get("HideFlags"); IntTag hideFlags = tag.get("HideFlags");
if (hideFlags == null) { if (hideFlags == null) {
hideFlags = new IntTag("HideFlags"); hideFlags = new IntTag("HideFlags");
tag.put(new ByteTag(NBT_TAG_NAME + "|DummyEnchant")); tag.put(new ByteTag(extraNbtTag + "|DummyEnchant"));
} else { } else {
tag.put(new IntTag(NBT_TAG_NAME + "|OldHideFlags", hideFlags.getValue())); tag.put(new IntTag(extraNbtTag + "|OldHideFlags", hideFlags.getValue()));
} }
if (newEnchantments.size() == 0) { if (newEnchantments.size() == 0) {
@ -758,9 +758,9 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
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(loreTag = new ListTag("Lore", StringTag.class));
tag.put(new ByteTag(NBT_TAG_NAME + "|DummyLore")); tag.put(new ByteTag(extraNbtTag + "|DummyLore"));
} else if (loreTag.size() != 0) { } else if (loreTag.size() != 0) {
ListTag oldLore = new ListTag(NBT_TAG_NAME + "|OldLore", StringTag.class); ListTag oldLore = new ListTag(extraNbtTag + "|OldLore", StringTag.class);
for (Tag value : loreTag) { for (Tag value : loreTag) {
oldLore.add(value.clone()); oldLore.add(value.clone());
} }
@ -808,7 +808,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
CompoundTag displayTag = (CompoundTag) display; CompoundTag displayTag = (CompoundTag) display;
StringTag name = displayTag.get("Name"); StringTag name = displayTag.get("Name");
if (name instanceof StringTag) { if (name instanceof StringTag) {
displayTag.put(new StringTag(NBT_TAG_NAME + "|Name", name.getValue())); displayTag.put(new StringTag(extraNbtTag + "|Name", name.getValue()));
name.setValue(ChatRewriter.legacyTextToJson(name.getValue())); name.setValue(ChatRewriter.legacyTextToJson(name.getValue()));
} }
} }
@ -858,7 +858,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
if (!MappingData.oldToNewItems.containsKey(rawId)) { if (!MappingData.oldToNewItems.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"));
tag.put(new IntTag(NBT_TAG_NAME, originalId)); // Data will be lost, saving original id tag.put(new IntTag(extraNbtTag, originalId)); // Data will be lost, saving original id
} }
if (item.getIdentifier() == 229) { // purple shulker box if (item.getIdentifier() == 229) { // purple shulker box
@ -885,7 +885,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
} }
private void rewriteCanPlaceToServer(CompoundTag tag, String tagName) { private void rewriteCanPlaceToServer(CompoundTag tag, String tagName) {
ListTag blockTag = tag.remove(NBT_TAG_NAME + "|" + tagName); ListTag blockTag = tag.remove(extraNbtTag + "|" + tagName);
if (blockTag != null) { if (blockTag != null) {
tag.put(ConverterRegistry.convertToTag(tagName, ConverterRegistry.convertToValue(blockTag))); tag.put(ConverterRegistry.convertToTag(tagName, ConverterRegistry.convertToValue(blockTag)));
} else if ((blockTag = tag.get(tagName)) != null) { } else if ((blockTag = tag.get(tagName)) != null) {
@ -920,15 +920,13 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
ListTag newEnchantments = new ListTag(key, CompoundTag.class); ListTag newEnchantments = new ListTag(key, CompoundTag.class);
boolean dummyEnchant = false; boolean dummyEnchant = false;
if (!storedEnch) { if (!storedEnch) {
IntTag hideFlags = tag.get(NBT_TAG_NAME + "|OldHideFlags"); IntTag hideFlags = tag.remove(extraNbtTag + "|OldHideFlags");
if (hideFlags != null) { if (hideFlags != null) {
tag.put(new IntTag("HideFlags", hideFlags.getValue())); tag.put(new IntTag("HideFlags", hideFlags.getValue()));
dummyEnchant = true; dummyEnchant = true;
tag.remove(NBT_TAG_NAME + "|OldHideFlags"); } else if (tag.remove(extraNbtTag + "|DummyEnchant") != null) {
} else if (tag.contains(NBT_TAG_NAME + "|DummyEnchant")) {
tag.remove("HideFlags"); tag.remove("HideFlags");
dummyEnchant = true; dummyEnchant = true;
tag.remove(NBT_TAG_NAME + "|DummyEnchant");
} }
} }
@ -949,12 +947,12 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
newEnchantments.add(enchantmentEntry); newEnchantments.add(enchantmentEntry);
} }
ListTag noMapped = tag.get(NBT_TAG_NAME + "|Enchantments"); ListTag noMapped = tag.get(extraNbtTag + "|Enchantments");
if (noMapped != null) { if (noMapped != null) {
for (Tag value : noMapped) { for (Tag value : noMapped) {
newEnchantments.add(value); newEnchantments.add(value);
} }
tag.remove(NBT_TAG_NAME + "|Enchantments"); tag.remove(extraNbtTag + "|Enchantments");
} }
CompoundTag display = tag.get("display"); CompoundTag display = tag.get("display");
@ -962,7 +960,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
tag.put(display = new CompoundTag("display")); tag.put(display = new CompoundTag("display"));
} }
ListTag oldLore = tag.get(NBT_TAG_NAME + "|OldLore"); ListTag oldLore = tag.get(extraNbtTag + "|OldLore");
if (oldLore != null) { if (oldLore != null) {
ListTag lore = display.get("Lore"); ListTag lore = display.get("Lore");
if (lore == null) { if (lore == null) {
@ -970,14 +968,12 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
} }
lore.setValue(oldLore.getValue()); lore.setValue(oldLore.getValue());
tag.remove(NBT_TAG_NAME + "|OldLore"); tag.remove(extraNbtTag + "|OldLore");
} else if (tag.contains(NBT_TAG_NAME + "|DummyLore")) { } else if (tag.remove(extraNbtTag + "|DummyLore") != null) {
display.remove("Lore"); display.remove("Lore");
if (display.isEmpty()) { if (display.isEmpty()) {
tag.remove("display"); tag.remove("display");
} }
tag.remove(NBT_TAG_NAME + "|DummyLore");
} }
if (!storedEnch) { if (!storedEnch) {