Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ItemDamageEvents called for 0 damage #11555

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions patches/server/0570-Add-EntityDamageItemEvent.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Add EntityDamageItemEvent


diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index f00b756fe5dad616323e3b11e35e27353f347042..8c9ae9ac38def29ae4cd8944395e566e434d46d0 100644
index f00b756fe5dad616323e3b11e35e27353f347042..55fb8f14f85efd589cc43c772dcb926646609691 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -692,11 +692,11 @@ public final class ItemStack implements DataComponentHolder {
@@ -692,11 +692,15 @@ public final class ItemStack implements DataComponentHolder {
return this.isDamageableItem() && this.getDamageValue() >= this.getMaxDamage() - 1;
}

Expand All @@ -18,12 +18,16 @@ index f00b756fe5dad616323e3b11e35e27353f347042..8c9ae9ac38def29ae4cd8944395e566e
// CraftBukkit start
- if (player != null) {
- PlayerItemDamageEvent event = new PlayerItemDamageEvent(player.getBukkitEntity(), CraftItemStack.asCraftMirror(this), j);
+ if (player instanceof final ServerPlayer serverPlayer) { // Paper - Add EntityDamageItemEvent
+ // Paper start - Add EntityDamageItemEvent
+ if (j == 0) {
+ return;
+ } else if (player instanceof final ServerPlayer serverPlayer) {
+ // Paper end - Add EntityDamageItemEvent
+ PlayerItemDamageEvent event = new PlayerItemDamageEvent(serverPlayer.getBukkitEntity(), CraftItemStack.asCraftMirror(this), j); // Paper - Add EntityDamageItemEvent
event.getPlayer().getServer().getPluginManager().callEvent(event);

if (j != event.getDamage() || event.isCancelled()) {
@@ -707,6 +707,14 @@ public final class ItemStack implements DataComponentHolder {
@@ -707,30 +711,38 @@ public final class ItemStack implements DataComponentHolder {
}

j = event.getDamage();
Expand All @@ -38,7 +42,10 @@ index f00b756fe5dad616323e3b11e35e27353f347042..8c9ae9ac38def29ae4cd8944395e566e
}
// CraftBukkit end

@@ -716,21 +724,21 @@ public final class ItemStack implements DataComponentHolder {
- if (j != 0) {
+ if (j != 0) { // Paper - Add EntityDamageItemEvent
this.applyDamage(this.getDamageValue() + j, player, breakCallback);
}

}

Expand Down Expand Up @@ -67,7 +74,7 @@ index f00b756fe5dad616323e3b11e35e27353f347042..8c9ae9ac38def29ae4cd8944395e566e
}
// CraftBukkit end

@@ -768,7 +776,7 @@ public final class ItemStack implements DataComponentHolder {
@@ -768,7 +780,7 @@ public final class ItemStack implements DataComponentHolder {
entityplayer = null;
}

Expand Down
10 changes: 7 additions & 3 deletions patches/server/0686-Expand-PlayerItemDamageEvent.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ Subject: [PATCH] Expand PlayerItemDamageEvent


diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index a100c7a53b4b1dac0a01ee65418d44297bcdb93f..bcb3a45166e5dd75dd727adf92304b3a75399c8d 100644
index 9cca3bbff57885380bda2dbe19b8fefe4ae2c1ac..2b0e8a159cf0765c6c93928384cd2ca2eb211e2a 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -693,10 +693,11 @@ public final class ItemStack implements DataComponentHolder {
@@ -693,6 +693,7 @@ public final class ItemStack implements DataComponentHolder {
}

public void hurtAndBreak(int amount, ServerLevel world, @Nullable LivingEntity player, Consumer<Item> breakCallback) { // Paper - Add EntityDamageItemEvent
+ int originalDamage = amount; // Paper - Expand PlayerItemDamageEvent
int j = this.processDurabilityChange(amount, world, player);
// CraftBukkit start
if (player instanceof final ServerPlayer serverPlayer) { // Paper - Add EntityDamageItemEvent
// Paper start - Add EntityDamageItemEvent
@@ -700,7 +701,7 @@ public final class ItemStack implements DataComponentHolder {
return;
} else if (player instanceof final ServerPlayer serverPlayer) {
// Paper end - Add EntityDamageItemEvent
- PlayerItemDamageEvent event = new PlayerItemDamageEvent(serverPlayer.getBukkitEntity(), CraftItemStack.asCraftMirror(this), j); // Paper - Add EntityDamageItemEvent
+ PlayerItemDamageEvent event = new PlayerItemDamageEvent(serverPlayer.getBukkitEntity(), CraftItemStack.asCraftMirror(this), j, originalDamage); // Paper - Add EntityDamageItemEvent
event.getPlayer().getServer().getPluginManager().callEvent(event);
Expand Down
12 changes: 6 additions & 6 deletions patches/server/0762-ItemStack-damage-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ 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 bcb3a45166e5dd75dd727adf92304b3a75399c8d..90a55f00c36903d52630c51bf69322973a2b5274 100644
index 13a7c23a7bee6be0ac14ba69b80dc54e5c18de93..a1c8e3ec97394880d9abe789d0025d0c6d21ad95 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -693,8 +693,13 @@ public final class ItemStack implements DataComponentHolder {
Expand All @@ -27,9 +27,9 @@ index bcb3a45166e5dd75dd727adf92304b3a75399c8d..90a55f00c36903d52630c51bf6932297
- int j = this.processDurabilityChange(amount, world, player);
+ int j = this.processDurabilityChange(amount, world, player, force); // Paper
// CraftBukkit start
if (player instanceof final ServerPlayer serverPlayer) { // Paper - Add EntityDamageItemEvent
PlayerItemDamageEvent event = new PlayerItemDamageEvent(serverPlayer.getBukkitEntity(), CraftItemStack.asCraftMirror(this), j, originalDamage); // Paper - Add EntityDamageItemEvent
@@ -726,7 +731,12 @@ public final class ItemStack implements DataComponentHolder {
// Paper start - Add EntityDamageItemEvent
if (j == 0) {
@@ -730,7 +735,12 @@ public final class ItemStack implements DataComponentHolder {
}

private int processDurabilityChange(int baseDamage, ServerLevel world, @Nullable LivingEntity player) { // Paper - Add EntityDamageItemEvent
Expand All @@ -43,7 +43,7 @@ index bcb3a45166e5dd75dd727adf92304b3a75399c8d..90a55f00c36903d52630c51bf6932297
}

private void applyDamage(int damage, @Nullable LivingEntity player, Consumer<Item> breakCallback) { // Paper - Add EntityDamageItemEvent
@@ -766,6 +776,11 @@ public final class ItemStack implements DataComponentHolder {
@@ -770,6 +780,11 @@ public final class ItemStack implements DataComponentHolder {
}

public void hurtAndBreak(int amount, LivingEntity entity, EquipmentSlot slot) {
Expand All @@ -55,7 +55,7 @@ index bcb3a45166e5dd75dd727adf92304b3a75399c8d..90a55f00c36903d52630c51bf6932297
Level world = entity.level();

if (world instanceof ServerLevel worldserver) {
@@ -778,8 +793,8 @@ public final class ItemStack implements DataComponentHolder {
@@ -782,8 +797,8 @@ public final class ItemStack implements DataComponentHolder {
}

this.hurtAndBreak(amount, worldserver, entity, (item) -> { // Paper - Add EntityDamageItemEvent
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0953-General-ItemMeta-fixes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public net/minecraft/world/level/block/entity/BlockEntity saveId(Lnet/minecraft/
Co-authored-by: GhastCraftHD <[email protected]>

diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index 98b5208baeaa12a5ff2788e457c542000d6ea48b..babd89f39c43b0c64709d99bf8aca6cdc6ca1b24 100644
index b5f9e0ef87d07515ca277e48ec523b1d4e9fa0a6..217280ec6e6f27dcb31978ee6a19f9ff7983bdd1 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -1361,6 +1361,11 @@ public final class ItemStack implements DataComponentHolder {
@@ -1365,6 +1365,11 @@ public final class ItemStack implements DataComponentHolder {
public void setItem(Item item) {
this.bukkitStack = null; // Paper
this.item = item;
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0983-Optimize-Hoppers.patch
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ index b13b3991292ab96542ba390f3e8e3ff0d7529c44..ff6f2dc31bbbaa420323a68282cb1ee3
gameprofilerfiller.push(() -> {
String s = String.valueOf(worldserver);
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index 947e2a3620d73569552c5185664b7564e908007e..33e7d2884195677c4d6340d8b84c1dd85c636ec1 100644
index b72519fc7744c4565d30face4a650fbe1f758110..445db1f17225d7606410623c1dbaba74295091a2 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -881,10 +881,16 @@ public final class ItemStack implements DataComponentHolder {
@@ -885,10 +885,16 @@ public final class ItemStack implements DataComponentHolder {
}

public ItemStack copy() {
Expand Down
Loading