mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-15 14:13:56 +01:00
Fixed CraftItemStack/CraftItemMeta enchantment level inconsistency (#8792)
Co-authored-by: Nassim Jahnke <nassim@njahnke.dev>
This commit is contained in:
parent
d8b5390f81
commit
bd8dd4f684
1 changed files with 19 additions and 0 deletions
|
@ -108,6 +108,25 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
|
||||
static boolean makeTag(net.minecraft.world.item.ItemStack item) {
|
||||
@@ -0,0 +0,0 @@ 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");
|
||||
|
||||
|
|
Loading…
Reference in a new issue