Skip to content

Commit

Permalink
Call PlayerItemDamageEvent for tridents (#11899)
Browse files Browse the repository at this point in the history
  • Loading branch information
notTamion authored Jan 12, 2025
1 parent 5e23d28 commit ab1b312
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions paper-server/patches/features/0028-Optimize-Hoppers.patch
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ index cc2d442682496197d29ace79b22e6cf6fb7edf5e..ae220a732c78ab076261f20b5a54c71d
/* Drop global time updates
if (this.tickCount % 20 == 0) {
diff --git a/net/minecraft/world/item/ItemStack.java b/net/minecraft/world/item/ItemStack.java
index 0eb9811e573f0c38de3eeb17099872efcbb4c2dd..b511fe8295369ac4014beb351cd2e3f770c10170 100644
index b393be76bead3c66ab0bd8a0e6fd9b9ef81d8e28..76f50437396f8f856381d0fbef52953ef7c263f6 100644
--- a/net/minecraft/world/item/ItemStack.java
+++ b/net/minecraft/world/item/ItemStack.java
@@ -808,10 +808,16 @@ public final class ItemStack implements DataComponentHolder {
@@ -827,10 +827,16 @@ public final class ItemStack implements DataComponentHolder {
}

public ItemStack copy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,33 @@
this.shrink(1);
onBreak.accept(item);
}
@@ -512,9 +_,14 @@
@@ -506,15 +_,39 @@
return;
}

- int min = Math.min(this.getDamageValue() + i, this.getMaxDamage() - 1);
+ int min = Math.min(this.getDamageValue() + i, this.getMaxDamage() - 1); // Paper - Expand PlayerItemDamageEvent - diff on change as min computation is copied post event.
+
+ // Paper start - Expand PlayerItemDamageEvent
+ if (min - this.getDamageValue() > 0) {
+ org.bukkit.event.player.PlayerItemDamageEvent event = new org.bukkit.event.player.PlayerItemDamageEvent(
+ serverPlayer.getBukkitEntity(),
+ org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this),
+ min - this.getDamageValue(),
+ damage
+ );
+ if (!event.callEvent() || event.getDamage() == 0) {
+ return;
+ }
+
+ // Prevent breaking the item in this code path as callers may expect the item to survive
+ // (given the method name)
+ min = Math.min(this.getDamageValue() + event.getDamage(), this.getMaxDamage() - 1);
+ }
+ // Paper end - Expand PlayerItemDamageEvent
+
this.applyDamage(min, serverPlayer, item -> {});
}
}

public void hurtAndBreak(int amount, LivingEntity entity, EquipmentSlot slot) {
Expand Down

0 comments on commit ab1b312

Please sign in to comment.