diff --git a/src/world/World.php b/src/world/World.php index ef37149d9..f21fdbd63 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -895,7 +895,13 @@ class World implements ChunkManager{ $dz = mt_rand(-$randRange, $randRange); $hash = World::chunkHash($dx + $chunkX, $dz + $chunkZ); if(!isset($chunkTickList[$hash]) and isset($this->chunks[$hash])){ - if(!$this->chunks[$hash]->isLightPopulated()){ + //TODO: this might need to be checked after adjacent chunks are loaded in future + $lightPopulatedState = $this->chunks[$hash]->isLightPopulated(); + if($lightPopulatedState !== true){ + if($lightPopulatedState === false){ + $this->chunks[$hash]->setLightPopulated(null); + $this->server->getAsyncPool()->submitTask(new LightPopulationTask($this, $this->chunks[$hash])); + } continue; } //check adjacent chunks are loaded @@ -2143,10 +2149,6 @@ class World implements ChunkManager{ (new ChunkLoadEvent($this, $chunk, !$chunk->isGenerated()))->call(); - if($chunk->isPopulated()){ - $this->getServer()->getAsyncPool()->submitTask(new LightPopulationTask($this, $chunk)); - } - if(!$this->isChunkInUse($x, $z)){ $this->logger->debug("Newly loaded chunk $x $z has no loaders registered, will be unloaded at next available opportunity"); $this->unloadChunkRequest($x, $z); diff --git a/src/world/format/Chunk.php b/src/world/format/Chunk.php index 0b76f0076..59602ce5a 100644 --- a/src/world/format/Chunk.php +++ b/src/world/format/Chunk.php @@ -58,7 +58,7 @@ class Chunk{ /** @var int */ private $dirtyFlags = 0; - /** @var bool */ + /** @var bool|null */ protected $lightPopulated = false; /** @var bool */ protected $terrainGenerated = false; @@ -387,11 +387,11 @@ class Chunk{ $this->dirtyFlags |= self::DIRTY_FLAG_BIOMES; } - public function isLightPopulated() : bool{ + public function isLightPopulated() : ?bool{ return $this->lightPopulated; } - public function setLightPopulated(bool $value = true) : void{ + public function setLightPopulated(?bool $value = true) : void{ $this->lightPopulated = $value; } diff --git a/src/world/format/io/FastChunkSerializer.php b/src/world/format/io/FastChunkSerializer.php index 242caebb8..a69ee4cbb 100644 --- a/src/world/format/io/FastChunkSerializer.php +++ b/src/world/format/io/FastChunkSerializer.php @@ -59,7 +59,7 @@ final class FastChunkSerializer{ * TODO: tiles and entities */ public static function serialize(Chunk $chunk, bool $includeLight = true) : string{ - $includeLight = $includeLight && $chunk->isLightPopulated(); + $includeLight = $includeLight && $chunk->isLightPopulated() === true; $stream = new BinaryStream(); $stream->putInt($chunk->getX()); diff --git a/src/world/light/LightPopulationTask.php b/src/world/light/LightPopulationTask.php index adfa76983..61d839be7 100644 --- a/src/world/light/LightPopulationTask.php +++ b/src/world/light/LightPopulationTask.php @@ -53,6 +53,7 @@ class LightPopulationTask extends AsyncTask{ public function __construct(World $world, Chunk $chunk){ $this->storeLocal(self::TLS_KEY_WORLD, $world); [$this->chunkX, $this->chunkZ] = [$chunk->getX(), $chunk->getZ()]; + $chunk->setLightPopulated(null); $this->chunk = FastChunkSerializer::serialize($chunk); }