Added core NBT modifications

This commit is contained in:
Shoghi Cervantes
2014-02-26 15:12:58 +01:00
parent 0231bf406e
commit 9cfa49c112
17 changed files with 122 additions and 99 deletions

View File

@ -2250,12 +2250,11 @@ class Player{
$t->spawn($this); $t->spawn($this);
}else{ }else{
$nbt = new NBT(); $nbt = new NBT();
$nbt->load($packet->namedtag); $nbt->read($packet->namedtag);
$d = array_shift($nbt->tree); if($nbt->id !== TILE_SIGN){
if($d["id"] !== TILE_SIGN){
$t->spawn($this); $t->spawn($this);
}else{ }else{
$t->setText($d["Text1"], $d["Text2"], $d["Text3"], $d["Text4"]); $t->setText($nbt->Text1, $nbt->Text2, $nbt->Text3, $nbt->Text4);
} }
} }
} }

View File

@ -48,7 +48,7 @@ class NBT{
return !isset($this->buffer{$this->offset}); return !isset($this->buffer{$this->offset});
} }
public function __construct($endianness = NBT::BIG_ENDIAN){ public function __construct($endianness = NBT::LITTLE_ENDIAN){
$this->offset = 0; $this->offset = 0;
$this->endianness = $endianness & 0x01; $this->endianness = $endianness & 0x01;
} }
@ -193,6 +193,26 @@ class NBT{
$this->buffer .= $v; $this->buffer .= $v;
} }
public function __get($name){
return $this->data instanceof NBTTag_Compound ? $this->data->{$name} : false;
}
public function __set($name, $value){
if($this->data instanceof NBTTag_Compound){
$this->data->{$name} = $value;
}
}
public function __isset($name){
return $this->data instanceof NBTTag_Compound ? isset($this->data->{$name}) : false;
}
public function __unset($name){
if($this->data instanceof NBTTag_Compound){
unset($this->data->{$name});
}
}
public function getData(){ public function getData(){
return $this->data; return $this->data;
} }

View File

@ -23,11 +23,14 @@
require_once("NBTTag.php"); require_once("NBTTag.php");
/***REM_END***/ /***REM_END***/
class NamedNBTTag{ abstract class NamedNBTTag extends NBTTag{
protected $name; protected $name;
public function __construct($name = ""){ public function __construct($name = "", $value = false){
$this->name = $name; $this->name = $name;
if($value !== false){
$this->value = $value;
}
} }
public function getName(){ public function getName(){

View File

@ -22,7 +22,7 @@
class NBTTag_Byte extends NamedNBTTag{ class NBTTag_Byte extends NamedNBTTag{
public function getType(){ public function getType(){
return self::TAG_Byte; return NBTTag::TAG_Byte;
} }
public function read(NBT $nbt){ public function read(NBT $nbt){

View File

@ -22,7 +22,7 @@
class NBTTag_Byte_Array extends NamedNBTTag{ class NBTTag_Byte_Array extends NamedNBTTag{
public function getType(){ public function getType(){
return self::TAG_Byte_Array; return NBTTag::TAG_Byte_Array;
} }
public function read(NBT $nbt){ public function read(NBT $nbt){

View File

@ -22,7 +22,25 @@
class NBTTag_Compound extends NamedNBTTag{ class NBTTag_Compound extends NamedNBTTag{
public function getType(){ public function getType(){
return self::TAG_Compound; return NBTTag::TAG_Compound;
}
public function __get($name){
return isset($this->value[$name]) ? $this->value[$name]->getValue() : false;
}
public function __set($name, $value){
if(isset($this->value[$name])){
$this->value[$name]->setValue($value);
}
}
public function __isset($name){
return isset($this->value[$name]);
}
public function __unset($name){
unset($this->value[$name]);
} }
public function read(NBT $nbt){ public function read(NBT $nbt){

View File

@ -22,7 +22,7 @@
class NBTTag_Double extends NamedNBTTag{ class NBTTag_Double extends NamedNBTTag{
public function getType(){ public function getType(){
return self::TAG_Double; return NBTTag::TAG_Double;
} }
public function read(NBT $nbt){ public function read(NBT $nbt){

View File

@ -22,7 +22,7 @@
class NBTTag_End extends NBTTag{ class NBTTag_End extends NBTTag{
public function getType(){ public function getType(){
return self::TAG_End; return NBTTag::TAG_End;
} }
public function read(NBT $nbt){ public function read(NBT $nbt){

View File

@ -22,7 +22,7 @@
class NBTTag_Float extends NamedNBTTag{ class NBTTag_Float extends NamedNBTTag{
public function getType(){ public function getType(){
return self::TAG_Float; return NBTTag::TAG_Float;
} }
public function read(NBT $nbt){ public function read(NBT $nbt){

View File

@ -22,7 +22,7 @@
class NBTTag_Int extends NamedNBTTag{ class NBTTag_Int extends NamedNBTTag{
public function getType(){ public function getType(){
return self::TAG_Int; return NBTTag::TAG_Int;
} }
public function read(NBT $nbt){ public function read(NBT $nbt){

View File

@ -22,7 +22,7 @@
class NBTTag_Int_Array extends NamedNBTTag{ class NBTTag_Int_Array extends NamedNBTTag{
public function getType(){ public function getType(){
return self::TAG_Int_Array; return NBTTag::TAG_Int_Array;
} }
public function read(NBT $nbt){ public function read(NBT $nbt){

View File

@ -22,7 +22,25 @@
class NBTTag_List extends NamedNBTTag{ class NBTTag_List extends NamedNBTTag{
public function getType(){ public function getType(){
return self::TAG_List; return NBTTag::TAG_List;
}
public function __get($name){
return isset($this->value[$name]) ? $this->value[$name]->getValue() : false;
}
public function __set($name, $value){
if(isset($this->value[$name])){
$this->value[$name]->setValue($value);
}
}
public function __isset($name){
return isset($this->value[$name]);
}
public function __unset($name){
unset($this->value[$name]);
} }
public function read(NBT $nbt){ public function read(NBT $nbt){

View File

@ -22,7 +22,7 @@
class NBTTag_Long extends NamedNBTTag{ class NBTTag_Long extends NamedNBTTag{
public function getType(){ public function getType(){
return self::TAG_Long; return NBTTag::TAG_Long;
} }
public function read(NBT $nbt){ public function read(NBT $nbt){

View File

@ -22,7 +22,7 @@
class NBTTag_Short extends NamedNBTTag{ class NBTTag_Short extends NamedNBTTag{
public function getType(){ public function getType(){
return self::TAG_Short; return NBTTag::TAG_Short;
} }
public function read(NBT $nbt){ public function read(NBT $nbt){

View File

@ -22,7 +22,7 @@
class NBTTag_String extends NamedNBTTag{ class NBTTag_String extends NamedNBTTag{
public function getType(){ public function getType(){
return self::TAG_String; return NBTTag::TAG_String;
} }
public function read(NBT $nbt){ public function read(NBT $nbt){

View File

@ -34,21 +34,21 @@ class LevelImport{
$tiles = new Config($this->path."tiles.yml", CONFIG_YAML, unserialize(file_get_contents($this->path."tileEntities.dat"))); $tiles = new Config($this->path."tiles.yml", CONFIG_YAML, unserialize(file_get_contents($this->path."tileEntities.dat")));
$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(NBT::LITTLE_ENDIAN);
$nbt->load(substr(file_get_contents($this->path."level.dat"), 8)); $nbt->read(substr(file_get_contents($this->path."level.dat"), 8));
$level = array_shift($nbt->tree); $level = $nbt->getData();
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);
$nbt->load(substr(file_get_contents($this->path."entities.dat"), 12)); $nbt->read(substr(file_get_contents($this->path."entities.dat"), 12));
$entities = array_shift($nbt->tree); $entities = $nbt->getData();
if(!isset($entities["TileEntities"])){ if(!isset($entities->TileEntities)){
$entities["TileEntities"] = array(); $entities->TileEntities = array();
} }
$tiles = $entities["TileEntities"]; $tiles = $entities->TileEntities;
$entities = $entities["Entities"]; $entities = $entities->Entities;
$entities = new Config($this->path."entities.yml", CONFIG_YAML, $entities); $entities = new Config($this->path."entities.yml", CONFIG_YAML, $entities);
$entities->save(); $entities->save();
$tiles = new Config($this->path."tiles.yml", CONFIG_YAML, $tiles); $tiles = new Config($this->path."tiles.yml", CONFIG_YAML, $tiles);

View File

@ -356,87 +356,52 @@ class Tile extends Position{
} }
switch($this->class){ switch($this->class){
case TILE_CHEST: case TILE_CHEST:
$nbt = new NBT(); $nbt = new NBT(NBT::LITTLE_ENDIAN);
$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_Int((int) $this->x);
$nbt->write(chr(NBT::TAG_INT));
$nbt->writeTAG_String("y");
$nbt->writeTAG_Int((int) $this->y);
$nbt->write(chr(NBT::TAG_INT));
$nbt->writeTAG_String("z");
$nbt->writeTAG_Int((int) $this->z);
if($this->isPaired()){ if($this->isPaired()){
$nbt->write(chr(NBT::TAG_INT)); $nbt->setData(new NBTTag_Compound("", array(
$nbt->writeTAG_String("pairx"); new NBTTag_String("id", $this->class),
$nbt->writeTAG_Int((int) $this->data["pairx"]); new NBTTag_Int("x", (int) $this->x),
new NBTTag_Int("y", (int) $this->y),
$nbt->write(chr(NBT::TAG_INT)); new NBTTag_Int("z", (int) $this->z),
$nbt->writeTAG_String("pairz"); new NBTTag_Int("pairx", (int) $this->data["pairx"]),
$nbt->writeTAG_Int((int) $this->data["pairz"]); new NBTTag_Int("pairz", (int) $this->data["pairz"]),
new NBTTag_End
)));
}else{
$nbt->setData(new NBTTag_Compound("", array(
new NBTTag_String("id", $this->class),
new NBTTag_String("x", (int) $this->x),
new NBTTag_String("y", (int) $this->y),
new NBTTag_String("z", (int) $this->z),
new NBTTag_End
)));
} }
$nbt->write(chr(NBT::TAG_END));
$pk = new EntityDataPacket; $pk = new EntityDataPacket;
$pk->x = $this->x; $pk->x = $this->x;
$pk->y = $this->y; $pk->y = $this->y;
$pk->z = $this->z; $pk->z = $this->z;
$pk->namedtag = $nbt->binary; $pk->namedtag = $nbt->write();
$player->dataPacket($pk); $player->dataPacket($pk);
break; break;
case TILE_SIGN: case TILE_SIGN:
$nbt = new NBT(); $nbt = new NBT(NBT::LITTLE_ENDIAN);
$nbt->write(chr(NBT::TAG_COMPOUND)."\x00\x00"); $nbt->setData(new NBTTag_Compound("", array(
new NBTTag_String("Text1", $this->data["Text1"]),
$nbt->write(chr(NBT::TAG_STRING)); new NBTTag_String("Text2", $this->data["Text2"]),
$nbt->writeTAG_String("Text1"); new NBTTag_String("Text3", $this->data["Text3"]),
$nbt->writeTAG_String($this->data["Text1"]); new NBTTag_String("Text4", $this->data["Text4"]),
new NBTTag_String("id", $this->class),
$nbt->write(chr(NBT::TAG_STRING)); new NBTTag_Int("x", (int) $this->x),
$nbt->writeTAG_String("Text2"); new NBTTag_Int("y", (int) $this->y),
$nbt->writeTAG_String($this->data["Text2"]); new NBTTag_Int("z", (int) $this->z),
new NBTTag_End
$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_Int((int) $this->x);
$nbt->write(chr(NBT::TAG_INT));
$nbt->writeTAG_String("y");
$nbt->writeTAG_Int((int) $this->y);
$nbt->write(chr(NBT::TAG_INT));
$nbt->writeTAG_String("z");
$nbt->writeTAG_Int((int) $this->z);
$nbt->write(chr(NBT::TAG_END));
$pk = new EntityDataPacket; $pk = new EntityDataPacket;
$pk->x = $this->x; $pk->x = $this->x;
$pk->y = $this->y; $pk->y = $this->y;
$pk->z = $this->z; $pk->z = $this->z;
$pk->namedtag = $nbt->binary; $pk->namedtag = $nbt->write();
$player->dataPacket($pk); $player->dataPacket($pk);
break; break;
} }