/** * This method should not be used by plugins, use the Inventory * * @param int $index * @param Item $item * * @return bool */ public function setItem($index, Item $item) { $i = $this->getSlotIndex($index); $d = NBT::putItemHelper($item, $index); if ($item->getId() === Item::AIR or $item->getCount() <= 0) { if ($i >= 0) { unset($this->namedtag->Items[$i]); } } elseif ($i < 0) { for ($i = 0; $i <= $this->getSize(); ++$i) { if (!isset($this->namedtag->Items[$i])) { break; } } $this->namedtag->Items[$i] = $d; } else { $this->namedtag->Items[$i] = $d; } return true; }
public function saveNBT() { parent::saveNBT(); $this->namedtag->Inventory = new Enum("Inventory", []); $this->namedtag->Inventory->setTagType(NBT::TAG_Compound); if ($this->inventory !== null) { for ($slot = 0; $slot < 9; ++$slot) { $hotbarSlot = $this->inventory->getHotbarSlotIndex($slot); if ($hotbarSlot !== -1) { $item = $this->inventory->getItem($hotbarSlot); if ($item->getId() !== 0 and $item->getCount() > 0) { $tag = NBT::putItemHelper($item, $slot); $tag->TrueSlot = new Byte("TrueSlot", $hotbarSlot); $this->namedtag->Inventory[$slot] = $tag; continue; } } $this->namedtag->Inventory[$slot] = new Compound("", [new Byte("Count", 0), new Short("Damage", 0), new Byte("Slot", $slot), new Byte("TrueSlot", -1), new Short("id", 0)]); } //Normal inventory $slotCount = Player::SURVIVAL_SLOTS + 9; //$slotCount = (($this instanceof Player and ($this->gamemode & 0x01) === 1) ? Player::CREATIVE_SLOTS : Player::SURVIVAL_SLOTS) + 9; for ($slot = 9; $slot < $slotCount; ++$slot) { $item = $this->inventory->getItem($slot - 9); $this->namedtag->Inventory[$slot] = NBT::putItemHelper($item, $slot); } //Armor for ($slot = 100; $slot < 104; ++$slot) { $item = $this->inventory->getItem($this->inventory->getSize() + $slot - 100); if ($item instanceof ItemItem and $item->getId() !== ItemItem::AIR) { $this->namedtag->Inventory[$slot] = NBT::putItemHelper($item, $slot); } } } if (strlen($this->getSkinData()) > 0) { $this->namedtag->Skin = new Compound("Skin", ["Data" => new String("Data", $this->getSkinData()), "Name" => new String("Name", $this->getSkinName())]); } }
/** * @param Vector3 $source * @param Item $item * @param Vector3 $motion * @param int $delay */ public function dropItem(Vector3 $source, Item $item, Vector3 $motion = null, $delay = 10) { $motion = $motion === null ? new Vector3(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1) : $motion; $itemTag = NBT::putItemHelper($item); $itemTag->setName("Item"); if ($item->getId() > 0 and $item->getCount() > 0) { $itemEntity = Entity::createEntity("Item", $this->getChunk($source->getX() >> 4, $source->getZ() >> 4, true), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $source->getX()), new Double("", $source->getY()), new Double("", $source->getZ())]), "Motion" => new Enum("Motion", [new Double("", $motion->x), new Double("", $motion->y + 0.1), new Double("", $motion->z)]), "Rotation" => new Enum("Rotation", [new Float("", lcg_value() * 360), new Float("", 0)]), "Health" => new Short("Health", 5), "Item" => $itemTag, "PickupDelay" => new Short("PickupDelay", $delay)])); $itemEntity->spawnToAll(); } }
public function saveNBT() { parent::saveNBT(); $this->namedtag->Item = NBT::putItemHelper($this->item); $this->namedtag->Health = new Short("Health", $this->getHealth()); $this->namedtag->Age = new Short("Age", $this->age); $this->namedtag->PickupDelay = new Short("PickupDelay", $this->pickupDelay); if ($this->owner !== null) { $this->namedtag->Owner = new String("Owner", $this->owner); } if ($this->thrower !== null) { $this->namedtag->Thrower = new String("Thrower", $this->thrower); } }