From 9aadb9a0c980b856d881a3d0e7d5357a01bcb991 Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Sun, 5 Mar 2023 18:48:34 +0100 Subject: [PATCH] Fix cancelling EntityDeathEvent for Armor Stands killed by players (#6478) --- patches/server/Improve-death-events.patch | 41 ++++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/patches/server/Improve-death-events.patch b/patches/server/Improve-death-events.patch index 52b32cacff..190a5a3a21 100644 --- a/patches/server/Improve-death-events.patch +++ b/patches/server/Improve-death-events.patch @@ -14,10 +14,6 @@ to cancel the death which has the benefit of also receiving the dropped items and experience which is otherwise only properly possible by using internal code. -TODO 1.17: this needs to be checked (actually get off your lazy ass and cancel the events) for the following entities, -maybe more (please check patch overrides for drops for more): -- players, armor stands, foxes, chested donkeys/llamas - == AT == public net.minecraft.world.entity.LivingEntity getDeathSound()Lnet/minecraft/sounds/SoundEvent; public net.minecraft.world.entity.LivingEntity getSoundVolume()F @@ -303,6 +299,43 @@ diff --git a/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java +++ b/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java +@@ -0,0 +0,0 @@ public class ArmorStand extends LivingEntity { + this.gameEvent(GameEvent.ENTITY_DAMAGE, source.getEntity()); + this.lastHit = i; + } else { +- this.brokenByPlayer(source); ++ org.bukkit.event.entity.EntityDeathEvent event = this.brokenByPlayer(source); // Paper + this.showBreakingParticles(); +- this.discard(); // CraftBukkit - SPIGOT-4890: remain as this.die() since above damagesource method will call death event ++ if (!event.isCancelled()) this.discard(); // CraftBukkit - SPIGOT-4890: remain as this.die() since above damagesource method will call death event // Paper + } + + return true; +@@ -0,0 +0,0 @@ public class ArmorStand extends LivingEntity { + + } + +- private void brokenByPlayer(DamageSource damageSource) { ++ private org.bukkit.event.entity.EntityDeathEvent brokenByPlayer(DamageSource damageSource) { // Paper + drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(new ItemStack(Items.ARMOR_STAND))); // CraftBukkit - add to drops +- this.brokenByAnything(damageSource); ++ return this.brokenByAnything(damageSource); // Paper + } + +- private void brokenByAnything(DamageSource damageSource) { ++ private org.bukkit.event.entity.EntityDeathEvent brokenByAnything(DamageSource damageSource) { // Paper + this.playBrokenSound(); + // this.dropAllDeathLoot(damagesource); // CraftBukkit - moved down + +@@ -0,0 +0,0 @@ public class ArmorStand extends LivingEntity { + this.armorItems.set(i, ItemStack.EMPTY); + } + } +- this.dropAllDeathLoot(damageSource); // CraftBukkit - moved from above ++ return this.dropAllDeathLoot(damageSource); // CraftBukkit - moved from above // Paper + + } + @@ -0,0 +0,0 @@ public class ArmorStand extends LivingEntity { @Override