2021-08-10 07:04:44 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
|
|
Date: Tue, 22 Dec 2020 13:52:48 -0800
|
2024-01-19 13:22:30 +01:00
|
|
|
Subject: [PATCH] Add EntityDamageItemEvent
|
2021-08-10 07:04:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
|
2024-04-27 04:09:42 +02:00
|
|
|
index 1fe34b2b160569b41ce87910eff56d590731e708..f5547caeaeeb8fa37f2aa9bfea6f176b1cc3430a 100644
|
2021-08-10 07:04:44 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
|
2024-04-27 00:08:35 +02:00
|
|
|
@@ -647,7 +647,7 @@ public final class ItemStack implements DataComponentHolder {
|
2024-04-24 17:27:28 +02:00
|
|
|
return (Integer) this.getOrDefault(DataComponents.MAX_DAMAGE, 0);
|
2021-08-10 07:04:44 +02:00
|
|
|
}
|
|
|
|
|
2024-04-24 17:27:28 +02:00
|
|
|
- public void hurtAndBreak(int amount, RandomSource random, @Nullable ServerPlayer player, Runnable breakCallback) {
|
|
|
|
+ public void hurtAndBreak(int amount, RandomSource random, @Nullable LivingEntity player, Runnable breakCallback) { // Paper - Add EntityDamageItemEvent
|
|
|
|
if (this.isDamageableItem()) {
|
|
|
|
int j;
|
|
|
|
|
2024-04-27 00:08:35 +02:00
|
|
|
@@ -663,8 +663,8 @@ public final class ItemStack implements DataComponentHolder {
|
2021-08-10 07:04:44 +02:00
|
|
|
|
|
|
|
amount -= k;
|
|
|
|
// CraftBukkit start
|
|
|
|
- if (player != null) {
|
|
|
|
- PlayerItemDamageEvent event = new PlayerItemDamageEvent(player.getBukkitEntity(), CraftItemStack.asCraftMirror(this), amount);
|
2024-01-19 13:22:30 +01:00
|
|
|
+ if (player instanceof ServerPlayer serverPlayer) { // Paper - Add EntityDamageItemEvent
|
|
|
|
+ PlayerItemDamageEvent event = new PlayerItemDamageEvent(serverPlayer.getBukkitEntity(), CraftItemStack.asCraftMirror(this), amount); // Paper - Add EntityDamageItemEvent
|
2021-08-10 07:04:44 +02:00
|
|
|
event.getPlayer().getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (amount != event.getDamage() || event.isCancelled()) {
|
2024-04-27 00:08:35 +02:00
|
|
|
@@ -675,6 +675,14 @@ public final class ItemStack implements DataComponentHolder {
|
2021-08-10 07:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
amount = event.getDamage();
|
2024-01-19 13:22:30 +01:00
|
|
|
+ // Paper start - Add EntityDamageItemEvent
|
2021-08-10 07:04:44 +02:00
|
|
|
+ } else if (player != null) {
|
|
|
|
+ io.papermc.paper.event.entity.EntityDamageItemEvent event = new io.papermc.paper.event.entity.EntityDamageItemEvent(player.getBukkitLivingEntity(), CraftItemStack.asCraftMirror(this), amount);
|
|
|
|
+ if (!event.callEvent()) {
|
2024-04-25 21:40:53 +02:00
|
|
|
+ return;
|
2021-08-10 07:04:44 +02:00
|
|
|
+ }
|
|
|
|
+ amount = event.getDamage();
|
2024-01-19 13:22:30 +01:00
|
|
|
+ // Paper end - Add EntityDamageItemEvent
|
2021-08-10 07:04:44 +02:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
if (amount <= 0) {
|
2024-04-27 00:08:35 +02:00
|
|
|
@@ -682,8 +690,8 @@ public final class ItemStack implements DataComponentHolder {
|
2021-08-10 07:04:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- if (player != null && amount != 0) {
|
|
|
|
- CriteriaTriggers.ITEM_DURABILITY_CHANGED.trigger(player, this, this.getDamageValue() + amount);
|
2024-01-19 13:22:30 +01:00
|
|
|
+ if (player instanceof ServerPlayer serverPlayer && amount != 0) { // Paper - Add EntityDamageItemEvent
|
|
|
|
+ CriteriaTriggers.ITEM_DURABILITY_CHANGED.trigger(serverPlayer, this, this.getDamageValue() + amount); // Paper - Add EntityDamageItemEvent
|
2021-08-10 07:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
j = this.getDamageValue() + amount;
|
2024-04-27 00:08:35 +02:00
|
|
|
@@ -716,7 +724,7 @@ public final class ItemStack implements DataComponentHolder {
|
2024-04-24 17:27:28 +02:00
|
|
|
entityplayer = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
- this.hurtAndBreak(amount, randomsource, entityplayer, () -> {
|
|
|
|
+ this.hurtAndBreak(amount, randomsource, entity, () -> { // Paper - Add EntityDamageItemEvent
|
|
|
|
entity.broadcastBreakEvent(slot);
|
|
|
|
Item item = this.getItem();
|
|
|
|
// CraftBukkit start - Check for item breaking
|