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;
|
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{
|
protected function getHighestAdjacentLight(int $x, int $y, int $z) : int{
|
||||||
$adjacent = 0;
|
$adjacent = 0;
|
||||||
foreach([
|
foreach([
|
||||||
@ -77,7 +84,7 @@ abstract class LightUpdate{
|
|||||||
[$x, $y, $z + 1],
|
[$x, $y, $z + 1],
|
||||||
[$x, $y, $z - 1]
|
[$x, $y, $z - 1]
|
||||||
] as [$x1, $y1, $z1]){
|
] 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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,6 +132,9 @@ abstract class LightUpdate{
|
|||||||
foreach($points as list($cx, $cy, $cz)){
|
foreach($points as list($cx, $cy, $cz)){
|
||||||
if($this->subChunkHandler->moveTo($cx, $cy, $cz, true)){
|
if($this->subChunkHandler->moveTo($cx, $cy, $cz, true)){
|
||||||
$this->computeRemoveLight($cx, $cy, $cz, $oldAdjacentLight);
|
$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)]);
|
unset($this->spreadVisited[World::blockHash($x, $y, $z)]);
|
||||||
|
|
||||||
if(!$this->subChunkHandler->moveTo($x, $y, $z, false)){
|
$newAdjacentLight = $this->getEffectiveLight($x, $y, $z);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$newAdjacentLight = $this->currentLightArray->get($x & 0xf, $y & 0xf, $z & 0xf);
|
|
||||||
if($newAdjacentLight <= 0){
|
if($newAdjacentLight <= 0){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\world\light;
|
namespace pocketmine\world\light;
|
||||||
|
|
||||||
use pocketmine\block\BlockFactory;
|
use pocketmine\block\BlockFactory;
|
||||||
|
use pocketmine\world\World;
|
||||||
use function max;
|
use function max;
|
||||||
|
|
||||||
class SkyLightUpdate extends LightUpdate{
|
class SkyLightUpdate extends LightUpdate{
|
||||||
@ -31,6 +32,14 @@ class SkyLightUpdate extends LightUpdate{
|
|||||||
$this->currentLightArray = $this->subChunkHandler->currentSubChunk->getBlockSkyLightArray();
|
$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{
|
public function recalculateNode(int $x, int $y, int $z) : void{
|
||||||
$chunk = $this->world->getChunk($x >> 4, $z >> 4);
|
$chunk = $this->world->getChunk($x >> 4, $z >> 4);
|
||||||
if($chunk === null){
|
if($chunk === null){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user