From 2e511434330d17a7cc0df017f19c99b855eb6663 Mon Sep 17 00:00:00 2001 From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Date: Sat, 24 Sep 2022 07:19:51 +0200 Subject: [PATCH] Avoid item meta usage for itemstack enchantment getter (#8373) --- .../Handle-Item-Meta-Inconsistencies.patch | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/patches/server/Handle-Item-Meta-Inconsistencies.patch b/patches/server/Handle-Item-Meta-Inconsistencies.patch index df92925b95..f20e245e8f 100644 --- a/patches/server/Handle-Item-Meta-Inconsistencies.patch +++ b/patches/server/Handle-Item-Meta-Inconsistencies.patch @@ -116,21 +116,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 static boolean makeTag(net.minecraft.world.item.ItemStack item) { @@ -0,0 +0,0 @@ public final class CraftItemStack extends ItemStack { - - @Override - public boolean containsEnchantment(Enchantment ench) { -- return this.getEnchantmentLevel(ench) > 0; -+ return this.hasItemMeta() && this.getItemMeta().hasEnchant(ench); // Paper - use meta - } - - @Override - public int getEnchantmentLevel(Enchantment ench) { -- Validate.notNull(ench, "Cannot find null enchantment"); -- if (this.handle == null) { -- return 0; -- } + if (this.handle == null) { + return 0; + } - return EnchantmentHelper.getItemEnchantmentLevel(CraftEnchantment.getRaw(ench), handle); -+ return this.hasItemMeta() ? this.getItemMeta().getEnchantLevel(ench) : 0; // Paper - replace entire method with meta ++ return net.minecraft.world.item.enchantment.EnchantmentHelper.getItemEnchantmentLevel(CraftEnchantment.getRaw(ench), handle); // Paper } @Override @@ -173,10 +163,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 - listCopy.add(list.get(i)); - } + // Paper start - replace entire method -+ final ItemMeta itemMeta = this.getItemMeta(); -+ if (itemMeta == null) return 0; -+ int level = itemMeta.getEnchantLevel(ench); ++ int level = getEnchantmentLevel(ench); + if (level > 0) { ++ final ItemMeta itemMeta = this.getItemMeta(); ++ if (itemMeta == null) return 0; + itemMeta.removeEnchant(ench); + this.setItemMeta(itemMeta); }