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 = ItemItem::nbtDeserialize($this->namedtag->Item);
     $this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this));
 }
Example #2
0
 protected function initEntity()
 {
     $this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, false, self::DATA_TYPE_BYTE);
     $this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [0, 0, 0], false);
     $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());
     }
     if (isset($this->namedtag->Inventory) and $this->namedtag->Inventory instanceof ListTag) {
         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, ItemItem::nbtDeserialize($item));
             } else {
                 $this->inventory->setItem($item["Slot"] - 9, ItemItem::nbtDeserialize($item));
             }
         }
     }
     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", $this->getXpLevel());
     } else {
         $this->setXpLevel($this->namedtag["XpLevel"]);
     }
     if (!isset($this->namedtag->XpP) or !$this->namedtag->XpP instanceof FloatTag) {
         $this->namedtag->XpP = new FloatTag("XpP", $this->getXpProgress());
     }
     if (!isset($this->namedtag->XpTotal) or !$this->namedtag->XpTotal instanceof IntTag) {
         $this->namedtag->XpTotal = new IntTag("XpTotal", $this->totalXp);
     } else {
         $this->totalXp = $this->namedtag["XpTotal"];
     }
     if (!isset($this->namedtag->XpSeed) or !$this->namedtag->XpSeed instanceof IntTag) {
         $this->namedtag->XpSeed = new IntTag("XpSeed", $this->xpSeed ?? ($this->xpSeed = mt_rand(PHP_INT_MIN, PHP_INT_MAX)));
     } else {
         $this->xpSeed = $this->namedtag["XpSeed"];
     }
 }
Example #3
0
 /**
  * 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 Item::nbtDeserialize($this->namedtag->Items[$i]);
     }
 }