From 9da206e28065f03527dea5c92d09070a90aec7a7 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Fri, 3 Jun 2022 18:19:54 +0200 Subject: [PATCH] Add sanity check in 1.13->1.12 enchantment handler Closes #2908 --- .../packets/BlockItemPackets1_13.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java index 4bca6781..c3eb504c 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java @@ -653,10 +653,17 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit for (Tag enchantmentEntryTag : enchantments.clone()) { CompoundTag enchantmentEntry = (CompoundTag) enchantmentEntryTag; Tag idTag = enchantmentEntry.get("id"); - if (!(idTag instanceof StringTag)) continue; + if (!(idTag instanceof StringTag)) { + continue; + } String newId = (String) idTag.getValue(); - int levelValue = ((NumberTag) enchantmentEntry.get("lvl")).asInt(); + NumberTag levelTag = enchantmentEntry.get("lvl"); + if (levelTag == null) { + continue; + } + + int levelValue = levelTag.asInt(); short level = levelValue < Short.MAX_VALUE ? (short) levelValue : Short.MAX_VALUE; String mappedEnchantmentId = enchantmentMappings.get(newId);