Fixed lighting issues with subchunks containing no blocks

A subchunk with no blocks is not necessarily empty.
This commit is contained in:
Dylan K. Taylor 2017-03-29 11:34:43 +01:00
parent c84ec90398
commit 1c3d89cfef
2 changed files with 7 additions and 4 deletions

View File

@ -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;
}
}

View File

@ -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{