diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index c245fa2b2..9f7209b97 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2529,11 +2529,15 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - if($heldItem->onAttackEntity($target) and $this->isSurvival()){ //always fire the hook, even if we are survival - $this->inventory->setItemInHand($heldItem); - } + if($this->isAlive()){ + //reactive damage like thorns might cause us to be killed by attacking another mob, which + //would mean we'd already have dropped the inventory by the time we reached here + if($heldItem->onAttackEntity($target) and $this->isSurvival()){ //always fire the hook, even if we are survival + $this->inventory->setItemInHand($heldItem); + } - $this->exhaust(0.3, PlayerExhaustEvent::CAUSE_ATTACK); + $this->exhaust(0.3, PlayerExhaustEvent::CAUSE_ATTACK); + } return true; default: diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index 55c2a03ae..6202e9ee4 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -469,6 +469,7 @@ abstract class Living extends Entity implements Damageable{ /** * Called after EntityDamageEvent execution to apply post-hurt effects, such as reducing absorption or modifying * armour durability. + * This will not be called by damage sources causing death. * * @param EntityDamageEvent $source */ @@ -534,6 +535,8 @@ abstract class Living extends Entity implements Damageable{ return; } + $this->attackTime = 10; //0.5 seconds cooldown + if($source instanceof EntityDamageByEntityEvent){ $e = $source->getDamager(); if($source instanceof EntityDamageByChildEntityEvent){ @@ -551,15 +554,12 @@ abstract class Living extends Entity implements Damageable{ } } - $this->applyPostDamageEffects($source); - if($this->isAlive()){ + $this->applyPostDamageEffects($source); $this->doHitAnimation(); }else{ $this->startDeathAnimation(); } - - $this->attackTime = 10; //0.5 seconds cooldown } protected function doHitAnimation() : void{