mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-13 13:25:16 +00:00
PMF Level format fixes
This commit is contained in:
parent
cbe160e655
commit
8c9f07f737
@ -78,6 +78,7 @@ class PMFLevel extends PMF{
|
|||||||
$this->locationTable = array();
|
$this->locationTable = array();
|
||||||
$cnt = pow($this->levelData["width"], 2);
|
$cnt = pow($this->levelData["width"], 2);
|
||||||
@mkdir(dirname($this->file)."/chunks/", 0755);
|
@mkdir(dirname($this->file)."/chunks/", 0755);
|
||||||
|
$this->payloadOffset = ftell($this->fp);
|
||||||
for($index = 0; $index < $cnt; ++$index){
|
for($index = 0; $index < $cnt; ++$index){
|
||||||
$this->chunks[$index] = false;
|
$this->chunks[$index] = false;
|
||||||
$this->chunkChange[$index] = false;
|
$this->chunkChange[$index] = false;
|
||||||
@ -89,6 +90,14 @@ class PMFLevel extends PMF{
|
|||||||
$this->getXZ($index, $X, $Z);
|
$this->getXZ($index, $X, $Z);
|
||||||
@file_put_contents($this->getChunkPath($X, $Z), gzdeflate("", 9));
|
@file_put_contents($this->getChunkPath($X, $Z), gzdeflate("", 9));
|
||||||
}
|
}
|
||||||
|
if(!file_exists(dirname($this->file)."/entities.yml")){
|
||||||
|
$entities = new Config(dirname($this->file)."/entities.yml", CONFIG_YAML);
|
||||||
|
$entities->save();
|
||||||
|
}
|
||||||
|
if(!file_exists(dirname($this->file)."/tileEntities.yml")){
|
||||||
|
$tileEntities = new Config(dirname($this->file)."/tileEntities.yml", CONFIG_YAML);
|
||||||
|
$tileEntities->save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function parseLevel(){
|
protected function parseLevel(){
|
||||||
@ -119,7 +128,7 @@ class PMFLevel extends PMF{
|
|||||||
public function getIndex($X, $Z){
|
public function getIndex($X, $Z){
|
||||||
$X = (int) $X;
|
$X = (int) $X;
|
||||||
$Z = (int) $Z;
|
$Z = (int) $Z;
|
||||||
return $X << $this->log + $Z;
|
return ($Z << $this->log) + $X;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getXZ($index, &$X = null, &$Z = null){
|
public function getXZ($index, &$X = null, &$Z = null){
|
||||||
@ -143,7 +152,7 @@ class PMFLevel extends PMF{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function getChunkPath($X, $Z){
|
private function getChunkPath($X, $Z){
|
||||||
return dirname($this->file)."/chunks/".$X.".".$Z.".pmc";
|
return dirname($this->file)."/chunks/".$Z.".".$X.".pmc";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadChunk($X, $Z){
|
public function loadChunk($X, $Z){
|
||||||
@ -185,7 +194,9 @@ class PMFLevel extends PMF{
|
|||||||
protected function isMiniChunkEmpty($X, $Z, $Y){
|
protected function isMiniChunkEmpty($X, $Z, $Y){
|
||||||
$index = $this->getIndex($X, $Z);
|
$index = $this->getIndex($X, $Z);
|
||||||
if($this->chunks[$index][$Y] !== false){
|
if($this->chunks[$index][$Y] !== false){
|
||||||
|
if(substr_count($this->chunks[$index][$Y], "\x00") < 8192){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -224,11 +235,33 @@ class PMFLevel extends PMF{
|
|||||||
if($this->isChunkLoaded($X, $Z) === false){
|
if($this->isChunkLoaded($X, $Z) === false){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$index = $this->getIndex($X, $Z);
|
||||||
$this->chunks[$index][$Y] = str_repeat("\x00", 8192);
|
$this->chunks[$index][$Y] = str_repeat("\x00", 8192);
|
||||||
$this->locationTable[$index][0] |= 1 << $Y;
|
$this->locationTable[$index][0] |= 1 << $Y;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getMiniChunk($X, $Z, $Y){
|
||||||
|
if($this->isChunkLoaded($X, $Z) === false){
|
||||||
|
return str_repeat("\x00", 8192);
|
||||||
|
}
|
||||||
|
$index = $this->getIndex($X, $Z);
|
||||||
|
if(!isset($this->chunks[$index][$Y])){
|
||||||
|
return str_repeat("\x00", 8192);
|
||||||
|
}
|
||||||
|
return $this->chunks[$index][$Y];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMiniChunk($X, $Z, $Y, $data){
|
||||||
|
if($this->isChunkLoaded($X, $Z) === false){
|
||||||
|
$this->loadChunk($X, $Z);
|
||||||
|
}
|
||||||
|
$index = $this->getIndex($X, $Z);
|
||||||
|
$this->chunks[$index][$Y] = substr($data, 0, 8192);
|
||||||
|
$this->locationTable[$index][0] |= 1 << $Y;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public function setBlock($x, $y, $z, $block, $meta = 0){
|
public function setBlock($x, $y, $z, $block, $meta = 0){
|
||||||
$X = $x << 4;
|
$X = $x << 4;
|
||||||
$Z = $z << 4;
|
$Z = $z << 4;
|
||||||
@ -291,7 +324,7 @@ class PMFLevel extends PMF{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->locationTable[$index][0] = $bitmap;
|
$this->locationTable[$index][0] = $bitmap;
|
||||||
$this->seek($this->payloadOffset + $index << 2);
|
$this->seek($this->payloadOffset + ($index << 1));
|
||||||
$this->write(Utils::writeShort($this->locationTable[$index][0]));
|
$this->write(Utils::writeShort($this->locationTable[$index][0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user