/** * @param Item $item * @param int $slot * @return Compound */ public static function putItemHelper(Item $item, $slot = null) { $tag = new Compound(null, ["id" => new Short("id", $item->getId()), "Count" => new Byte("Count", $item->getCount()), "Damage" => new Short("Damage", $item->getDamage())]); if ($slot !== null) { $tag->Slot = new Byte("Slot", (int) $slot); } if ($item->hasCompoundTag()) { $tag->tag = clone $item->getNamedTag(); $tag->tag->setName("tag"); } return $tag; }
/** * @param Item $item * * @return $this */ public function removeIngredient(Item $item) { foreach ($this->ingredients as $index => $ingredient) { if ($item->getCount() <= 0) { break; } if ($ingredient->equals($item, $item->getDamage() === null ? false : true, $item->getCompoundTag() === null ? false : true)) { unset($this->ingredients[$index]); $item->setCount($item->getCount() - 1); } } return $this; }
protected function checkFuel(Item $fuel) { $this->server->getPluginManager()->callEvent($ev = new FurnaceBurnEvent($this, $fuel, $fuel->getFuelTime())); if ($ev->isCancelled()) { return; } $this->namedtag->MaxTime = new Short("MaxTime", $ev->getBurnTime()); $this->namedtag->BurnTime = new Short("BurnTime", $ev->getBurnTime()); $this->namedtag->BurnTicks = new Short("BurnTicks", 0); if ($this->getBlock()->getId() === Item::FURNACE) { $this->getLevel()->setBlock($this, Block::get(Item::BURNING_FURNACE, $this->getBlock()->getDamage()), true); } if ($this->namedtag["BurnTime"] > 0 and $ev->isBurning()) { $fuel->setCount($fuel->getCount() - 1); if ($fuel->getCount() === 0) { $fuel = Item::get(Item::AIR, 0, 0); } $this->inventory->setFuel($fuel); } }
public function first(Item $item) { $count = max(1, $item->getCount()); $checkDamage = $item->getDamage() === null ? false : true; $checkTags = $item->getCompoundTag() === null ? false : true; foreach ($this->getContents() as $index => $i) { if ($item->equals($i, $checkDamage, $checkTags) and $i->getCount() >= $count) { return $index; } } return -1; }
public function sort(Item $i1, Item $i2) { if ($i1->getId() > $i2->getId()) { return 1; } elseif ($i1->getId() < $i2->getId()) { return -1; } elseif ($i1->getDamage() > $i2->getDamage()) { return 1; } elseif ($i1->getDamage() < $i2->getDamage()) { return -1; } elseif ($i1->getCount() > $i2->getCount()) { return 1; } elseif ($i1->getCount() < $i2->getCount()) { return -1; } else { return 0; } }
public function putSlot(Item $item) { if ($item->getId() === 0) { $this->putShort(0); return; } $this->putShort($item->getId()); $this->putByte($item->getCount()); $this->putShort($item->getDamage() === null ? -1 : $item->getDamage()); $nbt = $item->getCompoundTag(); $this->putShort(strlen($nbt)); $this->put($nbt); }
public function setItem($index, Item $item) { if ($index < 0 or $index >= $this->size) { return false; } elseif ($item->getId() === 0 or $item->getCount() <= 0) { return $this->clear($index); } if ($index >= $this->getSize()) { //Armor change Server::getInstance()->getPluginManager()->callEvent($ev = new EntityArmorChangeEvent($this->getHolder(), $this->getItem($index), $item, $index)); if ($ev->isCancelled() and $this->getHolder() instanceof Human) { $this->sendArmorSlot($index, $this->getViewers()); return false; } $item = $ev->getNewItem(); } else { Server::getInstance()->getPluginManager()->callEvent($ev = new EntityInventoryChangeEvent($this->getHolder(), $this->getItem($index), $item, $index)); if ($ev->isCancelled()) { $this->sendSlot($index, $this->getViewers()); return false; } $item = $ev->getNewItem(); } $old = $this->getItem($index); $this->slots[$index] = clone $item; $this->onSlotChange($index, $old); if ($this->getHolder() instanceof Player) { if ($this->getHolder()->isSurvival()) { $this->sendContents($this->getHolder()); } } return true; }