From 6b73de2510fc95192e9fe9980ff019353f6eb17b Mon Sep 17 00:00:00 2001 From: KennyTV Date: Mon, 16 Mar 2020 12:01:21 +0100 Subject: [PATCH] Fix number casting in 1.13 enchantments --- .../api/rewriters/EnchantmentRewriter.java | 2 +- .../packets/BlockItemPackets1_13.java | 23 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EnchantmentRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EnchantmentRewriter.java index f3265320..a72246fe 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EnchantmentRewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EnchantmentRewriter.java @@ -31,7 +31,7 @@ public class EnchantmentRewriter { if (enchantmentName != null) { enchantments.remove(enchantmentEntry); Number level = (Number) ((CompoundTag) enchantmentEntry).get("lvl").getValue(); - lore.add(new StringTag("", enchantmentName + " " + getRomanNumber(level.shortValue()))); + lore.add(new StringTag("", enchantmentName + " " + getRomanNumber(level.intValue()))); remappedEnchantments.add(enchantmentEntry); } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java index 7810d588..5aa7963f 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java @@ -646,14 +646,15 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It ListTag newEnchantments = new ListTag(storedEnch ? key : "ench", CompoundTag.class); List lore = new ArrayList<>(); boolean hasValidEnchants = false; - for (Tag enchantmentEntry : enchantments.clone()) { - CompoundTag enchEntry = new CompoundTag(""); - String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue(); + for (Tag enchantmentEntryTag : enchantments.clone()) { + CompoundTag enchantmentEntry = (CompoundTag) enchantmentEntryTag; + String newId = (String) enchantmentEntry.get("id").getValue(); + Number levelValue = (Number) enchantmentEntry.get("lvl").getValue(); + short level = levelValue.shortValue(); String mappedEnchantmentId = enchantmentMappings.get(newId); if (mappedEnchantmentId != null) { - lore.add(new StringTag("", mappedEnchantmentId + " " - + EnchantmentRewriter.getRomanNumber((Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue()))); + lore.add(new StringTag("", mappedEnchantmentId + " " + EnchantmentRewriter.getRomanNumber(level))); noMapped.add(enchantmentEntry); } else if (!newId.isEmpty()) { Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId); @@ -670,8 +671,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((Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue()))); + lore.add(new StringTag("", name + " " + EnchantmentRewriter.getRomanNumber(level))); } if (Via.getManager().isDebug()) { @@ -683,13 +683,14 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It } } - Short level = (Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue(); if (level != 0) { hasValidEnchants = true; } - enchEntry.put(new ShortTag("id", oldId)); - enchEntry.put(new ShortTag("lvl", level)); - newEnchantments.add(enchEntry); + + CompoundTag newEntry = new CompoundTag(""); + newEntry.put(new ShortTag("id", oldId)); + newEntry.put(new ShortTag("lvl", level)); + newEnchantments.add(newEntry); } }