Cleanup enchantment conversion in 1.12->1.13 to match vanilla (#4147)

Closes https://github.com/ViaVersion/ViaFabricPlus/issues/560
This commit is contained in:
EnZaXD 2024-09-14 21:33:18 +02:00 committed by GitHub
parent fcb472347e
commit 7235485802
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -304,23 +304,15 @@ public class ItemPacketRewriter1_13 extends ItemRewriter<ClientboundPackets1_12_
if (ench != null) {
ListTag<CompoundTag> enchantments = new ListTag<>(CompoundTag.class);
for (CompoundTag enchEntry : ench) {
NumberTag idTag = enchEntry.getNumberTag("id");
if (idTag == null) {
continue;
}
short oldId = enchEntry.getShort("id", (short) 0);
CompoundTag enchantmentEntry = new CompoundTag();
short oldId = idTag.asShort();
String newId = Protocol1_12_2To1_13.MAPPINGS.getOldEnchantmentsIds().get(oldId);
if (newId == null) {
newId = "viaversion:legacy/" + oldId;
}
enchantmentEntry.putString("id", newId);
NumberTag levelTag = enchEntry.getNumberTag("lvl");
if (levelTag != null) {
enchantmentEntry.putShort("lvl", levelTag.asShort());
}
enchantmentEntry.putShort("lvl", enchEntry.getShort("lvl", (short) 0));
enchantments.add(enchantmentEntry);
}
@ -589,10 +581,7 @@ public class ItemPacketRewriter1_13 extends ItemRewriter<ClientboundPackets1_12_
}
if (oldId != null) {
enchEntry.putShort("id", oldId);
NumberTag levelTag = enchantmentEntry.getNumberTag("lvl");
if (levelTag != null) {
enchEntry.putShort("lvl", levelTag.asShort());
}
enchEntry.putShort("lvl", enchantmentEntry.getShort("lvl", (short) 0));
ench.add(enchEntry);
}
}