Level saving

This commit is contained in:
Shoghi Cervantes Pueyo 2013-05-15 21:03:48 +02:00
parent 78baa237e3
commit e63677a23d
4 changed files with 39 additions and 38 deletions

View File

@ -100,7 +100,7 @@ class LevelAPI{
$level = new PMFLevel($path."level.pmf");
$entities = new Config($path."entities.yml", CONFIG_YAML);
$tileEntities = new Config($path."tileEntities.yml", CONFIG_YAML);
$this->levels[$name] = new Level($level, $entities, $tileEntities);
$this->levels[$name] = new Level($level, $entities, $tileEntities, $name);
foreach($entities->getAll() as $entity){
if(!isset($entity["id"])){
break;

View File

@ -169,7 +169,6 @@ class PocketMinecraftServer{
$this->api->chat->broadcast("Stopping server...");
}
}
$this->save(true);
$this->stop = true;
$this->trigger("server.close", $reason);
$this->interface->close();

View File

@ -180,7 +180,7 @@ class PMFLevel extends PMF{
@ftruncate($this->fp, $this->payloadOffset);
$this->seek($this->payloadOffset);
for($index = 0; $index < $cnt; ++$index){
$this->write(Utils::writeShort($this->locationTable[$index]));
$this->write(Utils::writeShort($this->locationTable[$index][0]));
}
}
@ -246,36 +246,6 @@ class PMFLevel extends PMF{
return true;
}
public function getBlock($x, $y, $z){
$X = $x >> 4;
$Z = $z >> 4;
$Y = $y >> 4;
if($X >= 32 or $Z >= 32 or $Y >= $this->levelData["height"]){
return array(AIR, 0);
}
$index = $this->getIndex($X, $Z);
if($this->chunks[$index] === false){
if($this->loadChunk($X, $Z) === false){
return array(AIR, 0);
}
}elseif($this->chunks[$index][$Y] === false){
return array(AIR, 0);
}
$aX = $x - ($X << 4);
$aZ = $z - ($Z << 4);
$aY = $y - ($Y << 4);
$bindex = $aY + ($aX << 5) + ($aZ << 9);
$mindex = ($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9);
$b = ord($this->chunks[$index][$Y]{$bindex});
$m = ord($this->chunks[$index][$Y]{$mindex});
if(($y & 1) === 0){
$m = $m & 0x0F;
}else{
$m = $m >> 4;
}
return array($b, $m);
}
protected function fillMiniChunk($X, $Z, $Y){
if($this->isChunkLoaded($X, $Z) === false){
return false;
@ -311,13 +281,43 @@ class PMFLevel extends PMF{
return true;
}
public function getBlock($x, $y, $z){
$X = $x >> 4;
$Z = $z >> 4;
$Y = $y >> 4;
if($X >= 32 or $Z >= 32 or $Y >= $this->levelData["height"] or $y < 0){
return array(AIR, 0);
}
$index = $this->getIndex($X, $Z);
if($this->chunks[$index] === false){
if($this->loadChunk($X, $Z) === false){
return array(AIR, 0);
}
}elseif($this->chunks[$index][$Y] === false){
return array(AIR, 0);
}
$aX = $x - ($X << 4);
$aZ = $z - ($Z << 4);
$aY = $y - ($Y << 4);
$bindex = $aY + ($aX << 5) + ($aZ << 9);
$mindex = ($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9);
$b = ord($this->chunks[$index][$Y]{$bindex});
$m = ord($this->chunks[$index][$Y]{$mindex});
if(($y & 1) === 0){
$m = $m & 0x0F;
}else{
$m = $m >> 4;
}
return array($b, $m);
}
public function setBlock($x, $y, $z, $block, $meta = 0){
$X = $x >> 4;
$Z = $z >> 4;
$Y = $y >> 4;
$block &= 0xFF;
$meta &= 0x0F;
if($X >= 32 or $Z >= 32 or $Y >= $this->levelData["height"]){
if($X >= 32 or $Z >= 32 or $Y >= $this->levelData["height"] or $y < 0){
return false;
}
$index = $this->getIndex($X, $Z);
@ -333,7 +333,7 @@ class PMFLevel extends PMF{
$aY = $y - ($Y << 4);
$bindex = $aY + ($aX << 5) + ($aZ << 9);
$mindex = ($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9);
$old_b = $this->chunks[$index][$Y]{$bindex};
$old_b = $this->chunks[$index][$Y]{$bindex};
$old_m = $this->chunks[$index][$Y]{$mindex};
if(($y & 1) === 0){
$old_m = $old_m & 0x0F;

View File

@ -27,9 +27,9 @@ the Free Software Foundation, either version 3 of the License, or
class Level{
public $entities, $tileEntities;
private $level, $time, $startCheck, $startTime, $server;
private $level, $time, $startCheck, $startTime, $server, $name;
public function __construct(PMFLevel $level, Config $entities, Config $tileEntities){
public function __construct(PMFLevel $level, Config $entities, Config $tileEntities, $name){
$this->server = ServerAPI::request();
$this->level = $level;
$this->entities = $entities;
@ -37,6 +37,8 @@ class Level{
$this->startTime = $this->time = (int) $this->level->getData("time");
$this->startCheck = microtime(true);
$this->server->schedule(15, array($this, "checkThings"));
$this->server->event("server.close", array($this, "save"));
$this->name = $name;
}
public function __destruct(){
@ -132,7 +134,7 @@ class Level{
}
public function getName(){
return $this->level->getData("name");
return $this->name;//return $this->level->getData("name");
}
public function setTime($time){