From a5a236084f623dca120fd4bdfe41eb20717cf62d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 22 Jun 2018 14:31:48 +0100 Subject: [PATCH 1/3] Living: don't applyPostDamageEffects() for dead mobs this has already been seen to cause duplication bugs when thorns is used. Anything else that modifies inventory during applyPostDamageEffects() when the mob is possibly dead will also cause duplication issues. --- src/pocketmine/entity/Living.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index 55c2a03ae..b5e409d78 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 */ @@ -551,9 +552,9 @@ abstract class Living extends Entity implements Damageable{ } } - $this->applyPostDamageEffects($source); if($this->isAlive()){ + $this->applyPostDamageEffects($source); $this->doHitAnimation(); }else{ $this->startDeathAnimation(); From 6c6630d8457319c5ec2ef08dd96f4123a9636f2d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 22 Jun 2018 17:17:40 +0100 Subject: [PATCH 2/3] Player: avoid doing some post-melee attack actions if attacking killed the attacker This can happen when an attacker attacks a victim wearing thorns armour while having low health, which prior to this commit would cause the tool to be duplicated. --- src/pocketmine/Player.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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: From 484d34fe040827138731d724cacec295f04e46f5 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 22 Jun 2018 17:47:11 +0100 Subject: [PATCH 3/3] Living: Reset attack cooldown before applying post damage effects this fixes things causing damage during post-damage calls coming back and being able to do even more damage --- src/pocketmine/entity/Living.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index b5e409d78..6202e9ee4 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -535,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){ @@ -552,15 +554,12 @@ abstract class Living extends Entity implements Damageable{ } } - if($this->isAlive()){ $this->applyPostDamageEffects($source); $this->doHitAnimation(); }else{ $this->startDeathAnimation(); } - - $this->attackTime = 10; //0.5 seconds cooldown } protected function doHitAnimation() : void{