changes to world format: added skylight into chunk data, replaced loctable in level.dat with a specific byte in every chunk, removed ncleveldata.pmf, bumped api version to 12.3

This commit is contained in:
GameHerobrine 2026-03-11 01:49:41 +03:00
parent d6c57e4aa6
commit 581a6a8fb2
7 changed files with 203 additions and 86 deletions

View file

@ -1,6 +1,5 @@
<?php <?php
//do not use any modern php features in this file //do not use any modern php features in this file
$errors = 0;
if(version_compare("8.0.0", PHP_VERSION) > 0){ if(version_compare("8.0.0", PHP_VERSION) > 0){
echo "[ERROR] Use PHP >= 8.0.0 to launch this server software.\n"; echo "[ERROR] Use PHP >= 8.0.0 to launch this server software.\n";

View file

@ -103,10 +103,10 @@ set_include_path(get_include_path() . PATH_SEPARATOR . FILE_PATH);
ini_set("memory_limit", "256M"); //Default ini_set("memory_limit", "256M"); //Default
define("LOG", true); define("LOG", true);
define("START_TIME", microtime(true)); define("START_TIME", microtime(true));
define("MAJOR_VERSION", "1.1.1dev"); define("MAJOR_VERSION", "1.1.2dev");
define("CODENAME", "Nostalgia"); //i\'m not very creative - kotyaralih, yeah - tema1d. define("CODENAME", "Nostalgia"); //i\'m not very creative - kotyaralih, yeah - tema1d.
define("CURRENT_MINECRAFT_VERSION", "v0.8.1 alpha"); define("CURRENT_MINECRAFT_VERSION", "v0.8.1 alpha");
define("CURRENT_API_VERSION", "12.2"); define("CURRENT_API_VERSION", "12.3");
define("CURRENT_PHP_VERSION", "8.0"); define("CURRENT_PHP_VERSION", "8.0");
$gitsha1 = false; $gitsha1 = false;
if(file_exists(FILE_PATH . ".git/refs/heads/master")){ //Found Git information! if(file_exists(FILE_PATH . ".git/refs/heads/master")){ //Found Git information!

View file

@ -7,7 +7,7 @@ class PMF{
protected $fp; protected $fp;
protected $file; protected $file;
private $version; private $version;
private $type; protected $type;
public function __construct($file, $new = false, $type = 0, $version = PMF_CURRENT_VERSION){ public function __construct($file, $new = false, $type = 0, $version = PMF_CURRENT_VERSION){
if($new === true){ if($new === true){
@ -74,7 +74,8 @@ class PMF{
public function parseInfo(){ public function parseInfo(){
$this->seek(0); $this->seek(0);
if(fread($this->fp, 3) !== "PMF"){ $type = fread($this->fp, 3);
if($type !== "PMF"){
return false; return false;
} }
$this->version = ord($this->read(1)); $this->version = ord($this->read(1));

View file

@ -1,9 +1,54 @@
<?php <?php
define("PMF_CURRENT_LEVEL_VERSION", 0x00); define("PMF_CURRENT_LEVEL_VERSION", 0x00);
class PMFLevel extends PMF{ class PMFLevel extends PMF{
const NC_DATA_VERSION = 1; const CHUNK_VERSION = 0;
/**
* Level data format stuff:
* Old:
* <z>.<x>.dat (chunk), gzipped
* Contains multiple 16x16x16 chunks(the amount of minichunks is determined by levelData["height"])
* Each minichunk is 8192 bytes long:
* * minichunk is split into 32byte chunks for 16 blocks(y from 0 to 15)
* * ids(first 16 bytes), metas(8 bytes, each is 4bits), blocklight(8 bytes, each is 4 bits, wasnt used before nc 1.1.1)
* * every column goes from x=0 to x=15 and then from z=0 to z=15(x=0,z=0 is 0, x=1,z=0 is 32, x=15,z=0 is 480, x=0,z=1 is 512, x=15,z=15 is 8160)
*
* level.pmf
* first 5 bytes - pmf header(PMF<PMFVERSION><TYPE>)
* next byte - level version(0 - pmmp/nc, 1 - ncpmf(0.9/0.10 branch),pmmp(very early 1.4dev, also used by nc-worlddev), 2 - ncpmf(0.9/0.10 branch), pmmp(early 1.4dev), others are reserved for ncpmf
* next 2 bytes world name length (<worldnamelen>)
* next <worldnamelen> bytes - world name
* seed(4 bytes), time(4 bytes), spawnX/Y/Z(each 4 bytes float)
* world width/height(1 byte each)
* extra data(gzipped, length is determined by 2 bytes at the beginning)
* loctable - location table - size is determined by (<world_width>)*(<world_width>)*2 - 512 for 16x16
*
* ncleveldata.pmf
* NC_DATA_VERSION(1 byte)
* hasLight (256 bytes)
*
* New: (WIP)
* <z>.<x>.dat (chunk), gzipped
* First byte is used for chunk version (0 for now)
* Next 2 bytes are used for location table value(what minichunks this chunk contains - msb is not used due to level beign 128 blocks tall => 128/16=8 => can fit into a single byte)
* Next byte is used to determine is this chunk populated by blocklight and skylight (moved from ncleveldata.pmf - (<v> & 1) => has blocklight, (<v> & 2) => has skylight)
* Next byte is used to determine should this chunk tick or not
* The rest of the file is minichunks(the amount of minichunks is determined by levelData["height"])
* Each minichunk is 4096+2048*3 bytes long:
* * minichunk is split into 40byte chunks for 16 blocks(y from 0 to 15)
* * ids(first 16 bytes), metas(8 bytes, each is 4bits), blocklight(8 bytes, each is 4 bits), skylight(8 bytes, each is 4 bits)
* * every column goes from x=0 to x=15 and then from z=0 to z=15(x=0,z=0 is 0, x=1,z=0 is 40, x=15,z=0 is 600, x=0,z=1 is 640, x=15,z=15 is 10200)
*
* level.pmf
* same as old(for now), except there is no loctable
* TODO maybe remove worldname, seed and spawn location because of the future changes i want to implement?
*/
const TYPE_CURRENT = self::TYPE_NEW;
const TYPE_OLD = 0; //old(nc 1.1.1 and below)
const TYPE_NEW = 1; //new
public $isLoaded = true; public $isLoaded = true;
private $levelData = []; private $levelData = [];
public $hasLight = ""; public $hasLight = "";
@ -18,7 +63,7 @@ class PMFLevel extends PMF{
public $level; public $level;
public function __construct($file, $blank = false){ public function __construct($file, $blank = false){
if(is_array($blank)){ if(is_array($blank)){
$this->create($file, 0); $this->create($file, self::TYPE_CURRENT);
$this->levelData = $blank; $this->levelData = $blank;
$this->createBlank(); $this->createBlank();
$this->isLoaded = true; $this->isLoaded = true;
@ -69,8 +114,9 @@ class PMFLevel extends PMF{
public function saveData($locationTable = true){ public function saveData($locationTable = true){
$this->levelData["version"] = PMF_CURRENT_LEVEL_VERSION; $this->levelData["version"] = PMF_CURRENT_LEVEL_VERSION;
@ftruncate($this->fp, 5); @ftruncate($this->fp, 4);
$this->seek(5); $this->seek(4);
$this->write(chr(self::TYPE_CURRENT)); //force update type
$this->write(chr($this->levelData["version"])); $this->write(chr($this->levelData["version"]));
$this->write(Utils::writeShort(strlen($this->levelData["name"])) . $this->levelData["name"]); $this->write(Utils::writeShort(strlen($this->levelData["name"])) . $this->levelData["name"]);
$this->write(Utils::writeInt($this->levelData["seed"])); $this->write(Utils::writeInt($this->levelData["seed"]));
@ -83,23 +129,6 @@ class PMFLevel extends PMF{
$extra = gzdeflate($this->levelData["extra"], PMF_LEVEL_DEFLATE_LEVEL); $extra = gzdeflate($this->levelData["extra"], PMF_LEVEL_DEFLATE_LEVEL);
$this->write(Utils::writeShort(strlen($extra)) . $extra); $this->write(Utils::writeShort(strlen($extra)) . $extra);
$this->payloadOffset = ftell($this->fp); $this->payloadOffset = ftell($this->fp);
if($locationTable !== false){
$this->writeLocationTable();
}
$this->writeNCData();
}
public function writeNCData(){
$dir = dirname($this->file);
try{
$file = fopen("$dir/ncleveldata.pmf", "wb");
fwrite($file, chr(self::NC_DATA_VERSION), 1);
fwrite($file, $this->hasLight, 16*16);
}finally{
fclose($file);
}
} }
public function readNCData(){ public function readNCData(){
@ -204,10 +233,15 @@ class PMFLevel extends PMF{
return dirname($this->file) . "/chunks/" . $Z . "." . $X . ".pmc"; return dirname($this->file) . "/chunks/" . $Z . "." . $X . ".pmc";
} }
protected function parseLevel(){ protected function parseLevel(){
if($this->getType() !== 0x00){
return false; $type = $this->getType();
} $isNCLevel = false;
if($type == 0x00) $isNCLevel = false;
else if($type == 0x01) $isNCLevel = true;
else return false;
$this->seek(5); $this->seek(5);
$this->levelData["version"] = ord($this->read(1)); $this->levelData["version"] = ord($this->read(1));
if($this->levelData["version"] > PMF_CURRENT_LEVEL_VERSION){ if($this->levelData["version"] > PMF_CURRENT_LEVEL_VERSION){
@ -224,24 +258,49 @@ class PMFLevel extends PMF{
if(($this->levelData["width"] !== 16 and $this->levelData["width"] !== 32) or $this->levelData["height"] !== 8){ if(($this->levelData["width"] !== 16 and $this->levelData["width"] !== 32) or $this->levelData["height"] !== 8){
return false; return false;
} }
$lastseek = ftell($this->fp);
if(($len = $this->read(2)) === false or ($this->levelData["extra"] = @gzinflate($this->read(Utils::readShort($len, false)))) === false){ //Corruption protection if(!$isNCLevel){
console("[NOTICE] Empty/corrupt location table detected, forcing recovery"); ConsoleAPI::notice("Old level found, starting conversion - reading old data");
fseek($this->fp, $lastseek); $lastseek = ftell($this->fp);
$c = gzdeflate(""); if(($len = $this->read(2)) === false or ($this->levelData["extra"] = @gzinflate($this->read(Utils::readShort($len, false)))) === false){ //Corruption protection
$this->write(Utils::writeShort(strlen($c)) . $c); console("[NOTICE] Empty/corrupt location table detected, forcing recovery");
$this->payloadOffset = ftell($this->fp); fseek($this->fp, $lastseek);
$this->levelData["extra"] = ""; $c = gzdeflate("");
$cnt = pow($this->levelData["width"], 2); $this->write(Utils::writeShort(strlen($c)) . $c);
for($index = 0; $index < $cnt; ++$index){ $this->payloadOffset = ftell($this->fp);
$this->write("\x00\xFF"); //Force index recreation $this->levelData["extra"] = "";
$cnt = pow($this->levelData["width"], 2);
for($index = 0; $index < $cnt; ++$index){
$this->write("\x00\xFF"); //Force index recreation
}
fseek($this->fp, $this->payloadOffset);
}else{
$this->payloadOffset = ftell($this->fp);
} }
fseek($this->fp, $this->payloadOffset); $this->readNCData();
$this->readLocationTable();
ConsoleAPI::notice("Converting chunks");
$this->convertOldChunks();
}else{ }else{
$this->payloadOffset = ftell($this->fp); if(($len = $this->read(2)) === false or ($this->levelData["extra"] = @gzinflate($this->read(Utils::readShort($len, false)))) === false){
}
}
}
public function convertOldChunks(){
for($x = 0; $x < 16; ++$x){
for($z = 0; $z < 16; ++$z){
$this->loadChunk($x, $z, self::TYPE_OLD);
}
}
for($x = 0; $x < 16; ++$x){
for($z = 0; $z < 16; ++$z){
$this->unloadChunk($x, $z);
}
} }
$this->readNCData();
return $this->readLocationTable();
} }
private function readLocationTable(){ private function readLocationTable(){
@ -318,7 +377,22 @@ 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);
gzwrite($chunk, chr(self::CHUNK_VERSION));
//$info = $this->locationTable[$index] = [Utils::readShort(gzread($chunk, 2), false)];
//$this->hasLight[$index] = ord(gzread($chunk, 1));
$bitmap = 0; $bitmap = 0;
for($Y = 0; $Y < $this->levelData["height"]; ++$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))){
$bitmap |= 1 << $Y;
}
}
gzwrite($chunk, Utils::writeShort($bitmap));
gzwrite($chunk, $this->hasLight[$index]);
gzwrite($chunk, chr(0)); //TODO reserved for shouldTick
for($Y = 0; $Y < $this->levelData["height"]; ++$Y){ for($Y = 0; $Y < $this->levelData["height"]; ++$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]);
@ -330,15 +404,15 @@ class PMFLevel extends PMF{
} }
$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;
} }
protected function isMiniChunkEmpty($X, $Z, $Y){ protected function isMiniChunkEmpty($X, $Z, $Y){
$index = self::getIndex($X, $Z); $index = self::getIndex($X, $Z);
if($this->chunks[$index][$Y] !== false){ if($this->chunks[$index][$Y] !== false){
if(substr_count($this->chunks[$index][$Y], "\x00") < 8192){ if(substr_count($this->chunks[$index][$Y], "\x00") < 10240){
return false; return false;
} }
} }
@ -347,42 +421,79 @@ class PMFLevel extends PMF{
public function getMiniChunk($X, $Z, $Y){ public function getMiniChunk($X, $Z, $Y){
if($this->loadChunk($X, $Z) === false){ if($this->loadChunk($X, $Z) === false){
return str_repeat("\x00", 8192); return str_repeat("\x00", 10240);
} }
$index = self::getIndex($X, $Z); $index = self::getIndex($X, $Z);
if(!isset($this->chunks[$index][$Y]) or $this->chunks[$index][$Y] === false){ if(!isset($this->chunks[$index][$Y]) or $this->chunks[$index][$Y] === false){
return str_repeat("\x00", 8192); return str_repeat("\x00", 10240);
} }
return $this->chunks[$index][$Y]; return $this->chunks[$index][$Y];
} }
public $checkLight = []; public $checkLight = [];
public function loadChunk($X, $Z){ public function loadChunk($X, $Z, $compatver=self::TYPE_CURRENT){
$index = self::getIndex($X, $Z); $index = self::getIndex($X, $Z);
if($this->isChunkLoaded($X, $Z)){ if($this->isChunkLoaded($X, $Z)){
return true; return true;
}elseif(!isset($this->locationTable[$index])){
return false;
} }
$info = $this->locationTable[$index]; if($compatver == self::TYPE_OLD){
$this->seek($info[0]); if(!isset($this->locationTable[$index])){
return false;
}
$info = $this->locationTable[$index];
$this->seek($info[0]);
}else{
$this->locationTable[$index] = 0;
}
$chunk = @gzopen($this->getChunkPath($X, $Z), "rb"); $chunk = @gzopen($this->getChunkPath($X, $Z), "rb");
if($chunk === false){ if($chunk === false){
return false; return false;
} }
if($compatver != self::TYPE_OLD){
$ver = ord(gzread($chunk, 1));
if($ver != self::CHUNK_VERSION){
ConsoleAPI::error("Failed to load chunk $X $Z: chunk version ($ver) doesnt match current (".self::CHUNK_VERSION.")");
@gzclose($chunk);
return false;
}
$info = $this->locationTable[$index] = [Utils::readShort(gzread($chunk, 2), false)];
$this->hasLight[$index] = gzread($chunk, 1);
gzread($chunk, 1); //TODO reserved for shouldTick
}
$this->chunks[$index] = []; $this->chunks[$index] = [];
$this->chunkChange[$index] = [-1 => false]; $this->chunkChange[$index] = [-1 => false];
if($compatver != self::TYPE_CURRENT){
$this->chunkChange[$index][-1] = true; //force save when unloading if loaded with old compat
}
for($Y = 0; $Y < $this->levelData["height"]; ++$Y){ for($Y = 0; $Y < $this->levelData["height"]; ++$Y){
$t = 1 << $Y; $t = 1 << $Y;
if(($info[0] & $t) === $t){ if(($info[0] & $t) === $t){
//TODO do something with skylight if($compatver == self::TYPE_OLD){
// 4096 + 2048 + 2048, Block Data, Meta, Light // 4096 + 2048 + 2048, Block Data, Meta, Light
if(strlen($this->chunks[$index][$Y] = gzread($chunk, 8192)) < 8192){ $cdata = gzread($chunk, 8192);
console("[NOTICE] Empty corrupt chunk detected [$X,$Z,:$Y], recovering contents", true, true, 2); if(strlen($cdata) < 8192){
$this->fillMiniChunk($X, $Z, $Y); console("[NOTICE] Empty corrupt chunk detected [$X,$Z,:$Y], recovering contents", true, true, 2);
$this->fillMiniChunk($X, $Z, $Y);
}
$this->chunks[$index][$Y] = "";
for($i = 0; $i < 8192; $i += 32){
$this->chunks[$index][$Y] .= substr($cdata, $i, 32) . "\x00\x00\x00\x00\x00\x00\x00\x00";
}
}else{
// 4096+2048+2048+2048, Block Data, Meta, blocklight, skylight
if(strlen($this->chunks[$index][$Y] = gzread($chunk, 4096+2048+2048+2048)) < 4096+2048+2048+2048){
console("[NOTICE] Empty corrupt chunk detected [$X,$Z,:$Y], recovering contents(".strlen($this->chunks[$index][$Y]).")", true, true, 2);
$this->fillMiniChunk($X, $Z, $Y);
}
} }
}else{ }else{
$this->chunks[$index][$Y] = false; $this->chunks[$index][$Y] = false;
@ -419,9 +530,9 @@ class PMFLevel extends PMF{
return false; return false;
} }
$index = self::getIndex($X, $Z); $index = self::getIndex($X, $Z);
$this->chunks[$index][$Y] = str_repeat("\x00", 8192); $this->chunks[$index][$Y] = str_repeat("\x00", 10240);
$this->chunkChange[$index][-1] = true; $this->chunkChange[$index][-1] = true;
$this->chunkChange[$index][$Y] = 8192; $this->chunkChange[$index][$Y] = 10240;
$this->locationTable[$index][0] |= 1 << $Y; $this->locationTable[$index][0] |= 1 << $Y;
return true; return true;
} }
@ -436,7 +547,7 @@ class PMFLevel extends PMF{
$index = self::getIndex($X, $Z); $index = self::getIndex($X, $Z);
$this->chunks[$index][$Y] = (string) $data; $this->chunks[$index][$Y] = (string) $data;
$this->chunkChange[$index][-1] = true; $this->chunkChange[$index][-1] = true;
$this->chunkChange[$index][$Y] = 8192; $this->chunkChange[$index][$Y] = 10240;
$this->locationTable[$index][0] |= 1 << $Y; $this->locationTable[$index][0] |= 1 << $Y;
return true; return true;
} }
@ -452,7 +563,7 @@ class PMFLevel extends PMF{
* @return number * @return number
*/ */
public function fastGetBlockID($chunkX, $chunkY, $chunkZ, $blockX, $blockY, $blockZ, $index){ public function fastGetBlockID($chunkX, $chunkY, $chunkZ, $blockX, $blockY, $blockZ, $index){
return ($this->chunks[$index][$chunkY] === false) ? 0 : ord($this->chunks[$index][$chunkY][$blockY + ($blockX << 5) + ($blockZ << 9)]); return ($this->chunks[$index][$chunkY] === false) ? 0 : ord($this->chunks[$index][$chunkY][$blockY + $blockX*40 + $blockZ*640]);
} }
public function getBlockID($x, $y, $z){ public function getBlockID($x, $y, $z){
@ -475,7 +586,7 @@ class PMFLevel extends PMF{
$aZ = $z & 0xf; $aZ = $z & 0xf;
$aY = $y & 0xf; $aY = $y & 0xf;
$b = ord($this->chunks[$index][$Y][($aY + ($aX << 5) + ($aZ << 9))]); $b = ord($this->chunks[$index][$Y][($aY + ($aX*40) + ($aZ*640))]);
return $b; return $b;
} }
@ -494,7 +605,7 @@ class PMFLevel extends PMF{
$aX = $x & 0xf; $aX = $x & 0xf;
$aZ = $z & 0xf; $aZ = $z & 0xf;
$aY = $y & 0xf; $aY = $y & 0xf;
$bind = (int) ($aY + ($aX << 5) + ($aZ << 9)); $bind = (int) ($aY + ($aX*40) + ($aZ*640));
if($this->chunks[$index][$Y][$bind] == chr($block)){ if($this->chunks[$index][$Y][$bind] == chr($block)){
return false; //no changes done return false; //no changes done
}else{ }else{
@ -522,7 +633,7 @@ class PMFLevel extends PMF{
$aX = $x & 0xf; $aX = $x & 0xf;
$aZ = $z & 0xf; $aZ = $z & 0xf;
$aY = $y & 0xf; $aY = $y & 0xf;
$m = ord($this->chunks[$index][$Y][(int) (($aY >> 1) + 24 + ($aX << 5) + ($aZ << 9))]); $m = ord($this->chunks[$index][$Y][(int) (($aY >> 1) + 24 + $aX*40 + $aZ*640)]);
return $y & 1 ? $m >> 4 : $m & 0x0F; return $y & 1 ? $m >> 4 : $m & 0x0F;
} }
@ -543,7 +654,7 @@ class PMFLevel extends PMF{
$aX = $x & 0xf; $aX = $x & 0xf;
$aZ = $z & 0xf; $aZ = $z & 0xf;
$aY = $y & 0xf; $aY = $y & 0xf;
$mindex = (int) (($aY >> 1) + 24 + ($aX << 5) + ($aZ << 9)); $mindex = (int) (($aY >> 1) + 24 + $aX*40 + $aZ*640);
$old_m = ord($this->chunks[$index][$Y][$mindex]); $old_m = ord($this->chunks[$index][$Y][$mindex]);
if(($y & 1) === 0) $m = ($old_m & 0xF0) | $value; if(($y & 1) === 0) $m = ($old_m & 0xF0) | $value;
else $m = ($value << 4) | ($old_m & 0x0F); else $m = ($value << 4) | ($old_m & 0x0F);
@ -575,7 +686,7 @@ class PMFLevel extends PMF{
$aX = $x & 0xf; $aX = $x & 0xf;
$aZ = $z & 0xf; $aZ = $z & 0xf;
$aY = $y & 0xf; $aY = $y & 0xf;
$m = ord($this->chunks[$index][$Y][(int) (($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9))]); $m = ord($this->chunks[$index][$Y][(int) (($aY >> 1) + 16 + $aX*40 + $aZ*640)]);
return $y & 1 ? $m >> 4 : $m & 0x0F; return $y & 1 ? $m >> 4 : $m & 0x0F;
} }
@ -592,7 +703,7 @@ class PMFLevel extends PMF{
$aX = $x & 0xf; $aX = $x & 0xf;
$aZ = $z & 0xf; $aZ = $z & 0xf;
$aY = $y & 0xf; $aY = $y & 0xf;
$mindex = (int) (($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9)); $mindex = (int) (($aY >> 1) + 16 + $aX*40 + $aZ*640);
$old_m = ord($this->chunks[$index][$Y][$mindex]); $old_m = ord($this->chunks[$index][$Y][$mindex]);
if(($y & 1) === 0){ if(($y & 1) === 0){
$m = ($old_m & 0xF0) | $damage; $m = ($old_m & 0xF0) | $damage;
@ -638,9 +749,9 @@ class PMFLevel extends PMF{
$aZ = $z & 0xf; $aZ = $z & 0xf;
$aY = $y & 0xf; $aY = $y & 0xf;
$b = ord($this->chunks[$index][$Y][($aY + ($aX << 5) + ($aZ << 9))]); $b = ord($this->chunks[$index][$Y][($aY + $aX*40 + $aZ*640)]);
$m = ord($this->chunks[$index][$Y][(($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9))]); $m = ord($this->chunks[$index][$Y][(($aY >> 1) + 16 + $aX*40 + $aZ*640)]);
$m = ($y & 1) ? $m >> 4 : $m & 0xf; $m = ($y & 1) ? $m >> 4 : $m & 0xf;
return [$b, $m]; return [$b, $m];
@ -666,8 +777,8 @@ class PMFLevel extends PMF{
$aX = $x - ($X << 4); $aX = $x - ($X << 4);
$aZ = $z - ($Z << 4); $aZ = $z - ($Z << 4);
$aY = $y - ($Y << 4); $aY = $y - ($Y << 4);
$bindex = (int) ($aY + ($aX << 5) + ($aZ << 9)); $bindex = (int) ($aY + $aX*40 + $aZ*640);
$mindex = (int) (($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9)); $mindex = (int) (($aY >> 1) + 16 + $aX*40 + $aZ*640);
$old_b = ord($this->chunks[$index][$Y][$bindex]); $old_b = ord($this->chunks[$index][$Y][$bindex]);
$old_m = ord($this->chunks[$index][$Y][$mindex]); $old_m = ord($this->chunks[$index][$Y][$mindex]);
@ -697,4 +808,9 @@ class PMFLevel extends PMF{
} }
} }
/**
* @deprecated used in nc 1.1.1 for ncleveldata.pmf which was removed
* @var integer
*/
const NC_DATA_VERSION = 1;
} }

View file

@ -732,7 +732,7 @@ class Level{
$y = ($xyz >> 16) & 0x7f; $y = ($xyz >> 16) & 0x7f;
$cy = $ch[$y >> 4]; $cy = $ch[$y >> 4];
if($cy === false) continue; if($cy === false) continue;
$id = ord($cy[($y & 0xf) + ($x << 5) + ($z << 9)]); $id = ord($cy[($y & 0xf) + $x*40 + $z*640]);
if(isset(self::$randomUpdateBlocks[$id])){ if(isset(self::$randomUpdateBlocks[$id])){
$cl = StaticBlock::$prealloc[$id]; $cl = StaticBlock::$prealloc[$id];
$cl::onRandomTick($this, ($cX << 4) + $x, $y, $z + ($cZ << 4)); $cl::onRandomTick($this, ($cX << 4) + $x, $y, $z + ($cZ << 4));
@ -1010,7 +1010,7 @@ class Level{
for($j = 0; $j < 256; ++$j){ for($j = 0; $j < 256; ++$j){
$ordered .= $flag; $ordered .= $flag;
foreach($raw as $mini){ foreach($raw as $mini){
$ordered .= substr($mini, $j << 5, 24); //16 + 8 $ordered .= substr($mini, $j*40, 24); //16 + 8
} }
} }
return $ordered; return $ordered;

View file

@ -74,7 +74,7 @@ class SuperflatGenerator implements LevelGenerator{
$blocks .= chr($this->structure[$y]->getID()); $blocks .= chr($this->structure[$y]->getID());
$metas .= substr(dechex($this->structure[$y]->getMetadata()), -1); $metas .= substr(dechex($this->structure[$y]->getMetadata()), -1);
} }
$this->chunks[$Y] .= $blocks . hex2bin($metas) . "\x00\x00\x00\x00\x00\x00\x00\x00"; $this->chunks[$Y] .= $blocks . hex2bin($metas) . "\x00\x00\x00\x00\x00\x00\x00\x00" . "\x00\x00\x00\x00\x00\x00\x00\x00";
} }
} }
} }

View file

@ -1,5 +1,5 @@
<?php <?php
define("EMPTY_MINI_CHUNK", str_repeat("\x00", 8192)); define("EMPTY_MINI_CHUNK", str_repeat("\x00", 10240));
define("EMPTY_16x16_ARR", array_fill(0, 256, 0)); define("EMPTY_16x16_ARR", array_fill(0, 256, 0));
class VanillaGenerator implements LevelGenerator class VanillaGenerator implements LevelGenerator
{ {
@ -159,7 +159,7 @@ class VanillaGenerator implements LevelGenerator
for($Y = 0; $Y < 8; ++$Y){ for($Y = 0; $Y < 8; ++$Y){
$index = ($chunkZ << 4) + $chunkX; $index = ($chunkZ << 4) + $chunkX;
$this->level->level->chunks[$index][$Y] = $chunkz[$Y]; $this->level->level->chunks[$index][$Y] = $chunkz[$Y];
$this->level->level->chunkChange[$index][$Y] = 8192; $this->level->level->chunkChange[$index][$Y] = 10240;
$this->level->level->locationTable[$index][0] |= 1 << $Y; //TODO mv out of loop $this->level->level->locationTable[$index][0] |= 1 << $Y; //TODO mv out of loop
} }
$this->level->level->chunkChange[$index][-1] = true; $this->level->level->chunkChange[$index][-1] = true;
@ -191,7 +191,7 @@ class VanillaGenerator implements LevelGenerator
for($Y = 7; $Y >= 0; --$Y){ for($Y = 7; $Y >= 0; --$Y){
for($cY = 15; $cY >= 0; --$cY){ for($cY = 15; $cY >= 0; --$cY){
$blockY = $Y*16 + $cY; $blockY = $Y*16 + $cY;
$blockID = ord($chunkz[$Y][$cY + ($blockX << 5) + ($blockZ << 9)]); $blockID = ord($chunkz[$Y][$cY + $blockX*40 + $blockZ*640]);
if($blockID > 0) { if($blockID > 0) {
$heightmapCPtr[$blockX + ($blockZ * 16)] = $blockY + 1 ; $heightmapCPtr[$blockX + ($blockZ * 16)] = $blockY + 1 ;
break 2; break 2;
@ -215,6 +215,7 @@ class VanillaGenerator implements LevelGenerator
$this->sandNoises = $this->beachNoise->generateNoiseOctaves($chunkX * 16, $chunkZ * 16, 0, 16, 16, 1, 0.03125, 0.03125, 1); $this->sandNoises = $this->beachNoise->generateNoiseOctaves($chunkX * 16, $chunkZ * 16, 0, 16, 16, 1, 0.03125, 0.03125, 1);
$this->gravelNoises = $this->beachNoise->generateNoiseOctaves($chunkX * 16, 109.01, $chunkZ * 16, 16, 1, 16, 0.03125, 1, 0.03125); $this->gravelNoises = $this->beachNoise->generateNoiseOctaves($chunkX * 16, 109.01, $chunkZ * 16, 16, 1, 16, 0.03125, 1, 0.03125);
$this->surfaceDepthNoises = $this->surfaceDepthNoise->generateNoiseOctaves($chunkX * 16, $chunkZ * 16, 0, 16, 16, 1, 0.0625, 0.0625, 0.0625); $this->surfaceDepthNoises = $this->surfaceDepthNoise->generateNoiseOctaves($chunkX * 16, $chunkZ * 16, 0, 16, 16, 1, 0.0625, 0.0625, 0.0625);
//TODO blockZ is actually blockX here?
for($blockX = 0; $blockX < 16; ++$blockX){ for($blockX = 0; $blockX < 16; ++$blockX){
for($blockZ = 0; $blockZ < 16; ++$blockZ){ for($blockZ = 0; $blockZ < 16; ++$blockZ){
/** @var Biome $biome **/ /** @var Biome $biome **/
@ -227,9 +228,9 @@ class VanillaGenerator implements LevelGenerator
$b2 = $biome->fillerBlock; $b2 = $biome->fillerBlock;
for($blockY = 127; $blockY >= 0; --$blockY){ for($blockY = 127; $blockY >= 0; --$blockY){
if($blockY <= $this->rand->nextInt(5)){ if($blockY <= $this->rand->nextInt(5)){
$chunks[$blockY >> 4][($blockY & 0xf) + ($blockZ << 5) + ($blockX << 9)] = "\x07"; $chunks[$blockY >> 4][($blockY & 0xf) + $blockZ*40 + $blockX*640] = "\x07";
}else{ }else{
$b3 = ord($chunks[$blockY >> 4][($blockY & 0xf) + ($blockZ << 5) + ($blockX << 9)]); $b3 = ord($chunks[$blockY >> 4][($blockY & 0xf) + $blockZ*40 + $blockX*640]);
if($b3 == 0){ if($b3 == 0){
$i = -1; $i = -1;
}elseif($b3 == STONE){ }elseif($b3 == STONE){
@ -253,10 +254,10 @@ class VanillaGenerator implements LevelGenerator
$b = $blockY < 64 && $b == 0 ? STILL_WATER : $b; $b = $blockY < 64 && $b == 0 ? STILL_WATER : $b;
$i = $nextFloat; $i = $nextFloat;
$chunks[$blockY >> 4][($blockY & 0xf) + ($blockZ << 5) + ($blockX << 9)] = $blockY >= 63 ? chr($b) : chr($b2); $chunks[$blockY >> 4][($blockY & 0xf) + ($blockZ*40) + ($blockX*640)] = $blockY >= 63 ? chr($b) : chr($b2);
}elseif($i > 0){ }elseif($i > 0){
--$i; --$i;
$chunks[$blockY >> 4][($blockY & 0xf) + ($blockZ << 5) + ($blockX << 9)] = chr($b2); $chunks[$blockY >> 4][($blockY & 0xf) + ($blockZ*40) + ($blockX*640)] = chr($b2);
if($i == 0 && $b2 == SAND){ if($i == 0 && $b2 == SAND){
$i = $this->rand->nextInt(4); $i = $this->rand->nextInt(4);
$b2 = SANDSTONE; $b2 = SANDSTONE;
@ -305,7 +306,7 @@ class VanillaGenerator implements LevelGenerator
$fx = ($unkXX + ($unkX * 4)); $fx = ($unkXX + ($unkX * 4));
$fy = (($unkY * 8) + $unkYY); $fy = (($unkY * 8) + $unkYY);
$fz = ($unkZZ + ($unkZ * 4)); $fz = ($unkZZ + ($unkZ * 4));
$chunks[$fy >> 4][($fy & 0xf) + ($fx << 5) + ($fz << 9)] = chr($i3); $chunks[$fy >> 4][($fy & 0xf) + $fx*40 + $fz*640] = chr($i3);
$f13 += $f14; $f13 += $f14;
} }
$f9 += $f11; $f9 += $f11;