From 1259b93ba636bf089cec5469a17ca2d75d3f537f Mon Sep 17 00:00:00 2001 From: Will FP <38837418+WillFP@users.noreply.github.com> Date: Mon, 21 Aug 2023 08:31:52 +0100 Subject: [PATCH] Fixed CraftItemStack/CraftItemMeta enchantment level inconsistency (#8792) Co-authored-by: Nassim Jahnke --- ...069-Handle-Item-Meta-Inconsistencies.patch | 23 +++++++++++++++++-- ...on-t-call-getItemMeta-on-hasItemMeta.patch | 4 ++-- patches/server/0791-More-Projectile-API.patch | 4 ++-- ...83-fix-item-meta-for-tadpole-buckets.patch | 4 ++-- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/patches/server/0069-Handle-Item-Meta-Inconsistencies.patch b/patches/server/0069-Handle-Item-Meta-Inconsistencies.patch index 0d40e0bab2..6c91ecd340 100644 --- a/patches/server/0069-Handle-Item-Meta-Inconsistencies.patch +++ b/patches/server/0069-Handle-Item-Meta-Inconsistencies.patch @@ -70,7 +70,7 @@ index 3f18fb61a47dda559a6997af9c6c043423dd206a..c33660718c0ea281d7bcdb15df0568d4 public boolean isEnchanted() { diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java -index 34a54a99e7484b2934e1d174c1b55f0472ff3812..7fd9a3a7f4cb98d89b7c4cbfda756d581963e5bf 100644 +index 34a54a99e7484b2934e1d174c1b55f0472ff3812..b75c8549e9484a2e6167d0bbb9fd64ae8b422931 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java @@ -178,28 +178,11 @@ public final class CraftItemStack extends ItemStack { @@ -107,7 +107,26 @@ index 34a54a99e7484b2934e1d174c1b55f0472ff3812..7fd9a3a7f4cb98d89b7c4cbfda756d58 } static boolean makeTag(net.minecraft.world.item.ItemStack item) { -@@ -232,50 +215,22 @@ public final class CraftItemStack extends ItemStack { +@@ -225,57 +208,40 @@ public final class CraftItemStack extends ItemStack { + if (this.handle == null) { + return 0; + } +- return EnchantmentHelper.getItemEnchantmentLevel(CraftEnchantment.getRaw(ench), handle); ++ // Paper start - replace to allow custom enchantments ++ final ListTag enchantments = this.handle.getEnchantmentTags(); ++ for (int i = 0; i < enchantments.size(); i++) { ++ final CompoundTag tag = enchantments.getCompound(i); ++ final String id = tag.getString(CraftMetaItem.ENCHANTMENTS_ID.NBT); ++ final Enchantment enchant = Enchantment.getByKey(CraftNamespacedKey.fromStringOrNull(id)); ++ if (ench.equals(enchant)) { ++ return EnchantmentHelper.getEnchantmentLevel(tag); ++ } ++ } ++ return 0; ++ // Paper end - replace to allow custom enchantments + } + + @Override public int removeEnchantment(Enchantment ench) { Preconditions.checkArgument(ench != null, "Enchantment cannot be null"); diff --git a/patches/server/0228-Don-t-call-getItemMeta-on-hasItemMeta.patch b/patches/server/0228-Don-t-call-getItemMeta-on-hasItemMeta.patch index ce7d42bc7a..8fa3d1c5a8 100644 --- a/patches/server/0228-Don-t-call-getItemMeta-on-hasItemMeta.patch +++ b/patches/server/0228-Don-t-call-getItemMeta-on-hasItemMeta.patch @@ -11,10 +11,10 @@ Returns true if getDamage() == 0 or has damage tag or other tag is set. Check the `ItemMetaTest#testTaggedButNotMeta` method to see how this method behaves. diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java -index 0ac686e880f0f87ab3f6dbed77e553d7568b3305..6775b432e17b09aaa21af5713fa0ffdf7fdbf8a9 100644 +index 3afb5e9e9c40031d9a8afe9460ebae81bbad58a9..0588f33b59e95ad660c07332ab31d253e240c9b8 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java -@@ -657,7 +657,7 @@ public final class CraftItemStack extends ItemStack { +@@ -668,7 +668,7 @@ public final class CraftItemStack extends ItemStack { @Override public boolean hasItemMeta() { diff --git a/patches/server/0791-More-Projectile-API.patch b/patches/server/0791-More-Projectile-API.patch index e283c148ef..272e36576c 100644 --- a/patches/server/0791-More-Projectile-API.patch +++ b/patches/server/0791-More-Projectile-API.patch @@ -492,10 +492,10 @@ index c628594b981f276acae7b9337100d811f919631b..c8b65210d2416b5a293cb4bcc1b71f56 // Paper end } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java -index 6775b432e17b09aaa21af5713fa0ffdf7fdbf8a9..d6b9897dcb4715decd4dd0b1b96995e25d789482 100644 +index 0588f33b59e95ad660c07332ab31d253e240c9b8..3f0c1edcc6bf57a72942b4680fccf27c68ea0a44 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java -@@ -279,12 +279,20 @@ public final class CraftItemStack extends ItemStack { +@@ -290,12 +290,20 @@ public final class CraftItemStack extends ItemStack { public ItemMeta getItemMeta() { return CraftItemStack.getItemMeta(this.handle); } diff --git a/patches/server/0983-fix-item-meta-for-tadpole-buckets.patch b/patches/server/0983-fix-item-meta-for-tadpole-buckets.patch index 0f7042779b..e5f69e6d49 100644 --- a/patches/server/0983-fix-item-meta-for-tadpole-buckets.patch +++ b/patches/server/0983-fix-item-meta-for-tadpole-buckets.patch @@ -17,10 +17,10 @@ index 4c0b250bb9e3cf52173b563b36fd27d9e893e154..3f4e55bb9a4134e54adddca3c6622851 case GLOW_ITEM_FRAME: case PAINTING: diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java -index 8657736cdfe2d5d2a1c0851ca54dd26ce17e0a83..f62ef038af2dfe7525e72c8b8e30a3fa9ce2b451 100644 +index dc524fd22ce5f9298e3d73b05d72c1ef7459d9ea..3e8cd6a892155c1eda34424d87bd426ace26f3cd 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java -@@ -579,6 +579,7 @@ public final class CraftItemStack extends ItemStack { +@@ -590,6 +590,7 @@ public final class CraftItemStack extends ItemStack { case COD_BUCKET: case PUFFERFISH_BUCKET: case SALMON_BUCKET: