From 0c9946621c25b2a2c226c5b7e5b87645173ced89 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 19 Oct 2018 15:48:46 +0100 Subject: [PATCH] Level: Do not tick chunks which have unloaded adjacent chunks Grass can cause issues here by requesting blocks randomly offset away from itself, which can cause silent chunk loading on chunk ticking. It also causes crashes if chunk autoloading is taken away, which is obviously undesired. It was also noticed that player chunkloaders cause chunks to start getting ticked as soon as they load their first chunk, which is before the entity is visible to everyone else on the server. This is probably undesired behaviour. --- src/pocketmine/level/Level.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 934c240c5..17c39b28c 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -971,13 +971,20 @@ class Level implements ChunkManager, Metadatable{ foreach($this->chunkTickList as $index => $loaders){ Level::getXZ($index, $chunkX, $chunkZ); - if(($chunk = $this->chunks[$index] ?? null) === null){ - unset($this->chunkTickList[$index]); - continue; - }elseif($loaders <= 0){ + for($cx = -1; $cx <= 1; ++$cx){ + for($cz = -1; $cz <= 1; ++$cz){ + if(!isset($this->chunks[Level::chunkHash($chunkX + $cx, $chunkZ + $cz)])){ + unset($this->chunkTickList[$index]); + goto skip_to_next; //no "continue 3" thanks! + } + } + } + + if($loaders <= 0){ unset($this->chunkTickList[$index]); } + $chunk = $this->chunks[$index]; foreach($chunk->getEntities() as $entity){ $entity->scheduleUpdate(); } @@ -1006,6 +1013,8 @@ class Level implements ChunkManager, Metadatable{ } } } + + skip_to_next: //dummy label to break out of nested loops } if($this->clearChunksOnTick){