mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-19 04:05:31 +00:00
Rewrote Location table handling on Pocket Level Format parser [due to MCEdit bug]
This commit is contained in:
parent
6bafcbf2a7
commit
1ca87c7ade
@ -38,23 +38,14 @@ class PocketChunkParser{
|
|||||||
private function loadLocationTable(){
|
private function loadLocationTable(){
|
||||||
$this->location = array();
|
$this->location = array();
|
||||||
console("[DEBUG] Loading Chunk Location table...", true, true, 2);
|
console("[DEBUG] Loading Chunk Location table...", true, true, 2);
|
||||||
$chunkCnt = 0;
|
|
||||||
for($offset = 0; $offset < 0x1000; $offset += 4){
|
for($offset = 0; $offset < 0x1000; $offset += 4){
|
||||||
$data = substr($this->raw, $offset, 4);
|
$data = Utils::readLInt(substr($this->raw, $offset, 4));
|
||||||
$sectors = ord($data{0});
|
$sectors = $data & 0xff;
|
||||||
if($sectors === 0){
|
if($sectors === 0){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$x = ord($data{1});
|
$sectorLocation = $data >> 8;
|
||||||
$z = ord($data{2});
|
$this->location[$offset >> 2] = $sectorLocation * $this->sectorLength;//$this->getOffset($X, $Z, $sectors);
|
||||||
$X = $chunkCnt % 16;
|
|
||||||
$Z = $chunkCnt >> 4;
|
|
||||||
//$unused = ord($data{3});
|
|
||||||
if(!isset($this->location[$X])){
|
|
||||||
$this->location[$X] = array();
|
|
||||||
}
|
|
||||||
$this->location[$X][$Z] = $this->getOffset($X, $Z, $sectors);
|
|
||||||
++$chunkCnt;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,17 +75,8 @@ class PocketChunkParser{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getOffsetPosition($X, $Z){
|
private function getOffset($X, $Z){
|
||||||
$data = substr($this->raw, ($X << 2) + ($Z << 7), 4); //$X * 4 + $Z * 128
|
return $this->location[$X + ($Z << 5)];
|
||||||
return array(ord($data{0}), ord($data{1}), ord($data{2}), ord($data{3}));
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getOffset($X, $Z, $sectors = 21){
|
|
||||||
return 0x1000 + (($X * $sectors) << 12) + (($Z * $sectors) << 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getOffsetLocation($X, $Z){
|
|
||||||
return $X << 2 + $Z << 7;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getChunk($X, $Z){
|
public function getChunk($X, $Z){
|
||||||
@ -121,7 +103,7 @@ class PocketChunkParser{
|
|||||||
public function parseChunk($X, $Z){
|
public function parseChunk($X, $Z){
|
||||||
$X = (int) $X;
|
$X = (int) $X;
|
||||||
$Z = (int) $Z;
|
$Z = (int) $Z;
|
||||||
$offset = $this->location[$X][$Z];
|
$offset = $this->getOffset($X, $Z);
|
||||||
$len = Utils::readLInt(substr($this->raw, $offset, 4));
|
$len = Utils::readLInt(substr($this->raw, $offset, 4));
|
||||||
$offset += 4;
|
$offset += 4;
|
||||||
$chunk = array(
|
$chunk = array(
|
||||||
@ -163,7 +145,7 @@ class PocketChunkParser{
|
|||||||
flock($fp, LOCK_EX);
|
flock($fp, LOCK_EX);
|
||||||
foreach($this->map as $x => $d){
|
foreach($this->map as $x => $d){
|
||||||
foreach($d as $z => $chunk){
|
foreach($d as $z => $chunk){
|
||||||
fseek($fp, $this->location[$x][$z]);
|
fseek($fp, $this->getOffset($x, $z));
|
||||||
fwrite($fp, $this->writeChunk($x, $z), $this->chunkLength);
|
fwrite($fp, $this->writeChunk($x, $z), $this->chunkLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user