ids, $ids, 4096); self::assignData($this->data, $data, 2048); self::assignData($this->skyLight, $skyLight, 2048, "\xff"); self::assignData($this->blockLight, $blockLight, 2048); } public function isEmpty(bool $checkLight = true) : bool{ return ( substr_count($this->ids, "\x00") === 4096 and (!$checkLight or ( substr_count($this->skyLight, "\xff") === 2048 and substr_count($this->blockLight, "\x00") === 2048 )) ); } public function getBlockId(int $x, int $y, int $z) : int{ return ord($this->ids{($x << 8) | ($z << 4) | $y}); } public function setBlockId(int $x, int $y, int $z, int $id) : bool{ $this->ids{($x << 8) | ($z << 4) | $y} = chr($id); return true; } public function getBlockData(int $x, int $y, int $z) : int{ return (ord($this->data{($x << 7) | ($z << 3) | ($y >> 1)}) >> (($y & 1) << 2)) & 0xf; } public function setBlockData(int $x, int $y, int $z, int $data) : bool{ $i = ($x << 7) | ($z << 3) | ($y >> 1); $shift = ($y & 1) << 2; $byte = ord($this->data{$i}); $this->data{$i} = chr(($byte & ~(0xf << $shift)) | (($data & 0xf) << $shift)); return true; } public function getFullBlock(int $x, int $y, int $z) : int{ $i = ($x << 8) | ($z << 4) | $y; return (ord($this->ids{$i}) << 4) | ((ord($this->data{$i >> 1}) >> (($y & 1) << 2)) & 0xf); } public function setBlock(int $x, int $y, int $z, ?int $id = null, ?int $data = null) : bool{ $i = ($x << 8) | ($z << 4) | $y; $changed = false; if($id !== null){ $block = chr($id); if($this->ids{$i} !== $block){ $this->ids{$i} = $block; $changed = true; } } if($data !== null){ $i >>= 1; $shift = ($y & 1) << 2; $byte = ord($this->data{$i}); $this->data{$i} = chr(($byte & ~(0xf << $shift)) | (($data & 0xf) << $shift)); if($this->data{$i} !== $byte){ $changed = true; } } return $changed; } public function getBlockLight(int $x, int $y, int $z) : int{ return (ord($this->blockLight{($x << 7) | ($z << 3) | ($y >> 1)}) >> (($y & 1) << 2)) & 0xf; } public function setBlockLight(int $x, int $y, int $z, int $level) : bool{ $i = ($x << 7) | ($z << 3) | ($y >> 1); $shift = ($y & 1) << 2; $byte = ord($this->blockLight{$i}); $this->blockLight{$i} = chr(($byte & ~(0xf << $shift)) | (($level & 0xf) << $shift)); return true; } public function getBlockSkyLight(int $x, int $y, int $z) : int{ return (ord($this->skyLight{($x << 7) | ($z << 3) | ($y >> 1)}) >> (($y & 1) << 2)) & 0xf; } public function setBlockSkyLight(int $x, int $y, int $z, int $level) : bool{ $i = ($x << 7) | ($z << 3) | ($y >> 1); $shift = ($y & 1) << 2; $byte = ord($this->skyLight{$i}); $this->skyLight{$i} = chr(($byte & ~(0xf << $shift)) | (($level & 0xf) << $shift)); return true; } public function getHighestBlockAt(int $x, int $z) : int{ $low = ($x << 8) | ($z << 4); $i = $low | 0x0f; for(; $i >= $low; --$i){ if($this->ids{$i} !== "\x00"){ return $i & 0x0f; } } return -1; //highest block not in this subchunk } public function getBlockIdColumn(int $x, int $z) : string{ return substr($this->ids, ($x << 8) | ($z << 4), 16); } public function getBlockDataColumn(int $x, int $z) : string{ return substr($this->data, ($x << 7) | ($z << 3), 8); } public function getBlockLightColumn(int $x, int $z) : string{ return substr($this->blockLight, ($x << 7) | ($z << 3), 8); } public function getBlockSkyLightColumn(int $x, int $z) : string{ return substr($this->skyLight, ($x << 7) | ($z << 3), 8); } public function getBlockIdArray() : string{ assert(strlen($this->ids) === 4096, "Wrong length of ID array, expecting 4096 bytes, got " . strlen($this->ids)); return $this->ids; } public function getBlockDataArray() : string{ assert(strlen($this->data) === 2048, "Wrong length of data array, expecting 2048 bytes, got " . strlen($this->data)); return $this->data; } public function getBlockSkyLightArray() : string{ assert(strlen($this->skyLight) === 2048, "Wrong length of skylight array, expecting 2048 bytes, got " . strlen($this->skyLight)); return $this->skyLight; } public function setBlockSkyLightArray(string $data){ assert(strlen($data) === 2048, "Wrong length of skylight array, expecting 2048 bytes, got " . strlen($data)); $this->skyLight = $data; } public function getBlockLightArray() : string{ assert(strlen($this->blockLight) === 2048, "Wrong length of light array, expecting 2048 bytes, got " . strlen($this->blockLight)); return $this->blockLight; } public function setBlockLightArray(string $data){ assert(strlen($data) === 2048, "Wrong length of light array, expecting 2048 bytes, got " . strlen($data)); $this->blockLight = $data; } public function networkSerialize() : string{ return "\x00" . $this->ids . $this->data; } public function __debugInfo(){ return []; } }