Player: fixed crash when stopping using a chunk before it's finished being generated

This commit is contained in:
Dylan K. Taylor 2020-12-04 15:36:43 +00:00
parent 5ba09b6a25
commit e056456dd1

View File

@ -672,11 +672,14 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
$world = $world ?? $this->getWorld();
$index = World::chunkHash($x, $z);
if(isset($this->usedChunks[$index])){
foreach($world->getChunk($x, $z)->getEntities() as $entity){
$chunk = $world->getChunk($x, $z);
if($chunk !== null){ //this might be a chunk that hasn't been generated yet
foreach($chunk->getEntities() as $entity){
if($entity !== $this){
$entity->despawnFrom($this);
}
}
}
$this->networkSession->stopUsingChunk($x, $z);
unset($this->usedChunks[$index]);
}