From 32161333dda65cfe90849c1c8ba8b23d25dad225 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Fri, 20 Jul 2018 15:47:05 -0300 Subject: [PATCH 1/3] Fix custom enchantments --- .../packets/InventoryPackets.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java index 1025771f7..ae647c85e 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java @@ -315,11 +315,12 @@ public class InventoryPackets { for (Tag enchEntry : ench) { if (enchEntry instanceof CompoundTag) { CompoundTag enchantmentEntry = new CompoundTag(""); - enchantmentEntry.put(new StringTag("id", - MappingData.oldEnchantmentsIds.get( - (short) ((CompoundTag) enchEntry).get("id").getValue() - ) - )); + short oldId = (short) ((CompoundTag) enchEntry).get("id").getValue(); + String newId = MappingData.oldEnchantmentsIds.get(oldId); + if (newId == null){ + newId = "viaversion:legacy/"+oldId; + } + enchantmentEntry.put(new StringTag("id", newId)); enchantmentEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchEntry).get("lvl").getValue())); enchantments.add(enchantmentEntry); } @@ -333,10 +334,13 @@ public class InventoryPackets { for (Tag enchEntry : storedEnch) { if (enchEntry instanceof CompoundTag) { CompoundTag enchantmentEntry = new CompoundTag(""); + short oldId = (short) ((CompoundTag) enchEntry).get("id").getValue(); + String newId = MappingData.oldEnchantmentsIds.get(oldId); + if (newId == null) { + newId = "viaversion:legacy/"+oldId; + } enchantmentEntry.put(new StringTag("id", - MappingData.oldEnchantmentsIds.get( - (short) ((CompoundTag) enchEntry).get("id").getValue() - ) + newId )); enchantmentEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchEntry).get("lvl").getValue())); newStoredEnch.add(enchantmentEntry); @@ -495,12 +499,15 @@ public class InventoryPackets { for (Tag enchantmentEntry : enchantments) { if (enchantmentEntry instanceof CompoundTag) { CompoundTag enchEntry = new CompoundTag(""); + String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue(); + Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId); + if (oldId == null && newId.startsWith("viaversion:legacy/")){ + oldId = Short.valueOf(newId.substring(18)); + } enchEntry.put( new ShortTag( "id", - MappingData.oldEnchantmentsIds.inverse().get( - (String) ((CompoundTag) enchantmentEntry).get("id").getValue() - ) + oldId ) ); enchEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue())); From 9a1376dcb353679545f08665b8832e115a96ace0 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Fri, 20 Jul 2018 15:54:52 -0300 Subject: [PATCH 2/3] Accept int tag --- .../packets/InventoryPackets.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java index ae647c85e..fbd049acf 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java @@ -315,7 +315,7 @@ public class InventoryPackets { for (Tag enchEntry : ench) { if (enchEntry instanceof CompoundTag) { CompoundTag enchantmentEntry = new CompoundTag(""); - short oldId = (short) ((CompoundTag) enchEntry).get("id").getValue(); + short oldId = ((Number) ((CompoundTag) enchEntry).get("id").getValue()).shortValue(); String newId = MappingData.oldEnchantmentsIds.get(oldId); if (newId == null){ newId = "viaversion:legacy/"+oldId; @@ -334,7 +334,7 @@ public class InventoryPackets { for (Tag enchEntry : storedEnch) { if (enchEntry instanceof CompoundTag) { CompoundTag enchantmentEntry = new CompoundTag(""); - short oldId = (short) ((CompoundTag) enchEntry).get("id").getValue(); + short oldId = ((Number) ((CompoundTag) enchEntry).get("id").getValue()).shortValue(); String newId = MappingData.oldEnchantmentsIds.get(oldId); if (newId == null) { newId = "viaversion:legacy/"+oldId; @@ -522,13 +522,15 @@ public class InventoryPackets { ListTag newStoredEnch = new ListTag("StoredEnchantments", CompoundTag.class); for (Tag enchantmentEntry : storedEnch) { if (enchantmentEntry instanceof CompoundTag) { - CompoundTag enchEntry = new CompoundTag(""); + CompoundTag enchEntry = new CompoundTag("");String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue(); + Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId); + if (oldId == null && newId.startsWith("viaversion:legacy/")){ + oldId = Short.valueOf(newId.substring(18)); + } enchEntry.put( new ShortTag( "id", - MappingData.oldEnchantmentsIds.inverse().get( - (String) ((CompoundTag) enchantmentEntry).get("id").getValue() - ) + oldId ) ); enchEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue())); From 6c17615ecbf771638c1eb0bd145d167a6409e036 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Fri, 20 Jul 2018 15:58:04 -0300 Subject: [PATCH 3/3] Accept int tag in level --- .../protocol1_13to1_12_2/packets/InventoryPackets.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java index fbd049acf..5e2257352 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java @@ -321,7 +321,7 @@ public class InventoryPackets { newId = "viaversion:legacy/"+oldId; } enchantmentEntry.put(new StringTag("id", newId)); - enchantmentEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchEntry).get("lvl").getValue())); + enchantmentEntry.put(new ShortTag("lvl", ((Number) ((CompoundTag) enchEntry).get("lvl").getValue()).shortValue())); enchantments.add(enchantmentEntry); } } @@ -342,7 +342,7 @@ public class InventoryPackets { enchantmentEntry.put(new StringTag("id", newId )); - enchantmentEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchEntry).get("lvl").getValue())); + enchantmentEntry.put(new ShortTag("lvl", ((Number) ((CompoundTag) enchEntry).get("lvl").getValue()).shortValue())); newStoredEnch.add(enchantmentEntry); } }