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:
Dylan T. 2025-06-27 16:08:08 +00:00
parent 7c651928ea
commit e5a38f270c

View File

@ -65,31 +65,18 @@ class BlockLightUpdate extends LightUpdate{
foreach($chunk->getSubChunks() as $subChunkY => $subChunk){
$subChunk->setBlockLightArray(LightArray::fill(0));
$foundLightEmitter = false;
// Check block layer for light emitters
$blockLayer = $subChunk->getBlockLayer();
if($blockLayer !== null){
foreach($blockLayer->getPalette() as $state){
$hasLightEmitter = false;
foreach([$subChunk->getBlockLayer(), $subChunk->getLiquidLayer()] as $layer){
foreach($layer->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);
$foundLightEmitter = true;
break;
$hasLightEmitter = true;
break 2;
}
}
}
// Check liquid layer for light emitters if not found in block layer
if(!$foundLightEmitter){
$liquidLayer = $subChunk->getLiquidLayer();
if($liquidLayer !== null){
foreach($liquidLayer->getPalette() as $state){
if(($this->lightEmitters[$state] ?? 0) > 0){
if($hasLightEmitter){
$lightSources += $this->scanForLightEmittingBlocks($subChunk, $chunkX << SubChunk::COORD_BIT_SIZE, $subChunkY << SubChunk::COORD_BIT_SIZE, $chunkZ << SubChunk::COORD_BIT_SIZE);
break;
}
}
}
}
}