diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 93bd09551..743e9d81b 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -980,7 +980,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ foreach($this->usedChunks as $index => $c){ Level::getXZ($index, $chunkX, $chunkZ); foreach($this->level->getChunkEntities($chunkX, $chunkZ) as $entity){ - if($entity !== $this and !$entity->isClosed() and $entity->isAlive()){ + if($entity !== $this and !$entity->isClosed() and $entity->isAlive() and !$entity->isFlaggedForDespawn()){ $entity->spawnTo($this); } } @@ -1451,7 +1451,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ foreach($this->level->getNearbyEntities($this->boundingBox->grow(1, 0.5, 1), $this) as $entity){ $entity->scheduleUpdate(); - if(!$entity->isAlive()){ + if(!$entity->isAlive() or $entity->isFlaggedForDespawn()){ continue; } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index f9631603f..8916ccb87 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1944,6 +1944,10 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ $this->needsDespawn = true; } + public function isFlaggedForDespawn() : bool{ + return $this->needsDespawn; + } + /** * Returns whether the entity has been "closed". * @return bool diff --git a/src/pocketmine/entity/FallingSand.php b/src/pocketmine/entity/FallingSand.php index 2f72ee76c..7ce9f7200 100644 --- a/src/pocketmine/entity/FallingSand.php +++ b/src/pocketmine/entity/FallingSand.php @@ -93,7 +93,7 @@ class FallingSand extends Entity{ $hasUpdate = parent::entityBaseTick($tickDiff); - if($this->isAlive()){ + if(!$this->isFlaggedForDespawn()){ $pos = Position::fromObject($this->add(-$this->width / 2, $this->height, -$this->width / 2)->floor(), $this->getLevel()); $this->block->position($pos); diff --git a/src/pocketmine/entity/Item.php b/src/pocketmine/entity/Item.php index 181fb922d..e8b0b4baf 100644 --- a/src/pocketmine/entity/Item.php +++ b/src/pocketmine/entity/Item.php @@ -105,7 +105,7 @@ class Item extends Entity{ $hasUpdate = parent::entityBaseTick($tickDiff); - if($this->isAlive()){ + if(!$this->isFlaggedForDespawn()){ if($this->pickupDelay > 0 and $this->pickupDelay < 32767){ //Infinite delay $this->pickupDelay -= $tickDiff; if($this->pickupDelay < 0){ diff --git a/src/pocketmine/entity/PrimedTNT.php b/src/pocketmine/entity/PrimedTNT.php index 71d1023ad..783067bbc 100644 --- a/src/pocketmine/entity/PrimedTNT.php +++ b/src/pocketmine/entity/PrimedTNT.php @@ -87,7 +87,7 @@ class PrimedTNT extends Entity implements Explosive{ $this->setDataProperty(self::DATA_FUSE_LENGTH, self::DATA_TYPE_INT, $this->fuse); } - if($this->isAlive()){ + if(!$this->isFlaggedForDespawn()){ $this->fuse -= $tickDiff; if($this->fuse <= 0){ diff --git a/src/pocketmine/entity/projectile/Projectile.php b/src/pocketmine/entity/projectile/Projectile.php index 70e1bf9a2..7ec665d62 100644 --- a/src/pocketmine/entity/projectile/Projectile.php +++ b/src/pocketmine/entity/projectile/Projectile.php @@ -121,7 +121,7 @@ abstract class Projectile extends Entity{ $hasUpdate = parent::entityBaseTick($tickDiff); - if($this->isAlive()){ + if(!$this->isFlaggedForDespawn()){ $movingObjectPosition = null; $moveVector = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ);