mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-23 00:55:57 +00:00
Added core NBT modifications
This commit is contained in:
parent
0231bf406e
commit
9cfa49c112
@ -2250,12 +2250,11 @@ class Player{
|
||||
$t->spawn($this);
|
||||
}else{
|
||||
$nbt = new NBT();
|
||||
$nbt->load($packet->namedtag);
|
||||
$d = array_shift($nbt->tree);
|
||||
if($d["id"] !== TILE_SIGN){
|
||||
$nbt->read($packet->namedtag);
|
||||
if($nbt->id !== TILE_SIGN){
|
||||
$t->spawn($this);
|
||||
}else{
|
||||
$t->setText($d["Text1"], $d["Text2"], $d["Text3"], $d["Text4"]);
|
||||
$t->setText($nbt->Text1, $nbt->Text2, $nbt->Text3, $nbt->Text4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ class NBT{
|
||||
return !isset($this->buffer{$this->offset});
|
||||
}
|
||||
|
||||
public function __construct($endianness = NBT::BIG_ENDIAN){
|
||||
public function __construct($endianness = NBT::LITTLE_ENDIAN){
|
||||
$this->offset = 0;
|
||||
$this->endianness = $endianness & 0x01;
|
||||
}
|
||||
@ -193,6 +193,26 @@ class NBT{
|
||||
$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(){
|
||||
return $this->data;
|
||||
}
|
||||
|
@ -23,11 +23,14 @@
|
||||
require_once("NBTTag.php");
|
||||
/***REM_END***/
|
||||
|
||||
class NamedNBTTag{
|
||||
abstract class NamedNBTTag extends NBTTag{
|
||||
|
||||
protected $name;
|
||||
public function __construct($name = ""){
|
||||
public function __construct($name = "", $value = false){
|
||||
$this->name = $name;
|
||||
if($value !== false){
|
||||
$this->value = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
|
@ -22,7 +22,7 @@
|
||||
class NBTTag_Byte extends NamedNBTTag{
|
||||
|
||||
public function getType(){
|
||||
return self::TAG_Byte;
|
||||
return NBTTag::TAG_Byte;
|
||||
}
|
||||
|
||||
public function read(NBT $nbt){
|
||||
|
@ -22,7 +22,7 @@
|
||||
class NBTTag_Byte_Array extends NamedNBTTag{
|
||||
|
||||
public function getType(){
|
||||
return self::TAG_Byte_Array;
|
||||
return NBTTag::TAG_Byte_Array;
|
||||
}
|
||||
|
||||
public function read(NBT $nbt){
|
||||
|
@ -22,7 +22,25 @@
|
||||
class NBTTag_Compound extends NamedNBTTag{
|
||||
|
||||
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){
|
||||
|
@ -22,7 +22,7 @@
|
||||
class NBTTag_Double extends NamedNBTTag{
|
||||
|
||||
public function getType(){
|
||||
return self::TAG_Double;
|
||||
return NBTTag::TAG_Double;
|
||||
}
|
||||
|
||||
public function read(NBT $nbt){
|
||||
|
@ -22,7 +22,7 @@
|
||||
class NBTTag_End extends NBTTag{
|
||||
|
||||
public function getType(){
|
||||
return self::TAG_End;
|
||||
return NBTTag::TAG_End;
|
||||
}
|
||||
|
||||
public function read(NBT $nbt){
|
||||
|
@ -22,7 +22,7 @@
|
||||
class NBTTag_Float extends NamedNBTTag{
|
||||
|
||||
public function getType(){
|
||||
return self::TAG_Float;
|
||||
return NBTTag::TAG_Float;
|
||||
}
|
||||
|
||||
public function read(NBT $nbt){
|
||||
|
@ -22,7 +22,7 @@
|
||||
class NBTTag_Int extends NamedNBTTag{
|
||||
|
||||
public function getType(){
|
||||
return self::TAG_Int;
|
||||
return NBTTag::TAG_Int;
|
||||
}
|
||||
|
||||
public function read(NBT $nbt){
|
||||
|
@ -22,7 +22,7 @@
|
||||
class NBTTag_Int_Array extends NamedNBTTag{
|
||||
|
||||
public function getType(){
|
||||
return self::TAG_Int_Array;
|
||||
return NBTTag::TAG_Int_Array;
|
||||
}
|
||||
|
||||
public function read(NBT $nbt){
|
||||
|
@ -22,7 +22,25 @@
|
||||
class NBTTag_List extends NamedNBTTag{
|
||||
|
||||
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){
|
||||
|
@ -22,7 +22,7 @@
|
||||
class NBTTag_Long extends NamedNBTTag{
|
||||
|
||||
public function getType(){
|
||||
return self::TAG_Long;
|
||||
return NBTTag::TAG_Long;
|
||||
}
|
||||
|
||||
public function read(NBT $nbt){
|
||||
|
@ -22,7 +22,7 @@
|
||||
class NBTTag_Short extends NamedNBTTag{
|
||||
|
||||
public function getType(){
|
||||
return self::TAG_Short;
|
||||
return NBTTag::TAG_Short;
|
||||
}
|
||||
|
||||
public function read(NBT $nbt){
|
||||
|
@ -22,7 +22,7 @@
|
||||
class NBTTag_String extends NamedNBTTag{
|
||||
|
||||
public function getType(){
|
||||
return self::TAG_String;
|
||||
return NBTTag::TAG_String;
|
||||
}
|
||||
|
||||
public function read(NBT $nbt){
|
||||
|
@ -34,21 +34,21 @@ class LevelImport{
|
||||
$tiles = new Config($this->path."tiles.yml", CONFIG_YAML, unserialize(file_get_contents($this->path."tileEntities.dat")));
|
||||
$tiles->save();
|
||||
}elseif(file_exists($this->path."chunks.dat") and file_exists($this->path."level.dat")){ //Pocket
|
||||
$nbt = new NBT();
|
||||
$nbt->load(substr(file_get_contents($this->path."level.dat"), 8));
|
||||
$level = array_shift($nbt->tree);
|
||||
if($level["LevelName"] == ""){
|
||||
$level["LevelName"] = "world".time();
|
||||
$nbt = new NBT(NBT::LITTLE_ENDIAN);
|
||||
$nbt->read(substr(file_get_contents($this->path."level.dat"), 8));
|
||||
$level = $nbt->getData();
|
||||
if($level->LevelName == ""){
|
||||
$level->LevelName = "world".time();
|
||||
}
|
||||
console("[INFO] Importing Pocket level \"".$level["LevelName"]."\" to PMF format");
|
||||
unset($level["Player"]);
|
||||
$nbt->load(substr(file_get_contents($this->path."entities.dat"), 12));
|
||||
$entities = array_shift($nbt->tree);
|
||||
if(!isset($entities["TileEntities"])){
|
||||
$entities["TileEntities"] = array();
|
||||
console("[INFO] Importing Pocket level \"".$level->LevelName."\" to PMF format");
|
||||
unset($level->Player);
|
||||
$nbt->read(substr(file_get_contents($this->path."entities.dat"), 12));
|
||||
$entities = $nbt->getData();
|
||||
if(!isset($entities->TileEntities)){
|
||||
$entities->TileEntities = array();
|
||||
}
|
||||
$tiles = $entities["TileEntities"];
|
||||
$entities = $entities["Entities"];
|
||||
$tiles = $entities->TileEntities;
|
||||
$entities = $entities->Entities;
|
||||
$entities = new Config($this->path."entities.yml", CONFIG_YAML, $entities);
|
||||
$entities->save();
|
||||
$tiles = new Config($this->path."tiles.yml", CONFIG_YAML, $tiles);
|
||||
|
@ -356,87 +356,52 @@ class Tile extends Position{
|
||||
}
|
||||
switch($this->class){
|
||||
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_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 = new NBT(NBT::LITTLE_ENDIAN);
|
||||
if($this->isPaired()){
|
||||
$nbt->write(chr(NBT::TAG_INT));
|
||||
$nbt->writeTAG_String("pairx");
|
||||
$nbt->writeTAG_Int((int) $this->data["pairx"]);
|
||||
|
||||
$nbt->write(chr(NBT::TAG_INT));
|
||||
$nbt->writeTAG_String("pairz");
|
||||
$nbt->writeTAG_Int((int) $this->data["pairz"]);
|
||||
$nbt->setData(new NBTTag_Compound("", array(
|
||||
new NBTTag_String("id", $this->class),
|
||||
new NBTTag_Int("x", (int) $this->x),
|
||||
new NBTTag_Int("y", (int) $this->y),
|
||||
new NBTTag_Int("z", (int) $this->z),
|
||||
new NBTTag_Int("pairx", (int) $this->data["pairx"]),
|
||||
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->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$pk->namedtag = $nbt->binary;
|
||||
$pk->namedtag = $nbt->write();
|
||||
$player->dataPacket($pk);
|
||||
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_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));
|
||||
|
||||
$nbt = new NBT(NBT::LITTLE_ENDIAN);
|
||||
$nbt->setData(new NBTTag_Compound("", array(
|
||||
new NBTTag_String("Text1", $this->data["Text1"]),
|
||||
new NBTTag_String("Text2", $this->data["Text2"]),
|
||||
new NBTTag_String("Text3", $this->data["Text3"]),
|
||||
new NBTTag_String("Text4", $this->data["Text4"]),
|
||||
new NBTTag_String("id", $this->class),
|
||||
new NBTTag_Int("x", (int) $this->x),
|
||||
new NBTTag_Int("y", (int) $this->y),
|
||||
new NBTTag_Int("z", (int) $this->z),
|
||||
new NBTTag_End
|
||||
)));
|
||||
$pk = new EntityDataPacket;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$pk->namedtag = $nbt->binary;
|
||||
$pk->namedtag = $nbt->write();
|
||||
$player->dataPacket($pk);
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user