Automatically set Entity / Tile entity save identifiers

This commit is contained in:
Shoghi Cervantes
2014-11-04 12:04:08 +01:00
parent a5369b3570
commit 8fd6582e74
31 changed files with 49 additions and 74 deletions

View File

@ -43,7 +43,6 @@ class Chest extends Spawnable implements InventoryHolder, Container{
protected $doubleInventory = null;
public function __construct(FullChunk $chunk, Compound $nbt){
$nbt->id = new String("id", Tile::CHEST);
parent::__construct($chunk, $nbt);
$this->inventory = new ChestInventory($this);

View File

@ -42,7 +42,6 @@ class Furnace extends Tile implements InventoryHolder, Container{
protected $inventory;
public function __construct(FullChunk $chunk, Compound $nbt){
$nbt->id = new String("id", Tile::FURNACE);
parent::__construct($chunk, $nbt);
$this->inventory = new FurnaceInventory($this);

View File

@ -29,7 +29,6 @@ use pocketmine\nbt\tag\String;
class Sign extends Spawnable{
public function __construct(FullChunk $chunk, Compound $nbt){
$nbt->id = new String("id", Tile::SIGN);
if(!isset($nbt->Text1)){
$nbt->Text1 = new String("Text1", "");
}

View File

@ -32,6 +32,7 @@ use pocketmine\level\Level;
use pocketmine\level\Position;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Int;
use pocketmine\nbt\tag\String;
use pocketmine\utils\ChunkException;
abstract class Tile extends Position{
@ -41,8 +42,8 @@ abstract class Tile extends Position{
public static $tileCount = 1;
/** @var Tile[] */
private static $knownTiles = [];
private static $shortNames = [];
/** @var Chunk */
public $chunk;
@ -88,12 +89,22 @@ abstract class Tile extends Position{
$class = new \ReflectionClass($className);
if(is_a($className, Tile::class, true) and !$class->isAbstract()){
self::$knownTiles[$class->getShortName()] = $className;
self::$shortNames[$className] = $class->getShortName();
return true;
}
return false;
}
/**
* Returns the short save name
*
* @return string
*/
public function getSaveId(){
return self::$shortNames[static::class];
}
public function __construct(FullChunk $chunk, Compound $nbt){
if($chunk === null or $chunk->getProvider() === null){
throw new ChunkException("Invalid garbage Chunk given to Tile");
@ -117,11 +128,12 @@ abstract class Tile extends Position{
$this->tickTimer = Timings::getTileEntityTimings($this);
}
public function getID(){
public function getId(){
return $this->id;
}
public function saveNBT(){
$this->namedtag->id = new String("id", $this->getSaveId());
$this->namedtag->x = new Int("x", $this->x);
$this->namedtag->y = new Int("y", $this->y);
$this->namedtag->z = new Int("z", $this->z);