mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 16:51:42 +00:00
Saving entities/tiles
This commit is contained in:
parent
fb69cf3392
commit
e0e724bcc3
@ -143,36 +143,6 @@ class LevelAPI{
|
||||
return $this->server->spawn;
|
||||
}
|
||||
|
||||
/*
|
||||
if(file_exists(DATA_PATH."worlds/level.dat")){
|
||||
console("[NOTICE] Detected unimported map data. Importing...");
|
||||
$this->importMap(DATA_PATH."worlds/", true);
|
||||
}
|
||||
|
||||
$this->server->mapName = $this->getProperty("level-name");
|
||||
$this->server->mapDir = DATA_PATH."worlds/".$this->server->mapName."/";
|
||||
if($this->server->mapName === false or trim($this->server->mapName) === "" or (!file_exists($this->server->mapDir."chunks.dat") and !file_exists($this->server->mapDir."chunks.dat.gz") and !file_exists($this->server->mapDir."level.pmf"))){
|
||||
if($this->server->mapName === false or trim($this->server->mapName) === ""){
|
||||
$this->server->mapName = "world";
|
||||
}
|
||||
$this->server->mapDir = DATA_PATH."worlds/".$this->server->mapName."/";
|
||||
$generator = "SuperflatGenerator";
|
||||
if($this->getProperty("generator") !== false and class_exists($this->getProperty("generator"))){
|
||||
$generator = $this->getProperty("generator");
|
||||
}
|
||||
$this->gen = new WorldGenerator($generator, $this->server->seed);
|
||||
if($this->getProperty("generator-settings") !== false and trim($this->getProperty("generator-settings")) != ""){
|
||||
$this->gen->set("preset", $this->getProperty("generator-settings"));
|
||||
}
|
||||
$this->gen->init();
|
||||
$this->gen->generate();
|
||||
$this->gen->save($this->server->mapDir, $this->server->mapName);
|
||||
$this->setProperty("level-name", $this->server->mapName);
|
||||
$this->setProperty("gamemode", SURVIVAL);
|
||||
}
|
||||
$this->server->loadMap();
|
||||
*/
|
||||
|
||||
public function loadMap(){
|
||||
if($this->mapName !== false and trim($this->mapName) !== ""){
|
||||
if(!file_exists($this->mapDir."level.pmf")){
|
||||
|
@ -71,7 +71,7 @@ class TileEntityAPI{
|
||||
$l = $this->server->query("SELECT ID FROM tileentities WHERE level = '".$level->getName()."';");
|
||||
if($l !== false and $l !== true){
|
||||
while(($t = $l->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$t = $this->get($e["ID"]);
|
||||
$t = $this->getByID($t["ID"]);
|
||||
if($t instanceof TileEntity){
|
||||
$tileEntities[$t->id] = $t;
|
||||
}
|
||||
|
@ -159,6 +159,10 @@ class Config{
|
||||
$this->config[$k] = $v;
|
||||
}
|
||||
|
||||
public function setAll($v){
|
||||
$this->config = $v;
|
||||
}
|
||||
|
||||
public function exists($k){
|
||||
return isset($this->config[$k]);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ class Level{
|
||||
$this->tileEntities = $tileEntities;
|
||||
$this->startTime = $this->time = (int) $this->level->getData("time");
|
||||
$this->nextSave = $this->startCheck = microtime(true);
|
||||
$this->nextSave += 30;
|
||||
$this->nextSave += 90;
|
||||
$this->server->schedule(15, array($this, "checkThings"), array(), true);
|
||||
$this->server->event("server.close", array($this, "save"));
|
||||
$this->name = $name;
|
||||
@ -78,7 +78,7 @@ class Level{
|
||||
|
||||
if($this->nextSave < $now){
|
||||
$this->save();
|
||||
$this->lastSave = $now + 30;
|
||||
$this->lastSave = $now + 90;
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,6 +88,72 @@ class Level{
|
||||
}
|
||||
|
||||
public function save(){
|
||||
$entities = array();
|
||||
foreach($this->server->api->entity->getAll($this) as $entity){
|
||||
if($entity->class === ENTITY_MOB){
|
||||
$entities[] = array(
|
||||
"id" => $entity->type,
|
||||
"Color" => @$entity->data["Color"],
|
||||
"Sheared" => @$entity->data["Sheared"],
|
||||
"Health" => $entity->health,
|
||||
"Pos" => array(
|
||||
0 => $entity->x,
|
||||
1 => $entity->y,
|
||||
2 => $entity->z,
|
||||
),
|
||||
"Rotation" => array(
|
||||
0 => $entity->yaw,
|
||||
1 => $entity->pitch,
|
||||
),
|
||||
);
|
||||
}elseif($entity->class === ENTITY_OBJECT){
|
||||
$entities[] = array(
|
||||
"id" => $entity->type,
|
||||
"TileX" => $entity->x,
|
||||
"TileX" => $entity->y,
|
||||
"TileX" => $entity->z,
|
||||
"Health" => $entity->health,
|
||||
"Motive" => $entity->data["Motive"],
|
||||
"Pos" => array(
|
||||
0 => $entity->x,
|
||||
1 => $entity->y,
|
||||
2 => $entity->z,
|
||||
),
|
||||
"Rotation" => array(
|
||||
0 => $entity->yaw,
|
||||
1 => $entity->pitch,
|
||||
),
|
||||
);
|
||||
}elseif($entity->class === ENTITY_ITEM){
|
||||
$entities[] = array(
|
||||
"id" => 64,
|
||||
"Item" => array(
|
||||
"id" => $entity->type,
|
||||
"Damage" => $entity->meta,
|
||||
"Count" => $entity->stack,
|
||||
),
|
||||
"Health" => $entity->health,
|
||||
"Pos" => array(
|
||||
0 => $entity->x,
|
||||
1 => $entity->y,
|
||||
2 => $entity->z,
|
||||
),
|
||||
"Rotation" => array(
|
||||
0 => 0,
|
||||
1 => 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->entities->setAll($entities);
|
||||
$this->entities->save();
|
||||
$tiles = array();
|
||||
foreach($this->server->api->tileentity->getAll($this) as $tile){
|
||||
$tiles[] = $tile->data;
|
||||
}
|
||||
$this->tileEntities->setAll($tiles);
|
||||
$this->tileEntities->save();
|
||||
|
||||
$this->level->setData("time", (int) $this->time);
|
||||
$this->level->doSaveRound();
|
||||
$this->level->saveData();
|
||||
|
Loading…
x
Reference in New Issue
Block a user