From d554d8060b509fad43a8aa353eccd5a72516c301 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 2 Jun 2020 10:05:42 +0100 Subject: [PATCH] fixed absorption hearts not being consumed, closes #3546 this was caused by a bad fix for switching. we can't consider zero-damage attacks as cancelled because zero-damage might have been the result of things like consuming absorption hearts, so the aftereffects need to be processed even when the net damage is zero. --- src/pocketmine/event/entity/EntityDamageEvent.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/pocketmine/event/entity/EntityDamageEvent.php b/src/pocketmine/event/entity/EntityDamageEvent.php index 065e8c724..ecc651f52 100644 --- a/src/pocketmine/event/entity/EntityDamageEvent.php +++ b/src/pocketmine/event/entity/EntityDamageEvent.php @@ -26,6 +26,7 @@ namespace pocketmine\event\entity; use pocketmine\entity\Entity; use pocketmine\event\Cancellable; use function array_sum; +use function max; /** * Called when an entity takes damage. @@ -144,7 +145,7 @@ class EntityDamageEvent extends EntityEvent implements Cancellable{ } public function getFinalDamage() : float{ - return $this->baseDamage + array_sum($this->modifiers); + return max(0, $this->baseDamage + array_sum($this->modifiers)); } /** @@ -182,8 +183,4 @@ class EntityDamageEvent extends EntityEvent implements Cancellable{ public function setAttackCooldown(int $attackCooldown) : void{ $this->attackCooldown = $attackCooldown; } - - public function isCancelled() : bool{ - return parent::isCancelled() or $this->getFinalDamage() <= 0; - } }