From a3b73d95a755ea9615b9eae5f47aba2311c1af96 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 23 Oct 2019 21:01:19 +0100 Subject: [PATCH] LightUpdate: allow providing effective light levels for propagation, fix #2999 --- src/world/light/LightUpdate.php | 18 ++++++++++++------ src/world/light/SkyLightUpdate.php | 9 +++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/world/light/LightUpdate.php b/src/world/light/LightUpdate.php index b608f475a0..c91a68ac47 100644 --- a/src/world/light/LightUpdate.php +++ b/src/world/light/LightUpdate.php @@ -67,6 +67,13 @@ abstract class LightUpdate{ abstract public function recalculateNode(int $x, int $y, int $z) : void; + protected function getEffectiveLight(int $x, int $y, int $z) : int{ + if($this->subChunkHandler->moveTo($x, $y, $z, false)){ + return $this->currentLightArray->get($x & 0xf, $y & 0xf, $z & 0xf); + } + return 0; + } + protected function getHighestAdjacentLight(int $x, int $y, int $z) : int{ $adjacent = 0; foreach([ @@ -77,7 +84,7 @@ abstract class LightUpdate{ [$x, $y, $z + 1], [$x, $y, $z - 1] ] as [$x1, $y1, $z1]){ - if($this->subChunkHandler->moveTo($x1, $y1, $z1, false) and ($adjacent = max($adjacent, $this->currentLightArray->get($x1 & 0xf, $y1 & 0xf, $z1 & 0xf))) === 15){ + if(($adjacent = max($adjacent, $this->getEffectiveLight($x1, $y1, $z1))) === 15){ break; } } @@ -125,6 +132,9 @@ abstract class LightUpdate{ foreach($points as list($cx, $cy, $cz)){ if($this->subChunkHandler->moveTo($cx, $cy, $cz, true)){ $this->computeRemoveLight($cx, $cy, $cz, $oldAdjacentLight); + }elseif($this->getEffectiveLight($cx, $cy, $cz) > 0 and !isset($this->spreadVisited[$index = World::blockHash($cx, $cy, $cz)])){ + $this->spreadVisited[$index] = true; + $this->spreadQueue->enqueue([$cx, $cy, $cz]); } } } @@ -134,11 +144,7 @@ abstract class LightUpdate{ unset($this->spreadVisited[World::blockHash($x, $y, $z)]); - if(!$this->subChunkHandler->moveTo($x, $y, $z, false)){ - continue; - } - - $newAdjacentLight = $this->currentLightArray->get($x & 0xf, $y & 0xf, $z & 0xf); + $newAdjacentLight = $this->getEffectiveLight($x, $y, $z); if($newAdjacentLight <= 0){ continue; } diff --git a/src/world/light/SkyLightUpdate.php b/src/world/light/SkyLightUpdate.php index 59ab9e98c4..f06b2b3c88 100644 --- a/src/world/light/SkyLightUpdate.php +++ b/src/world/light/SkyLightUpdate.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\world\light; use pocketmine\block\BlockFactory; +use pocketmine\world\World; use function max; class SkyLightUpdate extends LightUpdate{ @@ -31,6 +32,14 @@ class SkyLightUpdate extends LightUpdate{ $this->currentLightArray = $this->subChunkHandler->currentSubChunk->getBlockSkyLightArray(); } + protected function getEffectiveLight(int $x, int $y, int $z) : int{ + if($y >= World::Y_MAX){ + $this->subChunkHandler->invalidate(); + return 15; + } + return parent::getEffectiveLight($x, $y, $z); + } + public function recalculateNode(int $x, int $y, int $z) : void{ $chunk = $this->world->getChunk($x >> 4, $z >> 4); if($chunk === null){