defaultBlock = $default; $this->blockLayers = $blocks; $this->skyLight = $skyLight ?? new LightArray(LightArray::FIFTEEN); $this->blockLight = $blockLight ?? new LightArray(LightArray::ZERO); } public function isEmptyAuthoritative() : bool{ $this->collectGarbage(); return $this->isEmptyFast(); } public function isEmptyFast() : bool{ return empty($this->blockLayers); } public function getFullBlock(int $x, int $y, int $z) : int{ if(empty($this->blockLayers)){ return $this->defaultBlock; } return $this->blockLayers[0]->get($x, $y, $z); } public function setFullBlock(int $x, int $y, int $z, int $block) : void{ if(empty($this->blockLayers)){ $this->blockLayers[] = new PalettedBlockArray($this->defaultBlock); } $this->blockLayers[0]->set($x, $y, $z, $block); } /** * @return PalettedBlockArray[] */ public function getBlockLayers() : array{ return $this->blockLayers; } public function getHighestBlockAt(int $x, int $z) : int{ if(empty($this->blockLayers)){ return -1; } for($y = 15; $y >= 0; --$y){ if($this->blockLayers[0]->get($x, $y, $z) !== $this->defaultBlock){ return $y; } } return -1; //highest block not in this subchunk } public function getBlockSkyLightArray() : LightArray{ return $this->skyLight; } public function setBlockSkyLightArray(LightArray $data) : void{ $this->skyLight = $data; } public function getBlockLightArray() : LightArray{ return $this->blockLight; } public function setBlockLightArray(LightArray $data) : void{ $this->blockLight = $data; } public function __debugInfo(){ return []; } public function collectGarbage() : void{ foreach($this->blockLayers as $k => $layer){ $layer->collectGarbage(); foreach($layer->getPalette() as $p){ if($p !== $this->defaultBlock){ continue 2; } } unset($this->blockLayers[$k]); } $this->blockLayers = array_values($this->blockLayers); $this->skyLight->collectGarbage(); $this->blockLight->collectGarbage(); } }