本文整理匯總了PHP中pocketmine\item\Item::getCount方法的典型用法代碼示例。如果您正苦於以下問題:PHP Item::getCount方法的具體用法?PHP Item::getCount怎麽用?PHP Item::getCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pocketmine\item\Item
的用法示例。
在下文中一共展示了Item::getCount方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: onActivate
public function onActivate(Item $item, Player $player = null)
{
$tile = $this->getLevel()->getTile($this);
if ($tile instanceof FlowerPotTile) {
if ($tile->getFlowerPotItem() === Item::AIR) {
switch ($item->getId()) {
case Item::TALL_GRASS:
if ($item->getDamage() === 1) {
break;
}
case Item::SAPLING:
case Item::DEAD_BUSH:
case Item::DANDELION:
case Item::RED_FLOWER:
case Item::BROWN_MUSHROOM:
case Item::RED_MUSHROOM:
case Item::CACTUS:
$tile->setFlowerPotData($item->getId(), $item->getDamage());
$this->setDamage($item->getId());
$this->getLevel()->setBlock($this, $this, true, false);
if ($player->isSurvival()) {
$item->setCount($item->getCount() - 1);
$player->getInventory()->setItemInHand($item->getCount() > 0 ? $item : Item::get(Item::AIR));
}
return true;
break;
}
}
}
return false;
}
示例2: getChange
/**
* Returns the change in inventory resulting from this transaction
* @return Item[
* "in" => items added to the inventory
* "out" => items removed from the inventory
* ]
*/
public function getChange()
{
$sourceItem = $this->getInventory()->getItem($this->slot);
if ($sourceItem->deepEquals($this->targetItem, true, true, true)) {
//This should never happen, somehow a change happened where nothing changed
return null;
} elseif ($sourceItem->deepEquals($this->targetItem)) {
//Same item, change of count
$item = clone $sourceItem;
$countDiff = $this->targetItem->getCount() - $sourceItem->getCount();
$item->setCount(abs($countDiff));
if ($countDiff < 0) {
//Count decreased
return ["in" => null, "out" => $item];
} elseif ($countDiff > 0) {
//Count increased
return ["in" => $item, "out" => null];
} else {
//Should be impossible (identical items and no count change)
//This should be caught by the first condition even if it was possible
return null;
}
} elseif ($sourceItem->getId() !== Item::AIR and $this->targetItem->getId() === Item::AIR) {
//Slot emptied (item removed)
return ["in" => null, "out" => clone $sourceItem];
} elseif ($sourceItem->getId() === Item::AIR and $this->targetItem->getId() !== Item::AIR) {
//Slot filled (item added)
return ["in" => $this->getTargetItem(), "out" => null];
} else {
//Some other slot change - an item swap (tool damage changes will be ignored as they are processed server-side before any change is sent by the client
return ["in" => $this->getTargetItem(), "out" => clone $sourceItem];
}
}
示例3: onActivate
public function onActivate(Item $item, Player $player = null)
{
$tile = $this->getLevel()->getTile($this);
if (!$tile instanceof ItemFrameTile) {
$nbt = new CompoundTag("", [new StringTag("id", Tile::ITEM_FRAME), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z), new ByteTag("ItemRotation", 0), new FloatTag("ItemDropChance", 1.0)]);
Tile::createTile(Tile::ITEM_FRAME, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
}
$tile = $this->getLevel()->getTile($this);
if (!$tile instanceof ItemFrameTile) {
return false;
}
if ($tile->getItem()->getId() === 0) {
$tile->setItem(Item::get($item->getId(), $item->getDamage(), 1));
if ($player instanceof Player) {
if ($player->isSurvival()) {
$count = $item->getCount();
if (--$count <= 0) {
$player->getInventory()->setItemInHand(Item::get(Item::AIR));
return true;
}
$item->setCount($count);
$player->getInventory()->setItemInHand($item);
}
}
} else {
$itemRot = $tile->getItemRotation();
if ($itemRot === 7) {
$itemRot = 0;
} else {
$itemRot++;
}
$tile->setItemRotation($itemRot);
}
return true;
}
示例4: putItemHelper
/**
* @param Item $item
* @param int $slot
* @return CompoundTag
*/
public static function putItemHelper(Item $item, $slot = null)
{
$tag = new CompoundTag(null, ["id" => new ShortTag("id", $item->getId()), "Count" => new ByteTag("Count", $item->getCount()), "Damage" => new ShortTag("Damage", $item->getDamage())]);
if ($slot !== null) {
$tag->Slot = new ByteTag("Slot", (int) $slot);
}
if ($item->hasCompoundTag()) {
$tag->tag = clone $item->getNamedTag();
$tag->tag->setName("tag");
}
return $tag;
}
示例5: saveNBT
public function saveNBT()
{
$this->namedtag->Item = new Compound("Item", ["id" => new Short("id", $this->item->getID()), "Damage" => new Short("Damage", $this->item->getDamage()), "Count" => new Byte("Count", $this->item->getCount())]);
$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);
}
}
示例6: removeIngredient
/**
* @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;
}
示例7: equals
public final function equals(Item $item, bool $checkDamage = true, bool $checkCompound = true, bool $checkCount = false) : bool
{
return $this->id === $item->getId() and ($checkCount === false or $this->getCount() === $item->getCount()) and ($checkDamage === false or $this->getDamage() === $item->getDamage()) and ($checkCompound === false or $this->getCompoundTag() === $item->getCompoundTag());
}
示例8: setItem
/**
* 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 = $item->nbtSerialize($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;
}
示例9: putSlot
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->putLShort(strlen($nbt));
$this->put($nbt);
}
示例10: onActivate
public function onActivate(Item $item, Player $player = null)
{
$tile = $this->level->getTile($this);
if ($tile instanceof ItemFrame) {
if ($tile->getItem()->getId() === Item::AIR) {
$tile->setItem(Item::get($item->getId(), $item->getDamage(), 1));
$item->setCount($item->getCount() - 1);
} else {
$rot = $tile->getItemRotation() + 1;
$tile->setItemRotation($rot > 8 ? 0 : $rot);
}
return true;
}
return false;
}
示例11: checkFuel
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);
}
}
示例12: setItem
/**
* 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 = new Compound(false, [new Byte("Count", $item->getCount()), new Byte("Slot", $index), new Short("id", $item->getID()), new Short("Damage", $item->getDamage())]);
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;
}
示例13: putSlot
protected function putSlot(Item $item)
{
if ($item->getID() === 0) {
$this->putShort(-1);
} else {
$this->putShort($item->getID());
$this->putByte($item->getCount());
$this->putShort($item->getDamage());
$nbt = $item->getCompoundTag();
$this->putByte(strlen($nbt));
$this->put($nbt);
}
}
示例14: getDrops
/**
* Returns an array of Item objects to be dropped
*
* @param Item $item
*
* @return array
*/
public function getDrops(Item $item)
{
if (!isset(self::$list[$this->getId()])) {
//Unknown blocks
return [];
} else {
return [[$this->getId(), $this->getDamage(), 1], [$item->getId(), $item->getDamage(), $item->getCount()]];
}
}
示例15: hasItemPlayer
/**
* @param Player $player
* @param Item $item
* @return boolean
*/
private function hasItemPlayer(Player $player, Item $item)
{
if ($this->SignShop->getProvider()->getPlayer(strtolower($player->getName()))["authorized"] == "root") {
return true;
}
$ris = 0;
if ($player->getGamemode() != 1) {
for ($i = 0; $i <= $player->getInventory()->getSize(); ++$i) {
$inv = $player->getInventory()->getItem($i);
if ($inv->getID() == $item->getID() && $inv->getDamage() == $item->getDamage()) {
$ris = $ris + $inv->getCount();
}
}
}
if ($ris >= $item->getCount()) {
return true;
}
return false;
}