Fix ItemStack#addUnsafeEnchantment ignored for missing enchantment component (#12549)

This commit is contained in:
Pedro
2025-05-17 10:13:08 -04:00
committed by GitHub
parent 369ad1706b
commit 841d634230
2 changed files with 19 additions and 3 deletions

View File

@ -0,0 +1,18 @@
--- a/net/minecraft/world/item/enchantment/EnchantmentHelper.java
+++ b/net/minecraft/world/item/enchantment/EnchantmentHelper.java
@@ -52,8 +_,14 @@
}
public static ItemEnchantments updateEnchantments(ItemStack stack, Consumer<ItemEnchantments.Mutable> updater) {
+ // Paper start - allowing updating enchantments on items without component
+ return updateEnchantments(stack, updater, false);
+ }
+
+ public static ItemEnchantments updateEnchantments(ItemStack stack, Consumer<ItemEnchantments.Mutable> updater, final boolean createComponentIfMissing) {
+ // Paper end - allowing updating enchantments on items without component
DataComponentType<ItemEnchantments> componentType = getComponentType(stack);
- ItemEnchantments itemEnchantments = stack.get(componentType);
+ ItemEnchantments itemEnchantments = createComponentIfMissing ? stack.getOrDefault(componentType, ItemEnchantments.EMPTY) : stack.get(componentType); // Paper - allowing updating enchantments on items without component
if (itemEnchantments == null) {
return ItemEnchantments.EMPTY;
} else {