1
0
Fork 0
mirror of https://github.com/PaperMC/Paper.git synced 2025-01-18 23:23:19 +01:00

Call PlayerItemDamageEvent for tridents ()

This commit is contained in:
Tamion 2025-01-13 00:29:52 +01:00 committed by GitHub
parent 5e23d28ad2
commit ab1b312064
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 3 deletions
paper-server/patches
features
sources/net/minecraft/world/item

View file

@ -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() {

View file

@ -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) {