From 9f90b4c324077c0a407e6f94fdf47b4fa4bb31a0 Mon Sep 17 00:00:00 2001 From: Tamion <70228790+notTamion@users.noreply.github.com> Date: Sat, 4 Jan 2025 21:54:40 +0100 Subject: [PATCH] Fix ItemDamageEvents called for 0 damage (#11900) --- .../sources/net/minecraft/world/item/ItemStack.java.patch | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/world/item/ItemStack.java.patch b/paper-server/patches/sources/net/minecraft/world/item/ItemStack.java.patch index 2bd24dd054..141de8193a 100644 --- a/paper-server/patches/sources/net/minecraft/world/item/ItemStack.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/item/ItemStack.java.patch @@ -218,6 +218,7 @@ - public void hurtAndBreak(int damage, ServerLevel level, @Nullable ServerPlayer player, Consumer onBreak) { - int i = this.processDurabilityChange(damage, level, player); +- if (i != 0) { + public void hurtAndBreak(int damage, ServerLevel level, @Nullable LivingEntity player, Consumer onBreak) { // Paper - Add EntityDamageItemEvent + // Paper start - add force boolean overload + this.hurtAndBreak(damage, level, player, onBreak, false); @@ -227,7 +228,7 @@ + final int originalDamage = damage; // Paper - Expand PlayerItemDamageEvent + int i = this.processDurabilityChange(damage, level, player, force); // Paper + // CraftBukkit start -+ if (player instanceof final ServerPlayer serverPlayer) { // Paper - Add EntityDamageItemEvent ++ if (i > 0 && player instanceof final ServerPlayer serverPlayer) { // Paper - Add EntityDamageItemEvent - limit to positive damage and run for player + org.bukkit.event.player.PlayerItemDamageEvent event = new org.bukkit.event.player.PlayerItemDamageEvent(serverPlayer.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this), i, originalDamage); // Paper - Add EntityDamageItemEvent + event.getPlayer().getServer().getPluginManager().callEvent(event); + @@ -240,7 +241,7 @@ + + i = event.getDamage(); + // Paper start - Add EntityDamageItemEvent -+ } else if (player != null) { ++ } else if (i > 0 && player != null) { + io.papermc.paper.event.entity.EntityDamageItemEvent event = new io.papermc.paper.event.entity.EntityDamageItemEvent(player.getBukkitLivingEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this), i); + if (!event.callEvent()) { + return; @@ -249,7 +250,7 @@ + // Paper end - Add EntityDamageItemEvent + } + // CraftBukkit end - if (i != 0) { ++ if (i != 0) { // Paper - Add EntityDamageItemEvent - diff on change for above event ifs. this.applyDamage(this.getDamageValue() + i, player, onBreak); } }