fixed misusing isAlive(), close #1523

This commit is contained in:
Dylan K. Taylor 2017-11-07 09:32:38 +00:00
parent 99f06c6c18
commit 0e64c3dad8
6 changed files with 10 additions and 6 deletions

View File

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

View File

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

View File

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

View File

@ -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){

View File

@ -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){

View File

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