mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-20 15:41:33 +00:00
Automatically set Entity / Tile entity save identifiers
This commit is contained in:
@@ -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;
|
||||
|
@@ -26,7 +26,4 @@ use pocketmine\nbt\tag\String;
|
||||
|
||||
class Chicken extends Animal{
|
||||
|
||||
protected function initEntity(){
|
||||
$this->namedtag->id = new String("id", "Chicken");
|
||||
}
|
||||
}
|
@@ -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");
|
||||
}
|
||||
|
||||
}
|
@@ -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");
|
||||
}
|
||||
|
||||
}
|
@@ -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");
|
||||
}
|
||||
|
||||
}
|
@@ -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");
|
||||
}
|
||||
|
||||
}
|
@@ -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),
|
||||
|
@@ -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)){
|
||||
|
@@ -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)){
|
||||
|
@@ -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{
|
||||
|
||||
}
|
@@ -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");
|
||||
}
|
||||
|
||||
}
|
@@ -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");
|
||||
}
|
||||
|
||||
}
|
@@ -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");
|
||||
}
|
||||
|
||||
}
|
@@ -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{
|
||||
|
@@ -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");
|
||||
}
|
||||
|
||||
}
|
@@ -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");
|
||||
}
|
||||
|
||||
}
|
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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");
|
||||
}
|
||||
|
||||
}
|
@@ -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;
|
||||
|
@@ -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");
|
||||
}
|
||||
|
||||
}
|
@@ -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);
|
||||
}
|
||||
|
@@ -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");
|
||||
}
|
||||
|
||||
}
|
@@ -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";
|
||||
}
|
||||
|
Reference in New Issue
Block a user