mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-27 13:49:55 +00:00
LightUpdate: allow providing effective light levels for propagation, fix #2999
This commit is contained in:
parent
f3f9ebf312
commit
a3b73d95a7
@ -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;
|
||||
}
|
||||
|
@ -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){
|
||||
|
Loading…
x
Reference in New Issue
Block a user