Fix ItemStack#addUnsafeEnchantment ignored for missing enchantment component (#12549)
This commit is contained in:
@ -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 {
|
||||
Reference in New Issue
Block a user