From 5dadf123743495142b1636d8c552166f1e139ba3 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 31 May 2020 19:46:51 +0100 Subject: [PATCH] Living: fixed cooldown damage logic, closes #2939 --- src/pocketmine/entity/Living.php | 8 +++----- src/pocketmine/event/entity/EntityDamageEvent.php | 5 +++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index 22b2c791b..c6c9b7be6 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -436,6 +436,9 @@ abstract class Living extends Entity implements Damageable{ * to effects or armour. */ public function applyDamageModifiers(EntityDamageEvent $source) : void{ + if($this->lastDamageCause !== null and $this->attackTime > 0){ + $source->setModifier(-$this->lastDamageCause->getBaseDamage(), EntityDamageEvent::MODIFIER_PREVIOUS_DAMAGE_COOLDOWN); + } if($source->canBeReducedByArmor()){ //MCPE uses the same system as PC did pre-1.9 $source->setModifier(-$source->getFinalDamage() * $this->getArmorPoints() * 0.04, EntityDamageEvent::MODIFIER_ARMOR); @@ -514,11 +517,6 @@ abstract class Living extends Entity implements Damageable{ public function attack(EntityDamageEvent $source) : void{ if($this->noDamageTicks > 0){ $source->setCancelled(); - }elseif($this->attackTime > 0){ - $lastCause = $this->getLastDamageCause(); - if($lastCause !== null and $lastCause->getBaseDamage() >= $source->getBaseDamage()){ - $source->setCancelled(); - } } if($this->hasEffect(Effect::FIRE_RESISTANCE) and ( diff --git a/src/pocketmine/event/entity/EntityDamageEvent.php b/src/pocketmine/event/entity/EntityDamageEvent.php index 6e8c5a21e..065e8c724 100644 --- a/src/pocketmine/event/entity/EntityDamageEvent.php +++ b/src/pocketmine/event/entity/EntityDamageEvent.php @@ -40,6 +40,7 @@ class EntityDamageEvent extends EntityEvent implements Cancellable{ public const MODIFIER_CRITICAL = 7; public const MODIFIER_TOTEM = 8; public const MODIFIER_WEAPON_ENCHANTMENTS = 9; + public const MODIFIER_PREVIOUS_DAMAGE_COOLDOWN = 10; public const CAUSE_CONTACT = 0; public const CAUSE_ENTITY_ATTACK = 1; @@ -181,4 +182,8 @@ 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; + } }