mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-20 12:44:01 +00:00
Update Tiles to use NBT
This commit is contained in:
parent
ff99aab6ff
commit
9ec51b18fe
@ -41,13 +41,15 @@ class LevelImport{
|
||||
$tiles->save();
|
||||
}elseif(file_exists($this->path."chunks.dat") and file_exists($this->path."level.dat")){ //Pocket
|
||||
$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"] == ""){
|
||||
$level["LevelName"] = "world".time();
|
||||
}
|
||||
console("[INFO] Importing Pocket level \"".$level["LevelName"]."\" to PMF format");
|
||||
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"])){
|
||||
$entities["TileEntities"] = array();
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ class Tile extends Position{
|
||||
$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.");");
|
||||
switch($this->class){
|
||||
case TILE_CHEST:
|
||||
case TILE_SIGN:
|
||||
$this->server->query("UPDATE tiles SET spawnable = 1 WHERE ID = ".$this->id.";");
|
||||
break;
|
||||
@ -77,6 +78,35 @@ class Tile extends Position{
|
||||
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(){
|
||||
if($this->closed === true){
|
||||
@ -204,16 +234,88 @@ class Tile extends Position{
|
||||
$player = $this->server->api->player->get($player);
|
||||
}
|
||||
switch($this->class){
|
||||
case TILE_SIGN:
|
||||
$player->dataPacket(MC_SIGN_UPDATE, array(
|
||||
"level" => $this->level,
|
||||
case TILE_CHEST:
|
||||
$nbt = new NBT();
|
||||
$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,
|
||||
"y" => $this->y,
|
||||
"z" => $this->z,
|
||||
"line0" => $this->data["Text1"],
|
||||
"line1" => $this->data["Text2"],
|
||||
"line2" => $this->data["Text3"],
|
||||
"line3" => $this->data["Text4"],
|
||||
"namedtag" => $nbt->binary,
|
||||
));
|
||||
break;
|
||||
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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user