diff --git a/src/world/format/Chunk.php b/src/world/format/Chunk.php index c1ab0db60..09c329b61 100644 --- a/src/world/format/Chunk.php +++ b/src/world/format/Chunk.php @@ -26,7 +26,6 @@ declare(strict_types=1); namespace pocketmine\world\format; -use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; use pocketmine\block\tile\Tile; use pocketmine\block\tile\TileFactory; @@ -279,11 +278,16 @@ class Chunk{ /** * Recalculates the heightmap for the whole chunk. + * + * @param \SplFixedArray|int[] $lightFilters + * @param \SplFixedArray|bool[] $lightDiffusers + * @phpstan-param \SplFixedArray $lightFilters + * @phpstan-param \SplFixedArray $lightDiffusers */ - public function recalculateHeightMap() : void{ + public function recalculateHeightMap(\SplFixedArray $lightFilters, \SplFixedArray $lightDiffusers) : void{ for($z = 0; $z < 16; ++$z){ for($x = 0; $x < 16; ++$x){ - $this->recalculateHeightMapColumn($x, $z); + $this->recalculateHeightMapColumn($x, $z, $lightFilters, $lightDiffusers); } } } @@ -293,13 +297,17 @@ class Chunk{ * * @param int $x 0-15 * @param int $z 0-15 + * @param \SplFixedArray|int[] $lightFilters + * @param \SplFixedArray|bool[] $lightDiffusers + * @phpstan-param \SplFixedArray $lightFilters + * @phpstan-param \SplFixedArray $lightDiffusers * * @return int New calculated heightmap value (0-256 inclusive) */ - public function recalculateHeightMapColumn(int $x, int $z) : int{ + public function recalculateHeightMapColumn(int $x, int $z, \SplFixedArray $lightFilters, \SplFixedArray $lightDiffusers) : int{ $y = $this->getHighestBlockAt($x, $z); for(; $y >= 0; --$y){ - if(BlockFactory::$lightFilter[$state = $this->getFullBlock($x, $y, $z)] > 1 or BlockFactory::$diffusesSkyLight[$state]){ + if($lightFilters[$state = $this->getFullBlock($x, $y, $z)] > 1 or $lightDiffusers[$state]){ break; } } @@ -313,9 +321,12 @@ class Chunk{ * This does not cater for adjacent sky light, this performs direct sky light population only. This may cause some strange visual artifacts * if the chunk is light-populated after being terrain-populated. * + * @param \SplFixedArray|int[] $lightFilters + * @phpstan-param \SplFixedArray $lightFilters + * * TODO: fast adjacent light spread */ - public function populateSkyLight() : void{ + public function populateSkyLight(\SplFixedArray $lightFilters) : void{ $this->setAllBlockSkyLight(0); for($x = 0; $x < 16; ++$x){ @@ -329,7 +340,7 @@ class Chunk{ $light = 15; for(; $y >= 0; --$y){ - $light -= BlockFactory::$lightFilter[$this->getFullBlock($x, $y, $z)]; + $light -= $lightFilters[$this->getFullBlock($x, $y, $z)]; if($light <= 0){ break; } diff --git a/src/world/generator/PopulationTask.php b/src/world/generator/PopulationTask.php index bfe22168b..a6b79ca71 100644 --- a/src/world/generator/PopulationTask.php +++ b/src/world/generator/PopulationTask.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\world\generator; +use pocketmine\block\BlockFactory; use pocketmine\scheduler\AsyncTask; use pocketmine\world\format\Chunk; use pocketmine\world\format\io\FastChunkSerializer; @@ -118,8 +119,8 @@ class PopulationTask extends AsyncTask{ $chunk = $manager->getChunk($chunk->getX(), $chunk->getZ()); $chunk->setPopulated(); - $chunk->recalculateHeightMap(); - $chunk->populateSkyLight(); + $chunk->recalculateHeightMap(BlockFactory::$lightFilter, BlockFactory::$diffusesSkyLight); + $chunk->populateSkyLight(BlockFactory::$lightFilter); $chunk->setLightPopulated(); $this->chunk = FastChunkSerializer::serialize($chunk); diff --git a/src/world/light/LightPopulationTask.php b/src/world/light/LightPopulationTask.php index 37989dd25..0fd0b40d6 100644 --- a/src/world/light/LightPopulationTask.php +++ b/src/world/light/LightPopulationTask.php @@ -63,8 +63,8 @@ class LightPopulationTask extends AsyncTask{ /** @var Chunk $chunk */ $chunk = FastChunkSerializer::deserialize($this->chunk); - $chunk->recalculateHeightMap(); - $chunk->populateSkyLight(); + $chunk->recalculateHeightMap(BlockFactory::$lightFilter, BlockFactory::$diffusesSkyLight); + $chunk->populateSkyLight(BlockFactory::$lightFilter); $chunk->setLightPopulated(); $this->resultHeightMap = igbinary_serialize($chunk->getHeightMapArray()); diff --git a/src/world/light/SkyLightUpdate.php b/src/world/light/SkyLightUpdate.php index f06b2b3c8..74eba4031 100644 --- a/src/world/light/SkyLightUpdate.php +++ b/src/world/light/SkyLightUpdate.php @@ -51,7 +51,7 @@ class SkyLightUpdate extends LightUpdate{ $yPlusOne = $y + 1; if($yPlusOne === $oldHeightMap){ //Block changed directly beneath the heightmap. Check if a block was removed or changed to a different light-filter. - $newHeightMap = $chunk->recalculateHeightMapColumn($x & 0x0f, $z & 0x0f); + $newHeightMap = $chunk->recalculateHeightMapColumn($x & 0x0f, $z & 0x0f, BlockFactory::$lightFilter, BlockFactory::$diffusesSkyLight); }elseif($yPlusOne > $oldHeightMap){ //Block changed above the heightmap. if($source->getLightFilter() > 0 or $source->diffusesSkyLight()){ $chunk->setHeightMap($x & 0xf, $z & 0xf, $yPlusOne);