本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
//.........这里部分代码省略.........
示例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;
}
示例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);
}
}
}
示例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;
}
示例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;
}