pocketmine\entity\Entity::initEntity PHP Method

initEntity() protected method

protected initEntity ( )
    protected function initEntity()
    {
        if (!$this->namedtag instanceof CompoundTag) {
            throw new \InvalidArgumentException("Expecting CompoundTag, received " . get_class($this->namedtag));
        }
        if (isset($this->namedtag->CustomName)) {
            $this->setNameTag($this->namedtag["CustomName"]);
            if (isset($this->namedtag->CustomNameVisible)) {
                $this->setNameTagVisible($this->namedtag["CustomNameVisible"] > 0);
            }
        }
        $this->scheduleUpdate();
        $this->addAttributes();
        if (isset($this->namedtag->ActiveEffects)) {
            foreach ($this->namedtag->ActiveEffects->getValue() as $e) {
                $effect = Effect::getEffect($e["Id"]);
                if ($effect === null) {
                    continue;
                }
                $effect->setAmplifier($e["Amplifier"])->setDuration($e["Duration"])->setVisible($e["ShowParticles"] > 0);
                $this->addEffect($effect);
            }
        }
    }

Usage Example

Example #1
0
 protected function initEntity()
 {
     parent::initEntity();
     $this->setMaxHealth(5);
     $this->setHealth($this->namedtag["Health"]);
     if (isset($this->namedtag->Age)) {
         $this->age = $this->namedtag["Age"];
     }
     if (isset($this->namedtag->PickupDelay)) {
         $this->pickupDelay = $this->namedtag["PickupDelay"];
     }
     if (isset($this->namedtag->Owner)) {
         $this->owner = $this->namedtag["Owner"];
     }
     if (isset($this->namedtag->Thrower)) {
         $this->thrower = $this->namedtag["Thrower"];
     }
     if (!isset($this->namedtag->Item)) {
         $this->close();
         return;
     }
     assert($this->namedtag->Item instanceof CompoundTag);
     $this->item = NBT::getItemHelper($this->namedtag->Item);
     $this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this));
 }
All Usage Examples Of pocketmine\entity\Entity::initEntity