diff --git a/src/pocketmine/world/format/Chunk.php b/src/pocketmine/world/format/Chunk.php index 2c7b34540..4973e9866 100644 --- a/src/pocketmine/world/format/Chunk.php +++ b/src/pocketmine/world/format/Chunk.php @@ -221,10 +221,8 @@ class Chunk{ * @param int $level */ public function setAllBlockSkyLight(int $level) : void{ - $char = chr(($level & 0x0f) | ($level << 4)); - $data = str_repeat($char, 2048); for($y = $this->getHighestSubChunkIndex(); $y >= 0; --$y){ - $this->getSubChunk($y, true)->setBlockSkyLightArray(new LightArray($data)); + $this->getSubChunk($y, true)->setBlockSkyLightArray(LightArray::fill($level)); } } @@ -257,10 +255,8 @@ class Chunk{ * @param int $level */ public function setAllBlockLight(int $level) : void{ - $char = chr(($level & 0x0f) | ($level << 4)); - $data = str_repeat($char, 2048); for($y = $this->getHighestSubChunkIndex(); $y >= 0; --$y){ - $this->getSubChunk($y, true)->setBlockLightArray(new LightArray($data)); + $this->getSubChunk($y, true)->setBlockLightArray(LightArray::fill($level)); } } diff --git a/src/pocketmine/world/format/LightArray.php b/src/pocketmine/world/format/LightArray.php index 8822ddc12..dd3f1d7a0 100644 --- a/src/pocketmine/world/format/LightArray.php +++ b/src/pocketmine/world/format/LightArray.php @@ -54,6 +54,16 @@ final class LightArray{ $this->collectGarbage(); } + public static function fill(int $level) : self{ + if($level === 0){ + return new self(self::ZERO); + } + if($level === 15){ + return new self(self::FIFTEEN); + } + return new self(str_repeat(chr(($level & 0x0f) | ($level << 4)), 2048)); + } + public function get(int $x, int $y, int $z) : int{ return (ord($this->data{($x << 7) | ($z << 3) | ($y >> 1)}) >> (($y & 1) << 2)) & 0xf; }