mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-22 12:39:43 +00:00
infinite worlds!!!
This commit is contained in:
parent
c371fb9c8a
commit
27e6bc6540
1 changed files with 31 additions and 21 deletions
|
|
@ -46,10 +46,11 @@ class PMFLevel extends PMF{
|
||||||
for($X = 0; $X < 16; ++$X){
|
for($X = 0; $X < 16; ++$X){
|
||||||
for($Z = 0; $Z < 16; ++$Z){
|
for($Z = 0; $Z < 16; ++$Z){
|
||||||
$index = $this->getIndex($X, $Z);
|
$index = $this->getIndex($X, $Z);
|
||||||
$this->chunks[$index] = false;
|
$this->initCleanChunk($X, $Z);
|
||||||
$this->chunkChange[$index] = false;
|
//$this->chunks[$index] = false;
|
||||||
$this->locationTable[$index] = [0 => 0,];
|
//$this->chunkChange[$index] = false;
|
||||||
$this->write(Utils::writeShort(0));
|
//$this->locationTable[$index] = [0 => 0,];
|
||||||
|
//$this->write(Utils::writeShort(0));
|
||||||
//$X = $Z = null;
|
//$X = $Z = null;
|
||||||
//$this->getXZ($index, $X, $Z);
|
//$this->getXZ($index, $X, $Z);
|
||||||
@file_put_contents($this->getChunkPath($X, $Z), gzdeflate("", PMF_LEVEL_DEFLATE_LEVEL));
|
@file_put_contents($this->getChunkPath($X, $Z), gzdeflate("", PMF_LEVEL_DEFLATE_LEVEL));
|
||||||
|
|
@ -84,7 +85,7 @@ class PMFLevel extends PMF{
|
||||||
$this->payloadOffset = ftell($this->fp);
|
$this->payloadOffset = ftell($this->fp);
|
||||||
|
|
||||||
if($locationTable !== false){
|
if($locationTable !== false){
|
||||||
$this->writeLocationTable();
|
//$this->writeLocationTable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -152,19 +153,20 @@ class PMFLevel extends PMF{
|
||||||
}
|
}
|
||||||
|
|
||||||
private function readLocationTable(){
|
private function readLocationTable(){
|
||||||
$this->locationTable = [];
|
//$this->locationTable = [];
|
||||||
//$cnt = pow($this->levelData["width"], 2);
|
//$cnt = pow($this->levelData["width"], 2);
|
||||||
$this->seek($this->payloadOffset);
|
//$this->seek($this->payloadOffset);
|
||||||
for($X = 0; $X < 16; ++$X){
|
for($X = 0; $X < 16; ++$X){
|
||||||
for($Z = 0; $Z < 16; ++$Z){
|
for($Z = 0; $Z < 16; ++$Z){
|
||||||
$index = $this->getIndex($X, $Z);
|
$index = $this->getIndex($X, $Z);
|
||||||
$this->chunks[$index] = false;
|
$this->chunks[$index] = false;
|
||||||
$this->chunkChange[$index] = false;
|
$this->chunkChange[$index] = false;
|
||||||
$this->locationTable[$index] = [
|
//$this->locationTable[$index] = [
|
||||||
0 => Utils::readShort($this->read(2)), //16 bit flags
|
// 0 => Utils::readShort($this->read(2)), //16 bit flags
|
||||||
];
|
//];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//var_dump($this->locationTable);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -267,24 +269,28 @@ class PMFLevel extends PMF{
|
||||||
|
|
||||||
$chunk = @gzopen($this->getChunkPath($X, $Z), "wb" . PMF_LEVEL_DEFLATE_LEVEL);
|
$chunk = @gzopen($this->getChunkPath($X, $Z), "wb" . PMF_LEVEL_DEFLATE_LEVEL);
|
||||||
$bitmap = 0;
|
$bitmap = 0;
|
||||||
|
for($Y = 0; $Y < 8; ++$Y){
|
||||||
|
$bitmap |= ($this->chunks[$index][$Y] !== false and ((isset($this->chunkChange[$index][$Y]) and $this->chunkChange[$index][$Y] === 0) or !$this->isMiniChunkEmpty($X, $Z, $Y))) << $Y;
|
||||||
|
}
|
||||||
|
gzwrite($chunk, Utils::writeShort($bitmap), 2); //2 bytes locmap
|
||||||
$biomedata = $this->chunkInfo[$index][0];
|
$biomedata = $this->chunkInfo[$index][0];
|
||||||
if(strlen($biomedata) < 256){
|
if(strlen($biomedata) < 256){
|
||||||
$biomedata = str_repeat("\x01", 256);
|
$biomedata = str_repeat("\x01", 256);
|
||||||
}
|
}
|
||||||
|
|
||||||
gzwrite($chunk, $biomedata);
|
gzwrite($chunk, $biomedata);
|
||||||
for($Y = 0; $Y < $this->levelData["height"]; ++$Y){
|
for($Y = 0; $Y < 8; ++$Y){
|
||||||
if($this->chunks[$index][$Y] !== false and ((isset($this->chunkChange[$index][$Y]) and $this->chunkChange[$index][$Y] === 0) or !$this->isMiniChunkEmpty($X, $Z, $Y))){
|
if($this->chunks[$index][$Y] !== false and ((isset($this->chunkChange[$index][$Y]) and $this->chunkChange[$index][$Y] === 0) or !$this->isMiniChunkEmpty($X, $Z, $Y))){
|
||||||
gzwrite($chunk, $this->chunks[$index][$Y]);
|
gzwrite($chunk, $this->chunks[$index][$Y]);
|
||||||
$bitmap |= 1 << $Y;
|
|
||||||
}else{
|
}else{
|
||||||
$this->chunks[$index][$Y] = false;
|
$this->chunks[$index][$Y] = false;
|
||||||
}
|
}
|
||||||
$this->chunkChange[$index][$Y] = 0;
|
$this->chunkChange[$index][$Y] = 0;
|
||||||
}
|
}
|
||||||
$this->chunkChange[$index][-1] = false;
|
$this->chunkChange[$index][-1] = false;
|
||||||
$this->locationTable[$index][0] = $bitmap;
|
//$this->locationTable[$index][0] = $bitmap;
|
||||||
$this->seek($this->payloadOffset + ($index << 1));
|
//$this->seek($this->payloadOffset + ($index << 1));
|
||||||
$this->write(Utils::writeShort($this->locationTable[$index][0]));
|
//$this->write(Utils::writeShort($this->locationTable[$index][0]));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -311,7 +317,7 @@ class PMFLevel extends PMF{
|
||||||
|
|
||||||
public function generateChunk($X, $Z, LevelGenerator $generator){
|
public function generateChunk($X, $Z, LevelGenerator $generator){
|
||||||
$index = $this->getIndex($X, $Z);
|
$index = $this->getIndex($X, $Z);
|
||||||
if(isset($this->locationTable[$index])){
|
if(isset($this->chunks[$index])){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->initCleanChunk($X, $Z);
|
$this->initCleanChunk($X, $Z);
|
||||||
|
|
@ -333,19 +339,23 @@ class PMFLevel extends PMF{
|
||||||
if($this->isChunkLoaded($X, $Z)){
|
if($this->isChunkLoaded($X, $Z)){
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}elseif(!isset($this->locationTable[$index])){
|
}//elseif(!isset($this->locationTable[$index])){
|
||||||
return false;
|
// return false;
|
||||||
}
|
//}
|
||||||
|
|
||||||
$info = $this->locationTable[$index];
|
//$info = $this->locationTable[$index];
|
||||||
$this->seek($info[0]);
|
//$this->seek($info[0]);
|
||||||
$cp = $this->getChunkPath($X, $Z);
|
$cp = $this->getChunkPath($X, $Z);
|
||||||
|
if(!is_file($cp)) return false;
|
||||||
$chunk = file_get_contents($cp);
|
$chunk = file_get_contents($cp);
|
||||||
if($chunk === false){
|
if($chunk === false){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$chunk = zlib_decode($chunk);
|
$chunk = zlib_decode($chunk);
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
|
if(strlen($chunk) === 0) return false;
|
||||||
|
$info = [0 => Utils::readShort(substr($chunk, $offset, 2))];
|
||||||
|
$offset+=2;
|
||||||
$this->chunks[$index] = [];
|
$this->chunks[$index] = [];
|
||||||
$this->chunkChange[$index] = [-1 => false];
|
$this->chunkChange[$index] = [-1 => false];
|
||||||
$this->chunkInfo[$index][0] = substr($chunk, $offset, 256); //Biome data
|
$this->chunkInfo[$index][0] = substr($chunk, $offset, 256); //Biome data
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue