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.
This commit is contained in:
Dylan K. Taylor 2020-06-02 10:05:42 +01:00
parent b48243fd09
commit d554d8060b

View File

@ -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;
}
}