pocketmine\entity\Entity::__construct PHP Method

__construct() public method

public __construct ( pocketmine\level\format\FullChunk $chunk, CompoundTag $nbt )
$chunk pocketmine\level\format\FullChunk
$nbt pocketmine\nbt\tag\CompoundTag
    public function __construct(FullChunk $chunk, CompoundTag $nbt)
    {
        if ($chunk === null or $chunk->getProvider() === null) {
            throw new ChunkException("Invalid garbage Chunk given to Entity");
        }
        $this->timings = Timings::getEntityTimings($this);
        $this->isPlayer = $this instanceof Player;
        $this->temporalVector = new Vector3();
        if ($this->eyeHeight === null) {
            $this->eyeHeight = $this->height / 2 + 0.1;
        }
        $this->id = Entity::$entityCount++;
        $this->justCreated = true;
        $this->namedtag = $nbt;
        $this->chunk = $chunk;
        $this->setLevel($chunk->getProvider()->getLevel());
        $this->server = $chunk->getProvider()->getLevel()->getServer();
        $this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
        $this->setPositionAndRotation($this->temporalVector->setComponents($this->namedtag["Pos"][0], $this->namedtag["Pos"][1], $this->namedtag["Pos"][2]), $this->namedtag->Rotation[0], $this->namedtag->Rotation[1]);
        $this->setMotion($this->temporalVector->setComponents($this->namedtag["Motion"][0], $this->namedtag["Motion"][1], $this->namedtag["Motion"][2]));
        if (is_nan($this->x) or is_infinite($this->x) or is_nan($this->y) or is_infinite($this->y) or is_nan($this->z) or is_infinite($this->z)) {
            throw new \InvalidStateException("Invalid entity coordinates");
        }
        if (!isset($this->namedtag->FallDistance)) {
            $this->namedtag->FallDistance = new FloatTag("FallDistance", 0);
        }
        $this->fallDistance = $this->namedtag["FallDistance"];
        if (!isset($this->namedtag->Fire)) {
            $this->namedtag->Fire = new ShortTag("Fire", 0);
        }
        $this->fireTicks = $this->namedtag["Fire"];
        if (!isset($this->namedtag->Air)) {
            $this->namedtag->Air = new ShortTag("Air", 300);
        }
        $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $this->namedtag["Air"]);
        if (!isset($this->namedtag->OnGround)) {
            $this->namedtag->OnGround = new ByteTag("OnGround", 0);
        }
        $this->onGround = $this->namedtag["OnGround"] > 0 ? true : false;
        if (!isset($this->namedtag->Invulnerable)) {
            $this->namedtag->Invulnerable = new ByteTag("Invulnerable", 0);
        }
        $this->invulnerable = $this->namedtag["Invulnerable"] > 0 ? true : false;
        $this->attributeMap = new AttributeMap();
        $this->chunk->addEntity($this);
        $this->level->addEntity($this);
        $this->initEntity();
        $this->lastUpdate = $this->server->getTick();
        $this->server->getPluginManager()->callEvent(new EntitySpawnEvent($this));
        $this->scheduleUpdate();
    }

Usage Example

Example #1
0
 public function __construct(FullChunk $chunk, Compound $nbt, Entity $shootingEntity = null)
 {
     $this->shootingEntity = $shootingEntity;
     if ($shootingEntity !== null) {
         $this->setDataProperty(self::DATA_SHOOTER_ID, self::DATA_TYPE_LONG, $shootingEntity->getId());
     }
     parent::__construct($chunk, $nbt);
 }
All Usage Examples Of pocketmine\entity\Entity::__construct