Update Tiles to use NBT

This commit is contained in:
Shoghi Cervantes 2013-08-26 23:35:04 +02:00
parent ff99aab6ff
commit 9ec51b18fe
2 changed files with 113 additions and 9 deletions

View File

@ -41,13 +41,15 @@ class LevelImport{
$tiles->save(); $tiles->save();
}elseif(file_exists($this->path."chunks.dat") and file_exists($this->path."level.dat")){ //Pocket }elseif(file_exists($this->path."chunks.dat") and file_exists($this->path."level.dat")){ //Pocket
$nbt = new NBT(); $nbt = new NBT();
$level = parseNBTData($nbt->loadFile($this->path."level.dat")); $nbt->load(file_get_contents($this->path."level.dat"));
$level = array_shift($nbt->tree);
if($level["LevelName"] == ""){ if($level["LevelName"] == ""){
$level["LevelName"] = "world".time(); $level["LevelName"] = "world".time();
} }
console("[INFO] Importing Pocket level \"".$level["LevelName"]."\" to PMF format"); console("[INFO] Importing Pocket level \"".$level["LevelName"]."\" to PMF format");
unset($level["Player"]); unset($level["Player"]);
$entities = parseNBTData($nbt->loadFile($this->path."entities.dat")); $nbt->load(substr(file_get_contents($this->path."entities.dat"), 12));
$entities = array_shift($nbt->tree);
if(!isset($entities["TileEntities"])){ if(!isset($entities["TileEntities"])){
$entities["TileEntities"] = array(); $entities["TileEntities"] = array();
} }

View File

@ -57,6 +57,7 @@ class Tile extends Position{
$this->z = (int) $z; $this->z = (int) $z;
$this->server->query("INSERT OR REPLACE INTO tiles (ID, level, class, x, y, z) VALUES (".$this->id.", '".$this->level->getName()."', '".$this->class."', ".$this->x.", ".$this->y.", ".$this->z.");"); $this->server->query("INSERT OR REPLACE INTO tiles (ID, level, class, x, y, z) VALUES (".$this->id.", '".$this->level->getName()."', '".$this->class."', ".$this->x.", ".$this->y.", ".$this->z.");");
switch($this->class){ switch($this->class){
case TILE_CHEST:
case TILE_SIGN: case TILE_SIGN:
$this->server->query("UPDATE tiles SET spawnable = 1 WHERE ID = ".$this->id.";"); $this->server->query("UPDATE tiles SET spawnable = 1 WHERE ID = ".$this->id.";");
break; break;
@ -77,6 +78,35 @@ class Tile extends Position{
break; break;
} }
} }
public function isPaired(){
if($this->class !== TILE_CHEST){
return false;
}
if(!isset($this->data["pairx"]) or !isset($this->data["pairz"])){
return false;
}
return true;
}
public function getPair(){
if($this->isPaired()){
return $this->server->api->tile->get(new Position((int) $this->data["pairx"], $this->y, (int) $this->data["pairz"], $this->level));
}
return false;
}
public function pairWith(Tile $tile){
if($this->isPaired()or $tile->isPaired()){
return false;
}
$this->data["pairx"] = $tile->x;
$this->data["pairz"] = $tile->z;
$tile->data["pairx"] = $this->x;
$tile->data["pairz"] = $this->z;
}
public function update(){ public function update(){
if($this->closed === true){ if($this->closed === true){
@ -204,16 +234,88 @@ class Tile extends Position{
$player = $this->server->api->player->get($player); $player = $this->server->api->player->get($player);
} }
switch($this->class){ switch($this->class){
case TILE_SIGN: case TILE_CHEST:
$player->dataPacket(MC_SIGN_UPDATE, array( $nbt = new NBT();
"level" => $this->level, $nbt->write(chr(NBT::TAG_COMPOUND)."\x00\x00");
$nbt->write(chr(NBT::TAG_STRING));
$nbt->writeTAG_String("id");
$nbt->writeTAG_String($this->class);
$nbt->write(chr(NBT::TAG_INT));
$nbt->writeTAG_String("x");
$nbt->writeTAG_String((int) $this->x);
$nbt->write(chr(NBT::TAG_INT));
$nbt->writeTAG_String("y");
$nbt->writeTAG_String((int) $this->y);
$nbt->write(chr(NBT::TAG_INT));
$nbt->writeTAG_String("z");
$nbt->writeTAG_String((int) $this->z);
if($this->isPaired()){
$nbt->write(chr(NBT::TAG_INT));
$nbt->writeTAG_String("pairx");
$nbt->writeTAG_String((int) $this->data["pairx"]);
$nbt->write(chr(NBT::TAG_INT));
$nbt->writeTAG_String("pairz");
$nbt->writeTAG_String((int) $this->data["pairz"]);
}
$nbt->write(chr(NBT::TAG_END));
$player->dataPacket(MC_ENTITY_DATA, array(
"x" => $this->x, "x" => $this->x,
"y" => $this->y, "y" => $this->y,
"z" => $this->z, "z" => $this->z,
"line0" => $this->data["Text1"], "namedtag" => $nbt->binary,
"line1" => $this->data["Text2"], ));
"line2" => $this->data["Text3"], break;
"line3" => $this->data["Text4"], case TILE_SIGN:
$nbt = new NBT();
$nbt->write(chr(NBT::TAG_COMPOUND)."\x00\x00");
$nbt->write(chr(NBT::TAG_STRING));
$nbt->writeTAG_String("Text1");
$nbt->writeTAG_String($this->data["Text1"]);
$nbt->write(chr(NBT::TAG_STRING));
$nbt->writeTAG_String("Text2");
$nbt->writeTAG_String($this->data["Text2"]);
$nbt->write(chr(NBT::TAG_STRING));
$nbt->writeTAG_String("Text3");
$nbt->writeTAG_String($this->data["Text3"]);
$nbt->write(chr(NBT::TAG_STRING));
$nbt->writeTAG_String("Text4");
$nbt->writeTAG_String($this->data["Text4"]);
$nbt->write(chr(NBT::TAG_STRING));
$nbt->writeTAG_String("id");
$nbt->writeTAG_String($this->class);
$nbt->write(chr(NBT::TAG_INT));
$nbt->writeTAG_String("x");
$nbt->writeTAG_String((int) $this->x);
$nbt->write(chr(NBT::TAG_INT));
$nbt->writeTAG_String("y");
$nbt->writeTAG_String((int) $this->y);
$nbt->write(chr(NBT::TAG_INT));
$nbt->writeTAG_String("z");
$nbt->writeTAG_String((int) $this->z);
$nbt->write(chr(NBT::TAG_END));
$player->dataPacket(MC_ENTITY_DATA, array(
"x" => $this->x,
"y" => $this->y,
"z" => $this->z,
"namedtag" => $nbt->binary,
)); ));
break; break;
} }