pocketmine\entity\Human::initEntity PHP Method

initEntity() protected method

protected initEntity ( )
    protected function initEntity()
    {
        $this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, false);
        $this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [0, 0, 0]);
        $inventoryContents = $this->namedtag->Inventory ?? null;
        $this->inventory = new PlayerInventory($this, $inventoryContents);
        //Virtual inventory for desktop GUI crafting and anti-cheat transaction processing
        $this->floatingInventory = new FloatingInventory($this);
        if ($this instanceof Player) {
            $this->addWindow($this->inventory, 0);
        } else {
            if (isset($this->namedtag->NameTag)) {
                $this->setNameTag($this->namedtag["NameTag"]);
            }
            if (isset($this->namedtag->Skin) and $this->namedtag->Skin instanceof CompoundTag) {
                $this->setSkin($this->namedtag->Skin["Data"], $this->namedtag->Skin["Name"]);
            }
            $this->uuid = UUID::fromData($this->getId(), $this->getSkinData(), $this->getNameTag());
        }
        parent::initEntity();
        if (!isset($this->namedtag->foodLevel) or !$this->namedtag->foodLevel instanceof IntTag) {
            $this->namedtag->foodLevel = new IntTag("foodLevel", $this->getFood());
        } else {
            $this->setFood($this->namedtag["foodLevel"]);
        }
        if (!isset($this->namedtag->foodExhaustionLevel) or !$this->namedtag->foodExhaustionLevel instanceof IntTag) {
            $this->namedtag->foodExhaustionLevel = new FloatTag("foodExhaustionLevel", $this->getExhaustion());
        } else {
            $this->setExhaustion($this->namedtag["foodExhaustionLevel"]);
        }
        if (!isset($this->namedtag->foodSaturationLevel) or !$this->namedtag->foodSaturationLevel instanceof IntTag) {
            $this->namedtag->foodSaturationLevel = new FloatTag("foodSaturationLevel", $this->getSaturation());
        } else {
            $this->setSaturation($this->namedtag["foodSaturationLevel"]);
        }
        if (!isset($this->namedtag->foodTickTimer) or !$this->namedtag->foodTickTimer instanceof IntTag) {
            $this->namedtag->foodTickTimer = new IntTag("foodTickTimer", $this->foodTickTimer);
        } else {
            $this->foodTickTimer = $this->namedtag["foodTickTimer"];
        }
        if (!isset($this->namedtag->XpLevel) or !$this->namedtag->XpLevel instanceof IntTag) {
            $this->namedtag->XpLevel = new IntTag("XpLevel", 0);
        }
        $this->setXpLevel($this->namedtag["XpLevel"]);
        if (!isset($this->namedtag->XpP) or !$this->namedtag->XpP instanceof FloatTag) {
            $this->namedtag->XpP = new FloatTag("XpP", 0);
        }
        $this->setXpProgress($this->namedtag["XpP"]);
        if (!isset($this->namedtag->XpTotal) or !$this->namedtag->XpTotal instanceof IntTag) {
            $this->namedtag->XpTotal = new IntTag("XpTotal", 0);
        }
        $this->totalXp = $this->namedtag["XpTotal"];
        if (!isset($this->namedtag->XpSeed) or !$this->namedtag->XpSeed instanceof IntTag) {
            $this->namedtag->XpSeed = new IntTag("XpSeed", mt_rand(PHP_INT_MIN, PHP_INT_MAX));
        }
        $this->xpSeed = $this->namedtag["XpSeed"];
    }

Usage Example

Example #1
0
 protected function initEntity()
 {
     parent::initEntity();
 }