From e5a38f270c42b7e76d94f03229fa4ee634a0a218 Mon Sep 17 00:00:00 2001 From: "Dylan T." Date: Fri, 27 Jun 2025 16:08:08 +0000 Subject: [PATCH] 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 --- src/world/light/BlockLightUpdate.php | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/world/light/BlockLightUpdate.php b/src/world/light/BlockLightUpdate.php index 06efa6abf..9fb804dd0 100644 --- a/src/world/light/BlockLightUpdate.php +++ b/src/world/light/BlockLightUpdate.php @@ -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){ - $lightSources += $this->scanForLightEmittingBlocks($subChunk, $chunkX << SubChunk::COORD_BIT_SIZE, $subChunkY << SubChunk::COORD_BIT_SIZE, $chunkZ << SubChunk::COORD_BIT_SIZE); - break; - } - } - } + if($hasLightEmitter){ + $lightSources += $this->scanForLightEmittingBlocks($subChunk, $chunkX << SubChunk::COORD_BIT_SIZE, $subChunkY << SubChunk::COORD_BIT_SIZE, $chunkZ << SubChunk::COORD_BIT_SIZE); } }