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


PHP Item::setCount方法代码示例

本文整理汇总了PHP中pocketmine\item\Item::setCount方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::setCount方法的具体用法?PHP Item::setCount怎么用?PHP Item::setCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pocketmine\item\Item的用法示例。


在下文中一共展示了Item::setCount方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: 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

示例3: addIngredient

 /**
  * @param Item $item
  *
  * @returns ShapelessRecipe
  *
  * @throws \InvalidArgumentException
  */
 public function addIngredient(Item $item)
 {
     if (count($this->ingredients) >= 9) {
         throw new \InvalidArgumentException("Shapeless recipes cannot have more than 9 ingredients");
     }
     $it = clone $item;
     $it->setCount(1);
     while ($item->getCount() > 0) {
         $this->ingredients[] = clone $it;
         $item->setCount($item->getCount() - 1);
     }
     return $this;
 }
开发者ID:TexusDark,项目名称:Ananas-MP,代码行数:20,代码来源:ShapelessRecipe.php

示例4: 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

示例5: onActivate

 public function onActivate(Item $item, Player $player = null)
 {
     $tile = $this->getLevel()->getTile($this);
     if (!$tile instanceof Cauldron) {
         return false;
     }
     switch ($item->getId()) {
         case Item::BUCKET:
             if ($item->getDamage() === 0) {
                 //empty bucket
                 if (!$this->isFull() or $tile->isCustomColor() or $tile->hasPotion()) {
                     break;
                 }
                 $bucket = clone $item;
                 $bucket->setDamage(8);
                 //water bucket
                 Server::getInstance()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $this, 0, $item, $bucket));
                 if (!$ev->isCancelled()) {
                     if ($player->isSurvival()) {
                         $player->getInventory()->setItemInHand($ev->getItem(), $player);
                     }
                     $this->meta = 0;
                     //empty
                     $this->getLevel()->setBlock($this, $this, true);
                     $tile->clearCustomColor();
                     $this->getLevel()->addSound(new SplashSound($this->add(0.5, 1, 0.5)));
                 }
             } elseif ($item->getDamage() === 8) {
                 //water bucket
                 if ($this->isFull() and !$tile->isCustomColor() and !$tile->hasPotion()) {
                     break;
                 }
                 $bucket = clone $item;
                 $bucket->setDamage(0);
                 //empty bucket
                 Server::getInstance()->getPluginManager()->callEvent($ev = new PlayerBucketEmptyEvent($player, $this, 0, $item, $bucket));
                 if (!$ev->isCancelled()) {
                     if ($player->isSurvival()) {
                         $player->getInventory()->setItemInHand($ev->getItem(), $player);
                     }
                     if ($tile->hasPotion()) {
                         //if has potion
                         $this->meta = 0;
                         //empty
                         $this->getLevel()->setBlock($this, $this, true);
                         $tile->setPotionId(0xffff);
                         //reset potion
                         $tile->clearCustomColor();
                         $this->getLevel()->addSound(new ExplodeSound($this->add(0.5, 0, 0.5)));
                     } else {
                         $this->meta = 6;
                         //fill
                         $this->getLevel()->setBlock($this, $this, true);
                         $tile->clearCustomColor();
                         $this->getLevel()->addSound(new SplashSound($this->add(0.5, 1, 0.5)));
                     }
                     $this->update();
                 }
             }
             break;
         case Item::DYE:
             if ($tile->hasPotion()) {
                 break;
             }
             $color = Color::getDyeColor($item->getDamage());
             if ($tile->isCustomColor()) {
                 $color = Color::averageColor($color, $tile->getCustomColor());
             }
             if ($player->isSurvival()) {
                 $item->setCount($item->getCount() - 1);
                 /*if($item->getCount() <= 0){
                 		$player->getInventory()->setItemInHand(Item::get(Item::AIR));
                 		}*/
             }
             $tile->setCustomColor($color);
             $this->getLevel()->addSound(new SplashSound($this->add(0.5, 1, 0.5)));
             $this->update();
             break;
         case Item::LEATHER_CAP:
         case Item::LEATHER_TUNIC:
         case Item::LEATHER_PANTS:
         case Item::LEATHER_BOOTS:
             if ($this->isEmpty()) {
                 break;
             }
             if ($tile->isCustomColor()) {
                 --$this->meta;
                 $this->getLevel()->setBlock($this, $this, true);
                 $newItem = clone $item;
                 Utils::setCustomColorToArmor($newItem, $tile->getCustomColor());
                 $player->getInventory()->setItemInHand($newItem);
                 $this->getLevel()->addSound(new SplashSound($this->add(0.5, 1, 0.5)));
                 if ($this->isEmpty()) {
                     $tile->clearCustomColor();
                 }
             } else {
                 --$this->meta;
                 $this->getLevel()->setBlock($this, $this, true);
                 $newItem = clone $item;
                 Utils::clearCustomColorToArmor($newItem);
//.........这里部分代码省略.........
开发者ID:ClearSkyTeam,项目名称:ClearSky,代码行数:101,代码来源:Cauldron.php

示例6: setIngredient

 /**
  * @param string $key
  * @param Item   $item
  *
  * @return $this
  * @throws \Exception
  */
 public function setIngredient($key, Item $item)
 {
     if (!array_key_exists($key, $this->shape)) {
         throw new \Exception("Symbol does not appear in the shape: " . $key);
     }
     $item->setCount(1);
     $this->fixRecipe($key, $item);
     return $this;
 }
开发者ID:iTXTech,项目名称:Genisys,代码行数:16,代码来源:ShapedRecipe.php

示例7: addItem

 public function addItem(Item $item, Player $player, Item $result)
 {
     if ($item->getCount() <= 1) {
         $player->getInventory()->setItemInHand($result);
     } else {
         $item->setCount($item->getCount() - 1);
         if ($player->getInventory()->canAddItem($result) === true) {
             $player->getInventory()->addItem($result);
         } else {
             $motion = $player->getDirectionVector()->multiply(0.4);
             $position = clone $player->getPosition();
             $player->getLevel()->dropItem($position->add(0, 0.5, 0), $result, $motion, 40);
         }
     }
 }
开发者ID:iTXTech,项目名称:Genisys,代码行数:15,代码来源:Cauldron.php

示例8: condenseRecipes

 /**
  * @param Item $item
  * @return Item|null
  */
 private function condenseRecipes(Item $item)
 {
     if (isset($this->condenseShapes[0][$item->getId()])) {
         // 2x2 Shapes
         $shape = 4;
     } elseif (isset($this->condenseShapes[1][$item->getId()])) {
         // 3x3 Shapes
         $shape = 9;
     } else {
         return null;
     }
     $index = (int) sqrt($shape) - 2;
     $newId = $this->condenseShapes[$index][$item->getId()];
     $damage = 0;
     if (is_array($newId)) {
         if (!isset($newId[1][$item->getDamage()])) {
             return null;
         }
         $damage = $newId[1][$item->getDamage()];
         $newId = $newId[0];
     }
     $count = floor($item->getCount() / $shape);
     if ($count < 1) {
         return null;
     }
     $condensed = new Item($newId, $damage, $count);
     if ($condensed->getId() === Item::AIR) {
         return null;
     }
     $item->setCount($item->getCount() - $count * $shape);
     return $condensed;
 }
开发者ID:TBNRFrags2468,项目名称:EssentialsPE,代码行数:36,代码来源:BaseAPI.php

示例9: 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


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