Move Entity despawn logic back to Player

this is not network-session specific, and different implementations will need to do this.
This commit is contained in:
Dylan K. Taylor 2019-05-07 18:01:23 +01:00
parent 66481fedeb
commit d7a7ab5102
2 changed files with 6 additions and 5 deletions

View File

@ -956,6 +956,11 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
$world = $world ?? $this->world; $world = $world ?? $this->world;
$index = World::chunkHash($x, $z); $index = World::chunkHash($x, $z);
if(isset($this->usedChunks[$index])){ if(isset($this->usedChunks[$index])){
foreach($this->getWorld()->getChunkEntities($x, $z) as $entity){
if($entity !== $this){
$entity->despawnFrom($this);
}
}
$this->networkSession->stopUsingChunk($x, $z); $this->networkSession->stopUsingChunk($x, $z);
unset($this->usedChunks[$index]); unset($this->usedChunks[$index]);
} }

View File

@ -790,11 +790,7 @@ class NetworkSession{
} }
public function stopUsingChunk(int $chunkX, int $chunkZ) : void{ public function stopUsingChunk(int $chunkX, int $chunkZ) : void{
foreach($this->player->getWorld()->getChunkEntities($chunkX, $chunkZ) as $entity){
if($entity !== $this->player){
$entity->despawnFrom($this->player);
}
}
} }
public function tick() : bool{ public function tick() : bool{