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; } $this->item = NBT::getItemHelper($this->namedtag->Item); $this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this)); }
/** * This method should not be used by plugins, use the Inventory * * @param int $index * * @return Item */ public function getItem($index) { $i = $this->getSlotIndex($index); if ($i < 0) { return Item::get(Item::AIR, 0, 0); } else { return NBT::getItemHelper($this->namedtag->Items[$i]); } }
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]); $this->inventory = new PlayerInventory($this); if ($this instanceof Player) { $this->addWindow($this->inventory, 0); } if (!$this instanceof Player) { if (isset($this->namedtag->NameTag)) { $this->setNameTag($this->namedtag["NameTag"]); } if (isset($this->namedtag->Skin) and $this->namedtag->Skin instanceof Compound) { $this->setSkin($this->namedtag->Skin["Data"], $this->namedtag->Skin["Name"] > 0); } $this->uuid = UUID::fromData($this->getId(), $this->getSkinData(), $this->getNameTag()); } if (isset($this->namedtag->Inventory) and $this->namedtag->Inventory instanceof Enum) { foreach ($this->namedtag->Inventory as $item) { if ($item["Slot"] >= 0 and $item["Slot"] < 9) { //Hotbar $this->inventory->setHotbarSlotIndex($item["Slot"], isset($item["TrueSlot"]) ? $item["TrueSlot"] : -1); } elseif ($item["Slot"] >= 100 and $item["Slot"] < 104) { //Armor $this->inventory->setItem($this->inventory->getSize() + $item["Slot"] - 100, NBT::getItemHelper($item)); } else { $this->inventory->setItem($item["Slot"] - 9, NBT::getItemHelper($item)); } } } parent::initEntity(); }