当前位置: 首页>>代码示例>>PHP>>正文


PHP Item::getCount方法代码示例

本文整理汇总了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;
 }
开发者ID:PepbookPvP,项目名称:Genisys,代码行数:31,代码来源:FlowerPot.php

示例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];
     }
 }
开发者ID:ClearSkyTeam,项目名称:ClearSky,代码行数:40,代码来源:BaseTransaction.php

示例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;
 }
开发者ID:ClearSkyTeam,项目名称:ClearSky,代码行数:35,代码来源:ItemFrame.php

示例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;
 }
开发者ID:ianju,项目名称:PocketMine-MP,代码行数:17,代码来源:NBT.php

示例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);
     }
 }
开发者ID:boybook,项目名称:PocketMine-MP,代码行数:13,代码来源:DroppedItem.php

示例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;
 }
开发者ID:TexusDark,项目名称:Ananas-MP,代码行数:18,代码来源:ShapelessRecipe.php

示例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());
 }
开发者ID:AnonymousProjects,项目名称:PocketMine-MP-Original,代码行数:4,代码来源:Item.php

示例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;
 }
开发者ID:robske110,项目名称:ClearSky,代码行数:28,代码来源:Chest.php

示例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);
 }
开发者ID:Cecil107,项目名称:PocketMine-0.13.0,代码行数:13,代码来源:BinaryStream.php

示例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;
 }
开发者ID:beito123,项目名称:PocketMine-MP-Plugins,代码行数:15,代码来源:BlockItemFrame.php

示例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);
     }
 }
开发者ID:NewDelion,项目名称:PocketMine-0.13.x,代码行数:20,代码来源:Furnace.php

示例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;
 }
开发者ID:boybook,项目名称:PocketMine-MP,代码行数:28,代码来源:Furnace.php

示例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);
     }
 }
开发者ID:iPocketTeam,项目名称:BigBrother,代码行数:13,代码来源:Packet.php

示例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()]];
     }
 }
开发者ID:0kino7ori,项目名称:PocketMine-MP,代码行数:16,代码来源:Block.php

示例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;
 }
开发者ID:PocketMine-PHP7,项目名称:SignShop-PHP7,代码行数:24,代码来源:PlayerTouchEvent.php


注:本文中的pocketmine\item\Item::getCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。