From f0d62cf4ce845c0eedf8868fe69510e6a2f35ff3 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 31 Oct 2020 20:38:15 +0000 Subject: [PATCH] World: don't try to load chunks to read light levels sync chunk load is useless here because lighting isn't immediately calculated anyway and it isn't available directly from the chunk when loaded. --- src/world/World.php | 10 ++++++++-- tests/phpstan/configs/l8-baseline.neon | 5 ----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/world/World.php b/src/world/World.php index 74342b68d..01dab4449 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -1839,7 +1839,10 @@ class World implements ChunkManager{ * @return int 0-15 */ public function getPotentialBlockSkyLightAt(int $x, int $y, int $z) : int{ - return $this->getOrLoadChunk($x >> 4, $z >> 4, true)->getSubChunk($y >> 4)->getBlockSkyLightArray()->get($x & 0x0f, $y & 0xf, $z & 0x0f); + if(($chunk = $this->getChunk($x >> 4, $z >> 4, false)) !== null){ + return $chunk->getSubChunk($y >> 4)->getBlockSkyLightArray()->get($x & 0x0f, $y & 0xf, $z & 0x0f); + } + return 0; //TODO: this should probably throw instead (light not calculated yet) } /** @@ -1848,7 +1851,10 @@ class World implements ChunkManager{ * @return int 0-15 */ public function getBlockLightAt(int $x, int $y, int $z) : int{ - return $this->getOrLoadChunk($x >> 4, $z >> 4, true)->getSubChunk($y >> 4)->getBlockLightArray()->get($x & 0x0f, $y & 0xf, $z & 0x0f); + if(($chunk = $this->getChunk($x >> 4, $z >> 4, false)) !== null){ + return $chunk->getSubChunk($y >> 4)->getBlockLightArray()->get($x & 0x0f, $y & 0xf, $z & 0x0f); + } + return 0; //TODO: this should probably throw instead (light not calculated yet) } public function getBiomeId(int $x, int $z) : int{ diff --git a/tests/phpstan/configs/l8-baseline.neon b/tests/phpstan/configs/l8-baseline.neon index e07ad407c..f98b36f58 100644 --- a/tests/phpstan/configs/l8-baseline.neon +++ b/tests/phpstan/configs/l8-baseline.neon @@ -555,11 +555,6 @@ parameters: count: 3 path: ../../../src/world/World.php - - - message: "#^Cannot call method getSubChunk\\(\\) on pocketmine\\\\world\\\\format\\\\Chunk\\|null\\.$#" - count: 2 - path: ../../../src/world/World.php - - message: "#^Cannot call method getBiomeId\\(\\) on pocketmine\\\\world\\\\format\\\\Chunk\\|null\\.$#" count: 1