Fixed CraftItemStack/CraftItemMeta enchantment level inconsistency (#8792)

Co-authored-by: Nassim Jahnke <nassim@njahnke.dev>
This commit is contained in:
Will FP 2023-08-21 08:31:52 +01:00 committed by GitHub
parent 990765bd08
commit 1259b93ba6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 8 deletions

View File

@ -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");

View File

@ -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() {

View File

@ -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);
}

View File

@ -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: