mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 16:51:42 +00:00
LightArray: added fill(), remove duplicated code
This commit is contained in:
parent
4264923f4f
commit
5a2e84eb9f
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user