mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Chunk parsing...
This commit is contained in:
@ -32,9 +32,10 @@ class ChunkParser{
|
||||
private $raw = b"";
|
||||
var $sectorLenght = 4096; //16 * 16 * 16
|
||||
var $chunkLenght = 86016; //21 * $sectorLenght
|
||||
var $map;
|
||||
|
||||
function __construct(){
|
||||
|
||||
$map = array();
|
||||
}
|
||||
|
||||
public function loadFile($file){
|
||||
@ -67,8 +68,68 @@ class ChunkParser{
|
||||
return substr($this->raw, $this->getOffset($X, $Z) + $add, $this->chunkLenght - $add);
|
||||
}
|
||||
|
||||
public function getColumn($X, $Z){
|
||||
public function parseChunk($X, $Z){
|
||||
$X = (int) $X;
|
||||
$Z = (int) $Z;
|
||||
$offset = $this->getOffset($X, $Z);
|
||||
$len = Utils::readLInt(substr($this->raw, $offset, 4));
|
||||
$offset += 4;
|
||||
$chunk = array(
|
||||
0 => array(), //Block
|
||||
1 => array(), //Data
|
||||
2 => array(), //SkyLight
|
||||
3 => array(), //BlockLight
|
||||
);
|
||||
foreach($chunk as $section => &$data){
|
||||
$l = $section === 0 ? 128:64;
|
||||
for($i = 0; $i < 256; ++$i){
|
||||
$data[] = substr($this->raw, $offset, $l);
|
||||
$offset += $l;
|
||||
}
|
||||
}
|
||||
return $chunk;
|
||||
}
|
||||
|
||||
public function getRawColumn($offset, $l){
|
||||
$data = "";
|
||||
if($l === 128){
|
||||
$data = substr($this->raw, $offset, $l);
|
||||
}elseif($l === 64){
|
||||
for($i = 0; $i < $l; ++$i){
|
||||
$d = ord($this->raw{$offset + $i});
|
||||
$data .= chr($d >> 4);
|
||||
$data .= chr($d & 0x0F);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function parseColumn($offset, $l){
|
||||
$data = array();
|
||||
if($l === 128){
|
||||
for($i = 0; $i < $l; ++$i){
|
||||
$data[] = ord($this->raw{$offset + $i});
|
||||
}
|
||||
}elseif($l === 64){
|
||||
for($i = 0; $i < $l; ++$i){
|
||||
$d = ord($this->raw{$offset + $i});
|
||||
$data[] = $d >> 4;
|
||||
$data[] = $d & 0x0F;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function loadMap(){
|
||||
console("[DEBUG] Loading chunks...", true, true, 2);
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
$this->map[$x] = array();
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
$this->map[$x][$z] = $this->parseChunk($x, $z);
|
||||
console("[INTERNAL] Chunk X ".$x." Z ".$z." loaded", true, true, 3);
|
||||
}
|
||||
}
|
||||
console("[DEBUG] Chunks loaded!", true, true, 2);
|
||||
}
|
||||
|
||||
public function getBlock($x, $y, $z){
|
||||
@ -77,8 +138,14 @@ class ChunkParser{
|
||||
$z = (int) $z;
|
||||
$X = $x >> 4;
|
||||
$Z = $z >> 4;
|
||||
$block = $this->getOffset($X, $Z) + 4 + (($x << 6) + $y + ($z << 10));
|
||||
$meta = $this->getOffset($X, $Z) + 4 + (($x << 6) + $y + ($z << 10));
|
||||
$aX = $x - ($X << 4);
|
||||
$aZ = $z - ($Z << 4);
|
||||
$index = $aZ + ($aX << 4);
|
||||
console("[DEBUG] $x $y $z | $X $Z $index", true, true, 2);
|
||||
var_dump($this->map[$X][$Z][0][$index]);
|
||||
$block = ord($this->map[$X][$Z][0][$index]{$y});
|
||||
//$meta = $this->getOffset($X, $Z) + 4 + (($x << 6) + $y + ($z << 10));
|
||||
return array($block, 0);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user