From cb518f98785742a6124a55c880c2950b1dd64c30 Mon Sep 17 00:00:00 2001 From: Bjarne Koll Date: Fri, 12 Jul 2024 09:47:50 +0200 Subject: [PATCH] Only skip damage tick if damage is unmodified zero (#11058) Only skip the damage tick logic on player entities if the original damage was zero and was not modified by plugins down the line. This way all the following three scenarios trigger the damage tick a) vanilla damage was 0, plugin set it to non zero b) vanilla damage was non zero, plugin did not modify it c) vanilla damage was non zero, plugin set it to zero. Regarding case c, the argument here is that EntityDamageEvent#setDamage should not modify the damage tick logic. --- ...vanilla-handling-of-LivingEntity-actuallyH.patch | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/patches/server/Revert-to-vanilla-handling-of-LivingEntity-actuallyH.patch b/patches/server/Revert-to-vanilla-handling-of-LivingEntity-actuallyH.patch index c3aa0a716..b45d4f448 100644 --- a/patches/server/Revert-to-vanilla-handling-of-LivingEntity-actuallyH.patch +++ b/patches/server/Revert-to-vanilla-handling-of-LivingEntity-actuallyH.patch @@ -8,11 +8,20 @@ diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/ma index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/LivingEntity.java +++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java +@@ -0,0 +0,0 @@ public abstract class LivingEntity extends Entity implements Attackable { + } + + this.noActionTime = 0; +- float f1 = amount; ++ float f1 = amount; final float originalAmount = f1; // Paper - revert to vanilla #hurt - OBFHELPER + boolean flag = amount > 0.0F && this.isDamageSourceBlocked(source); // Copied from below + float f2 = 0.0F; + @@ -0,0 +0,0 @@ public abstract class LivingEntity extends Entity implements Attackable { if (!this.actuallyHurt(source, (float) event.getFinalDamage() - this.lastHurt, event)) { return false; } -+ if (this instanceof ServerPlayer && event.getDamage() == 0) return false; // Paper - revert to vanilla damage - players are not affected by damage that is 0 - use raw damage here, as it is just the original amount but post plugin changes to it. ++ if (this instanceof ServerPlayer && event.getDamage() == 0 && originalAmount == 0) return false; // Paper - revert to vanilla damage - players are not affected by damage that is 0 - skip damage if the vanilla damage is 0 and was not modified by plugins in the event. // CraftBukkit end this.lastHurt = amount; flag1 = false; @@ -20,7 +29,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 if (!this.actuallyHurt(source, (float) event.getFinalDamage(), event)) { return false; } -+ if (this instanceof ServerPlayer && event.getDamage() == 0) return false; // Paper - revert to vanilla damage - players are not affected by damage that is 0 - use raw damage here, as it is just the original amount but post plugin changes to it. ++ if (this instanceof ServerPlayer && event.getDamage() == 0 && originalAmount == 0) return false; // Paper - revert to vanilla damage - players are not affected by damage that is 0 - skip damage if the vanilla damage is 0 and was not modified by plugins in the event. this.lastHurt = amount; this.invulnerableTime = this.invulnerableDuration; // CraftBukkit - restore use of maxNoDamageTicks // this.actuallyHurt(damagesource, f);