mirror of
https://github.com/PaperMC/Paper.git
synced 2025-05-19 05:30:23 -07:00
Fix ItemStack#addUnsafeEnchantment ignored for missing enchantment component (#12549)
This commit is contained in:
parent
369ad1706b
commit
841d634230
@ -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 {
|
@ -268,15 +268,13 @@ public final class CraftItemStack extends ItemStack {
|
|||||||
public void addUnsafeEnchantment(Enchantment enchant, int level) {
|
public void addUnsafeEnchantment(Enchantment enchant, int level) {
|
||||||
Preconditions.checkArgument(enchant != null, "Enchantment cannot be null");
|
Preconditions.checkArgument(enchant != null, "Enchantment cannot be null");
|
||||||
|
|
||||||
// Paper start
|
|
||||||
if (this.handle == null) {
|
if (this.handle == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
EnchantmentHelper.updateEnchantments(this.handle, mutable -> { // data component api doesn't really support mutable things once already set yet
|
EnchantmentHelper.updateEnchantments(this.handle, mutable -> { // data component api doesn't really support mutable things once already set yet
|
||||||
mutable.set(CraftEnchantment.bukkitToMinecraftHolder(enchant), level);
|
mutable.set(CraftEnchantment.bukkitToMinecraftHolder(enchant), level);
|
||||||
});
|
}, true);
|
||||||
// Paper end
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user