From 1c3d89cfefeae9123f28ddd1afa4210d72cc7cdd Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 29 Mar 2017 11:34:43 +0100 Subject: [PATCH] Fixed lighting issues with subchunks containing no blocks A subchunk with no blocks is not necessarily empty. --- src/pocketmine/level/format/Chunk.php | 4 ++-- src/pocketmine/level/format/SubChunk.php | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/pocketmine/level/format/Chunk.php b/src/pocketmine/level/format/Chunk.php index 52684896c..9f47296cf 100644 --- a/src/pocketmine/level/format/Chunk.php +++ b/src/pocketmine/level/format/Chunk.php @@ -307,7 +307,7 @@ class Chunk{ * @param int $level 0-15 */ public function setBlockSkyLight(int $x, int $y, int $z, int $level){ - if($this->getSubChunk($y >> 4)->setBlockSkyLight($x, $y & 0x0f, $z, $level)){ + if($this->getSubChunk($y >> 4, true)->setBlockSkyLight($x, $y & 0x0f, $z, $level)){ $this->hasChanged = true; } } @@ -334,7 +334,7 @@ class Chunk{ * @param int $level 0-15 */ public function setBlockLight(int $x, int $y, int $z, int $level){ - if($this->getSubChunk($y >> 4)->setBlockLight($x, $y & 0x0f, $z, $level)){ + if($this->getSubChunk($y >> 4, true)->setBlockLight($x, $y & 0x0f, $z, $level)){ $this->hasChanged = true; } } diff --git a/src/pocketmine/level/format/SubChunk.php b/src/pocketmine/level/format/SubChunk.php index 38cb57194..8a5cc5be6 100644 --- a/src/pocketmine/level/format/SubChunk.php +++ b/src/pocketmine/level/format/SubChunk.php @@ -47,8 +47,11 @@ class SubChunk{ } public function isEmpty() : bool{ - assert(strlen($this->ids) === 4096, "Wrong length of ID array, expecting 4096 bytes, got " . strlen($this->ids)); - return substr_count($this->ids, "\x00") === 4096; + return ( + substr_count($this->ids, "\x00") === 4096 and + substr_count($this->skyLight, "\xff") === 2048 and + substr_count($this->blockLight, "\x00") === 2048 + ); } public function getBlockId(int $x, int $y, int $z) : int{