diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 50db91f34..6b74d2317 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -794,7 +794,7 @@ class Block extends Position implements Metadatable{ /** * @return int */ - final public function getID(){ + final public function getId(){ return $this->id; } diff --git a/src/pocketmine/entity/Arrow.php b/src/pocketmine/entity/Arrow.php index d6d067e8e..ea8b0a294 100644 --- a/src/pocketmine/entity/Arrow.php +++ b/src/pocketmine/entity/Arrow.php @@ -45,12 +45,6 @@ class Arrow extends Projectile{ parent::__construct($chunk, $nbt); } - protected function initEntity(){ - $this->namedtag->id = new String("id", "Arrow"); - parent::initEntity(); - - } - public function onUpdate($currentTick){ if($this->closed){ return false; diff --git a/src/pocketmine/entity/Chicken.php b/src/pocketmine/entity/Chicken.php index 651342b0f..305d9bfdd 100644 --- a/src/pocketmine/entity/Chicken.php +++ b/src/pocketmine/entity/Chicken.php @@ -26,7 +26,4 @@ use pocketmine\nbt\tag\String; class Chicken extends Animal{ - protected function initEntity(){ - $this->namedtag->id = new String("id", "Chicken"); - } } \ No newline at end of file diff --git a/src/pocketmine/entity/Cow.php b/src/pocketmine/entity/Cow.php index a9caf21db..16ee11b8a 100644 --- a/src/pocketmine/entity/Cow.php +++ b/src/pocketmine/entity/Cow.php @@ -25,7 +25,5 @@ namespace pocketmine\entity; use pocketmine\nbt\tag\String; class Cow extends Animal{ - protected function initEntity(){ - $this->namedtag->id = new String("id", "Cow"); - } + } \ No newline at end of file diff --git a/src/pocketmine/entity/Creeper.php b/src/pocketmine/entity/Creeper.php index 040f72e13..b329a8a6e 100644 --- a/src/pocketmine/entity/Creeper.php +++ b/src/pocketmine/entity/Creeper.php @@ -25,7 +25,5 @@ namespace pocketmine\entity; use pocketmine\nbt\tag\String; class Creeper extends Monster implements Explosive{ - protected function initEntity(){ - $this->namedtag->id = new String("id", "Creeper"); - } + } \ No newline at end of file diff --git a/src/pocketmine/entity/Egg.php b/src/pocketmine/entity/Egg.php index 87eb24c79..3f765d424 100644 --- a/src/pocketmine/entity/Egg.php +++ b/src/pocketmine/entity/Egg.php @@ -25,7 +25,5 @@ namespace pocketmine\entity; use pocketmine\nbt\tag\String; class Egg extends Projectile{ - protected function initEntity(){ - $this->namedtag->id = new String("id", "Egg"); - } + } \ No newline at end of file diff --git a/src/pocketmine/entity/Enderman.php b/src/pocketmine/entity/Enderman.php index 37e01a01f..b8b44abc8 100644 --- a/src/pocketmine/entity/Enderman.php +++ b/src/pocketmine/entity/Enderman.php @@ -26,7 +26,5 @@ use pocketmine\inventory\InventoryHolder; use pocketmine\nbt\tag\String; class Enderman extends Monster implements InventoryHolder{ - protected function initEntity(){ - $this->namedtag->id = new String("id", "Enderman"); - } + } \ No newline at end of file diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index d517909f5..5583e0259 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -49,6 +49,7 @@ use pocketmine\nbt\tag\Double; use pocketmine\nbt\tag\Enum; use pocketmine\nbt\tag\Float; use pocketmine\nbt\tag\Short; +use pocketmine\nbt\tag\String; use pocketmine\Network; use pocketmine\network\protocol\MoveEntityPacket; use pocketmine\network\protocol\MovePlayerPacket; @@ -69,6 +70,7 @@ abstract class Entity extends Location implements Metadatable{ public static $entityCount = 1; /** @var Entity[] */ private static $knownEntities = []; + private static $shortNames = []; /** * @var Player[] @@ -250,13 +252,27 @@ abstract class Entity extends Location implements Metadatable{ } self::$knownEntities[$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 saveNBT(){ + if(!($this instanceof Player)){ + $this->namedtag->id = new String("id", $this->getSaveId()); + } + $this->namedtag->Pos = new Enum("Pos", [ new Double(0, $this->x), new Double(1, $this->y), diff --git a/src/pocketmine/entity/FallingSand.php b/src/pocketmine/entity/FallingSand.php index 1ee261ed2..2e7d07d79 100644 --- a/src/pocketmine/entity/FallingSand.php +++ b/src/pocketmine/entity/FallingSand.php @@ -50,7 +50,6 @@ class FallingSand extends Entity{ public $canCollide = false; protected function initEntity(){ - $this->namedtag->id = new String("id", "FallingSand"); if(isset($this->namedtag->TileID)){ $this->blockId = $this->namedtag["TileID"]; }elseif(isset($this->namedtag->Tile)){ diff --git a/src/pocketmine/entity/Item.php b/src/pocketmine/entity/Item.php index d874f9744..c9572d692 100644 --- a/src/pocketmine/entity/Item.php +++ b/src/pocketmine/entity/Item.php @@ -53,7 +53,6 @@ class Item extends Entity{ public $canCollide = false; protected function initEntity(){ - $this->namedtag->id = new String("id", "Item"); $this->setMaxHealth(5); $this->setHealth($this->namedtag["Health"]); if(isset($this->namedtag->Age)){ diff --git a/src/pocketmine/entity/Ocelot.php b/src/pocketmine/entity/Ozelot.php similarity index 84% rename from src/pocketmine/entity/Ocelot.php rename to src/pocketmine/entity/Ozelot.php index a03ce7eaa..f51f923a1 100644 --- a/src/pocketmine/entity/Ocelot.php +++ b/src/pocketmine/entity/Ozelot.php @@ -24,8 +24,6 @@ namespace pocketmine\entity; use pocketmine\nbt\tag\String; -class Ocelot extends Animal implements Tameable{ - protected function initEntity(){ - $this->namedtag->id = new String("id", "Ozelot"); - } +class Ozelot extends Animal implements Tameable{ + } \ No newline at end of file diff --git a/src/pocketmine/entity/Painting.php b/src/pocketmine/entity/Painting.php index 7e591a87f..ca8f9e319 100644 --- a/src/pocketmine/entity/Painting.php +++ b/src/pocketmine/entity/Painting.php @@ -25,7 +25,5 @@ namespace pocketmine\entity; use pocketmine\nbt\tag\String; class Painting extends Hanging{ - protected function initEntity(){ - $this->namedtag->id = new String("id", "Painting"); - } + } \ No newline at end of file diff --git a/src/pocketmine/entity/Pig.php b/src/pocketmine/entity/Pig.php index d4e328557..17c2ae0ef 100644 --- a/src/pocketmine/entity/Pig.php +++ b/src/pocketmine/entity/Pig.php @@ -25,7 +25,5 @@ namespace pocketmine\entity; use pocketmine\nbt\tag\String; class Pig extends Animal implements Rideable{ - protected function initEntity(){ - $this->namedtag->id = new String("id", "Pig"); - } + } \ No newline at end of file diff --git a/src/pocketmine/entity/PigZombie.php b/src/pocketmine/entity/PigZombie.php index 26fe44935..a6517b0a7 100644 --- a/src/pocketmine/entity/PigZombie.php +++ b/src/pocketmine/entity/PigZombie.php @@ -25,7 +25,5 @@ namespace pocketmine\entity; use pocketmine\nbt\tag\String; class PigZombie extends Zombie{ - protected function initEntity(){ - $this->namedtag->id = new String("id", "PigZombie"); - } + } \ No newline at end of file diff --git a/src/pocketmine/entity/PrimedTNT.php b/src/pocketmine/entity/PrimedTNT.php index d1e871132..ed7f8028d 100644 --- a/src/pocketmine/entity/PrimedTNT.php +++ b/src/pocketmine/entity/PrimedTNT.php @@ -47,7 +47,6 @@ class PrimedTNT extends Entity implements Explosive{ public $canCollide = false; protected function initEntity(){ - $this->namedtag->id = new String("id", "PrimedTNT"); if(isset($this->namedtag->Fuse)){ $this->fuse = $this->namedtag["Fuse"]; }else{ diff --git a/src/pocketmine/entity/Sheep.php b/src/pocketmine/entity/Sheep.php index 7eaf87a0f..2cea6f714 100644 --- a/src/pocketmine/entity/Sheep.php +++ b/src/pocketmine/entity/Sheep.php @@ -25,7 +25,5 @@ namespace pocketmine\entity; use pocketmine\nbt\tag\String; class Sheep extends Animal implements Colorable{ - protected function initEntity(){ - $this->namedtag->id = new String("id", "Sheep"); - } + } \ No newline at end of file diff --git a/src/pocketmine/entity/Silverfish.php b/src/pocketmine/entity/Silverfish.php index 58a966b7f..23806f168 100644 --- a/src/pocketmine/entity/Silverfish.php +++ b/src/pocketmine/entity/Silverfish.php @@ -25,7 +25,5 @@ namespace pocketmine\entity; use pocketmine\nbt\tag\String; class Silverfish extends Monster{ - protected function initEntity(){ - $this->namedtag->id = new String("id", "Silverfish"); - } + } \ No newline at end of file diff --git a/src/pocketmine/entity/Skeleton.php b/src/pocketmine/entity/Skeleton.php index 41de98e5d..3318858fb 100644 --- a/src/pocketmine/entity/Skeleton.php +++ b/src/pocketmine/entity/Skeleton.php @@ -24,7 +24,5 @@ namespace pocketmine\entity; use pocketmine\nbt\tag\String; class Skeleton extends Monster implements ProjectileSource{ - protected function initEntity(){ - $this->namedtag->id = new String("id", "Skeleton"); - } + } diff --git a/src/pocketmine/entity/Slime.php b/src/pocketmine/entity/Slime.php index 475fca583..5560db116 100644 --- a/src/pocketmine/entity/Slime.php +++ b/src/pocketmine/entity/Slime.php @@ -25,7 +25,5 @@ namespace pocketmine\entity; use pocketmine\nbt\tag\String; class Slime extends Living{ - protected function initEntity(){ - $this->namedtag->id = new String("id", "Slime"); - } + } \ No newline at end of file diff --git a/src/pocketmine/entity/Snowball.php b/src/pocketmine/entity/Snowball.php index 8e71756e8..fc1d35c9e 100644 --- a/src/pocketmine/entity/Snowball.php +++ b/src/pocketmine/entity/Snowball.php @@ -63,11 +63,6 @@ class Snowball extends Projectile{ return $hasUpdate; } - protected function initEntity(){ - $this->namedtag->id = new String("id", "Snowball"); - parent::initEntity(); - } - public function spawnTo(Player $player){ $pk = new AddEntityPacket(); $pk->type = Snowball::NETWORK_ID; diff --git a/src/pocketmine/entity/Spider.php b/src/pocketmine/entity/Spider.php index 7dc21fd6c..9aa087481 100644 --- a/src/pocketmine/entity/Spider.php +++ b/src/pocketmine/entity/Spider.php @@ -25,7 +25,5 @@ namespace pocketmine\entity; use pocketmine\nbt\tag\String; class Spider extends Monster{ - protected function initEntity(){ - $this->namedtag->id = new String("id", "Spider"); - } + } \ No newline at end of file diff --git a/src/pocketmine/entity/Villager.php b/src/pocketmine/entity/Villager.php index b2f01cc50..5e93391d7 100644 --- a/src/pocketmine/entity/Villager.php +++ b/src/pocketmine/entity/Villager.php @@ -48,7 +48,6 @@ class Villager extends Creature implements NPC, Ageable{ protected function initEntity(){ parent::initEntity(); - $this->namedtag->id = new String("id", "Villager"); if(!isset($this->namedtag->Profession)){ $this->setProfession(self::PROFESSION_GENERIC); } diff --git a/src/pocketmine/entity/Wolf.php b/src/pocketmine/entity/Wolf.php index d1f1f3352..20a56100a 100644 --- a/src/pocketmine/entity/Wolf.php +++ b/src/pocketmine/entity/Wolf.php @@ -25,7 +25,5 @@ namespace pocketmine\entity; use pocketmine\nbt\tag\String; class Wolf extends Animal implements Tameable{ - protected function initEntity(){ - $this->namedtag->id = new String("id", "Wolf"); - } + } \ No newline at end of file diff --git a/src/pocketmine/entity/Zombie.php b/src/pocketmine/entity/Zombie.php index 31dc438eb..4544494cd 100644 --- a/src/pocketmine/entity/Zombie.php +++ b/src/pocketmine/entity/Zombie.php @@ -36,10 +36,6 @@ class Zombie extends Monster{ public $length = 0.6; public $height = 1.8; - protected function initEntity(){ - $this->namedtag->id = new String("id", "Zombie"); - } - public function getName(){ return "Zombie"; } diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index ed2cf884b..3540f0b5a 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -539,7 +539,7 @@ class Item{ } } - final public function getID(){ + final public function getId(){ return $this->id; } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index dcd1b1571..f1889e079 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -307,7 +307,7 @@ class Level implements ChunkManager, Metadatable{ * * @return int */ - final public function getID(){ + final public function getId(){ return $this->levelId; } diff --git a/src/pocketmine/level/generator/GenerationChunkManager.php b/src/pocketmine/level/generator/GenerationChunkManager.php index 2d50857e8..a84ab37c7 100644 --- a/src/pocketmine/level/generator/GenerationChunkManager.php +++ b/src/pocketmine/level/generator/GenerationChunkManager.php @@ -66,7 +66,7 @@ class GenerationChunkManager implements ChunkManager{ /** * @return int */ - public function getID(){ + public function getId(){ return $this->levelID; } diff --git a/src/pocketmine/tile/Chest.php b/src/pocketmine/tile/Chest.php index 49c9e3b58..d61245f2d 100644 --- a/src/pocketmine/tile/Chest.php +++ b/src/pocketmine/tile/Chest.php @@ -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); diff --git a/src/pocketmine/tile/Furnace.php b/src/pocketmine/tile/Furnace.php index e8c9686be..9c8fd3f86 100644 --- a/src/pocketmine/tile/Furnace.php +++ b/src/pocketmine/tile/Furnace.php @@ -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); diff --git a/src/pocketmine/tile/Sign.php b/src/pocketmine/tile/Sign.php index fae67c191..98870ddc7 100644 --- a/src/pocketmine/tile/Sign.php +++ b/src/pocketmine/tile/Sign.php @@ -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", ""); } diff --git a/src/pocketmine/tile/Tile.php b/src/pocketmine/tile/Tile.php index 7acf9307f..32252094e 100644 --- a/src/pocketmine/tile/Tile.php +++ b/src/pocketmine/tile/Tile.php @@ -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);