mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-08-11 22:08:42 +00:00
Clean up BlockLightUpdate::recalculateChunk
- Remove unnecessary null checks for blockLayer and liquidLayer (they are now non-nullable) - Deduplicate code by scanning both layers in a single loop - Simplify logic flow by checking palettes first before scanning blocks
This commit is contained in:
parent
7c651928ea
commit
e5a38f270c
@ -65,31 +65,18 @@ class BlockLightUpdate extends LightUpdate{
|
|||||||
foreach($chunk->getSubChunks() as $subChunkY => $subChunk){
|
foreach($chunk->getSubChunks() as $subChunkY => $subChunk){
|
||||||
$subChunk->setBlockLightArray(LightArray::fill(0));
|
$subChunk->setBlockLightArray(LightArray::fill(0));
|
||||||
|
|
||||||
$foundLightEmitter = false;
|
$hasLightEmitter = false;
|
||||||
|
foreach([$subChunk->getBlockLayer(), $subChunk->getLiquidLayer()] as $layer){
|
||||||
// Check block layer for light emitters
|
foreach($layer->getPalette() as $state){
|
||||||
$blockLayer = $subChunk->getBlockLayer();
|
|
||||||
if($blockLayer !== null){
|
|
||||||
foreach($blockLayer->getPalette() as $state){
|
|
||||||
if(($this->lightEmitters[$state] ?? 0) > 0){
|
if(($this->lightEmitters[$state] ?? 0) > 0){
|
||||||
$lightSources += $this->scanForLightEmittingBlocks($subChunk, $chunkX << SubChunk::COORD_BIT_SIZE, $subChunkY << SubChunk::COORD_BIT_SIZE, $chunkZ << SubChunk::COORD_BIT_SIZE);
|
$hasLightEmitter = true;
|
||||||
$foundLightEmitter = true;
|
break 2;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check liquid layer for light emitters if not found in block layer
|
if($hasLightEmitter){
|
||||||
if(!$foundLightEmitter){
|
$lightSources += $this->scanForLightEmittingBlocks($subChunk, $chunkX << SubChunk::COORD_BIT_SIZE, $subChunkY << SubChunk::COORD_BIT_SIZE, $chunkZ << SubChunk::COORD_BIT_SIZE);
|
||||||
$liquidLayer = $subChunk->getLiquidLayer();
|
|
||||||
if($liquidLayer !== null){
|
|
||||||
foreach($liquidLayer->getPalette() as $state){
|
|
||||||
if(($this->lightEmitters[$state] ?? 0) > 0){
|
|
||||||
$lightSources += $this->scanForLightEmittingBlocks($subChunk, $chunkX << SubChunk::COORD_BIT_SIZE, $subChunkY << SubChunk::COORD_BIT_SIZE, $chunkZ << SubChunk::COORD_BIT_SIZE);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user