Correctly check enchants for ItemStack#damage (#11240)

This commit is contained in:
Jake Potrebic 2024-08-11 13:27:24 -07:00 committed by GitHub
parent 7d7f123e98
commit 1c3c47ab0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,10 +11,10 @@ the logic associated with damaging them
public net.minecraft.world.entity.LivingEntity entityEventForEquipmentBreak(Lnet/minecraft/world/entity/EquipmentSlot;)B
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index 598507684aed7978fa2e9bae0d959c7d0f9e53d6..7c52ae813bfe47983ca94f4daf68f17e899949da 100644
index 598507684aed7978fa2e9bae0d959c7d0f9e53d6..e6588a7fc03df4036b38f9a2011e7a716ff111f4 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -647,11 +647,16 @@ public final class ItemStack implements DataComponentHolder {
@@ -647,8 +647,13 @@ public final class ItemStack implements DataComponentHolder {
}
public void hurtAndBreak(int amount, ServerLevel world, @Nullable LivingEntity player, Consumer<Item> breakCallback) { // Paper - Add EntityDamageItemEvent
@ -28,11 +28,7 @@ index 598507684aed7978fa2e9bae0d959c7d0f9e53d6..7c52ae813bfe47983ca94f4daf68f17e
+ if (player == null || !player.hasInfiniteMaterials() || force) { // Paper
if (amount > 0) {
int originalDamage = amount; // Paper - Expand PlayerItemDamageEvent
- amount = EnchantmentHelper.processDurabilityChange(world, this, amount);
+ if (!force) amount = EnchantmentHelper.processDurabilityChange(world, this, amount); // Paper - itemstack damage API - do not consider enchantments when damaging from API
// CraftBukkit start
if (player instanceof ServerPlayer serverPlayer) { // Paper - Add EntityDamageItemEvent
PlayerItemDamageEvent event = new PlayerItemDamageEvent(serverPlayer.getBukkitEntity(), CraftItemStack.asCraftMirror(this), amount, originalDamage); // Paper - Add EntityDamageItemEvent & Expand PlayerItemDamageEvent
amount = EnchantmentHelper.processDurabilityChange(world, this, amount);
@@ -699,6 +704,11 @@ public final class ItemStack implements DataComponentHolder {
}