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


PHP Item::getId方法代码示例

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


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

示例1: onActivate

 public function onActivate(Item $item, Player $player = null)
 {
     $tile = $this->getLevel()->getTile($this);
     if ($this->meta == 0) {
         switch ($item->getId()) {
             case Item::BUCKET:
                 if ($item->getDamage() === 8) {
                     $this->meta = 6;
                     $this->getLevel()->setBlock($this, $this, true, false);
                     if ($player->isSurvival()) {
                         $item->setDamage(0);
                         $player->getInventory()->setItemInHand($item(), $player);
                     }
                 }
                 return true;
                 break;
         }
     }
     return false;
 }
开发者ID:NUMAKAGE,项目名称:NIGHTMARE,代码行数:20,代码来源:Cauldron.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->count--;
                     }
                     return true;
                     break;
             }
         }
     }
     return false;
 }
开发者ID:abc12309874,项目名称:Genisys,代码行数:30,代码来源:FlowerPot.php

示例3: initEntity

 protected function initEntity()
 {
     parent::initEntity();
     $this->setMaxHealth(5);
     $this->setHealth($this->namedtag["Health"]);
     if (isset($this->namedtag->Age)) {
         $this->age = $this->namedtag["Age"];
     }
     if (isset($this->namedtag->PickupDelay)) {
         $this->pickupDelay = $this->namedtag["PickupDelay"];
     }
     if (isset($this->namedtag->Owner)) {
         $this->owner = $this->namedtag["Owner"];
     }
     if (isset($this->namedtag->Thrower)) {
         $this->thrower = $this->namedtag["Thrower"];
     }
     if (!isset($this->namedtag->Item)) {
         $this->close();
         return;
     }
     $this->item = NBT::getItemHelper($this->namedtag->Item);
     if ($this->item->getId() <= 0) {
         $this->close();
         return;
     }
     $this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this));
 }
开发者ID:iTXTech,项目名称:Genisys,代码行数:28,代码来源:Item.php

示例4: getPossibleEnchantments

 /**
  * @param Item $item
  * @param int  $modifiedLevel
  * @return Enchantment[]
  */
 public static function getPossibleEnchantments(Item $item, int $modifiedLevel)
 {
     $result = [];
     $enchantmentIds = [];
     if ($item->getId() == Item::BOOK) {
         $enchantmentIds = array_keys(self::$map);
     } elseif ($item->isArmor()) {
         $enchantmentIds[] = Enchantment::TYPE_ARMOR_PROTECTION;
         $enchantmentIds[] = Enchantment::TYPE_ARMOR_FIRE_PROTECTION;
         $enchantmentIds[] = Enchantment::TYPE_ARMOR_EXPLOSION_PROTECTION;
         $enchantmentIds[] = Enchantment::TYPE_ARMOR_PROJECTILE_PROTECTION;
         $enchantmentIds[] = Enchantment::TYPE_ARMOR_THORNS;
         if ($item->isBoots()) {
             $enchantmentIds[] = Enchantment::TYPE_ARMOR_FALL_PROTECTION;
         }
         if ($item->isHelmet()) {
             $enchantmentIds[] = Enchantment::TYPE_WATER_BREATHING;
             $enchantmentIds[] = Enchantment::TYPE_WATER_AFFINITY;
         }
     } elseif ($item->isSword()) {
         $enchantmentIds[] = Enchantment::TYPE_WEAPON_SHARPNESS;
         $enchantmentIds[] = Enchantment::TYPE_WEAPON_SMITE;
         $enchantmentIds[] = Enchantment::TYPE_WEAPON_ARTHROPODS;
         $enchantmentIds[] = Enchantment::TYPE_WEAPON_KNOCKBACK;
         $enchantmentIds[] = Enchantment::TYPE_WEAPON_FIRE_ASPECT;
         $enchantmentIds[] = Enchantment::TYPE_WEAPON_LOOTING;
     } elseif ($item->isTool()) {
         $enchantmentIds[] = Enchantment::TYPE_MINING_EFFICIENCY;
         $enchantmentIds[] = Enchantment::TYPE_MINING_SILK_TOUCH;
         $enchantmentIds[] = Enchantment::TYPE_MINING_FORTUNE;
     } elseif ($item->getId() == Item::BOW) {
         $enchantmentIds[] = Enchantment::TYPE_BOW_POWER;
         $enchantmentIds[] = Enchantment::TYPE_BOW_KNOCKBACK;
         $enchantmentIds[] = Enchantment::TYPE_BOW_FLAME;
         $enchantmentIds[] = Enchantment::TYPE_BOW_INFINITY;
     } elseif ($item->getId() == Item::FISHING_ROD) {
         $enchantmentIds[] = Enchantment::TYPE_FISHING_FORTUNE;
         $enchantmentIds[] = Enchantment::TYPE_FISHING_LURE;
     }
     if ($item->isTool() || $item->isArmor()) {
         $enchantmentIds[] = Enchantment::TYPE_MINING_DURABILITY;
     }
     foreach ($enchantmentIds as $enchantmentId) {
         $enchantment = Enchantment::getEnchantment($enchantmentId);
         $ranges = self::$map[$enchantmentId];
         $i = 0;
         /** @var Range $range */
         foreach ($ranges as $range) {
             $i++;
             if (self::isInRange($range[0], $range[1], $modifiedLevel)) {
                 $result[] = $enchantment->setLevel($i);
             }
         }
     }
     return $result;
 }
开发者ID:ClearSkyTeam,项目名称:ClearSky,代码行数:61,代码来源:EnchantmentLevelTable.php

示例5: str

 /**
  * Given an pocketmine\item\Item object, it returns a friendly name
  * for it.
  *
  * @param Item item
  * @return str
  */
 public static function str(Item $item)
 {
     if (self::$xnames == null) {
         self::initXnames();
     }
     if (isset(self::$xnames[$item->getId()])) {
         if (isset(self::$xnames[$item->getId()][$item->getDamage()])) {
             return self::$xnames[$item->getId()][$item->getDamage()];
         } elseif (isset(self::$xnames[$item->getId()]["*"])) {
             return self::$xnames[$item->getId()]["*"];
         } else {
             return self::$xnames[$item->getId()][0];
         }
     }
     $n = $item->getName();
     if ($n != "Unknown") {
         return $n;
     }
     if (count(self::$items) == 0) {
         $constants = array_keys((new \ReflectionClass("pocketmine\\item\\Item"))->getConstants());
         foreach ($constants as $constant) {
             $id = constant("pocketmine\\item\\Item::{$constant}");
             $constant = str_replace("_", " ", $constant);
             self::$items[$id] = $constant;
         }
     }
     if (isset(self::$items[$item->getId()])) {
         return self::$items[$item->getId()];
     }
     return $n;
 }
开发者ID:AvivShopen,项目名称:bad-plugins,代码行数:38,代码来源:ItemName.php

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

示例7: __construct

 /**
  * @param string $name
  * @param array|Item[] $items
  */
 public function __construct($name, array $items)
 {
     $this->name = $name;
     foreach ($items as $i) {
         if (!$i instanceof Item) {
             $i = explode(" ", $i);
             if (count($i) > 1) {
                 $amount = $i[1];
                 unset($i[1]);
             } else {
                 $amount = 1;
             }
             $i = explode(":", $i[0]);
             if (count($i) > 1) {
                 $id = $i[0];
                 $meta = $i[1];
             } else {
                 $id = $i[0];
                 $meta = 0;
             }
             $i = new Item($id, $meta, $amount);
         }
         $this->items[$i->getId()] = $i;
     }
 }
开发者ID:PrimusLV,项目名称:EssentialsPE,代码行数:29,代码来源:BaseKit.php

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

示例9: onActivate

 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getId() === Item::DYE and $item->getDamage() === Dye::BONEMEAL) {
         $grow = false;
         if ($this->getSide(0)->getId() !== self::SUGARCANE_BLOCK && $this->getSide(0, 2)->getId() !== self::SUGARCANE_BLOCK) {
             for ($y = 1; $y < 2; $y++) {
                 $b = $this->getSide(1, $y);
                 if ($b->getId() === self::AIR) {
                     Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, new Sugarcane()));
                     if (!$ev->isCancelled()) {
                         $this->getLevel()->setBlock($b, $ev->getNewState(), true);
                         $grow = true;
                     }
                     break;
                 } else {
                     break;
                 }
             }
             $this->meta = 0;
             $this->getLevel()->setBlock($this, $this, true);
         }
         if ($grow && $player->isSurvival()) {
             $item->count--;
         }
         return true;
     }
     return false;
 }
开发者ID:ClearSkyTeam,项目名称:ClearSky,代码行数:28,代码来源:Sugarcane.php

示例10: onActivate

 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getId() === Item::DYE and $item->getDamage() === 0xf) {
         //Bonemeal
         if ($this->getSide(0)->getId() !== self::SUGARCANE_BLOCK) {
             for ($y = 1; $y < 3; ++$y) {
                 $b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
                 if ($b->getId() === self::AIR) {
                     Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, new Sugarcane()));
                     if (!$ev->isCancelled()) {
                         $this->getLevel()->setBlock($b, $ev->getNewState(), true);
                     }
                     break;
                 }
             }
             $this->meta = 0;
             $this->getLevel()->setBlock($this, $this, true);
         }
         if (($player->gamemode & 0x1) === 0) {
             $item->count--;
         }
         return true;
     }
     return false;
 }
开发者ID:xHFx,项目名称:ImagicalMine,代码行数:25,代码来源:Sugarcane.php

示例11: onActivate

 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getId() === Item::DYE and $item->getDamage() === 0xf and $this->getDamage() === 1 || $this->getDamage() === 2) {
         $this->getLevel()->setBlock($this->getSide(1), new DoublePlant($this->getDamage() + 1 ^ 0x8));
         $this->getLevel()->setBlock($this, new DoublePlant($this->getDamage() + 1));
         return true;
     } else {
         return false;
     }
 }
开发者ID:orlando092,项目名称:ImagicalMine,代码行数:10,代码来源:TallGrass.php

示例12: setItem

 public function setItem(Item $item)
 {
     $this->namedtag["item"] = $item->getId();
     $this->namedtag["mData"] = $item->getDamage();
     $this->spawnToAll();
     if ($this->chunk) {
         $this->chunk->setChanged();
         $this->level->clearChunkCache($this->chunk->getX(), $this->chunk->getZ());
     }
 }
开发者ID:xxFlare,项目名称:PocketMine-MP,代码行数:10,代码来源:FlowerPot.php

示例13: countInvItem

 /**
  * Count amount of items
  * @param Player $target
  * @param Item $item
  * @return int
  */
 public static function countInvItem(Player $target, Item $item)
 {
     $k = 0;
     foreach ($target->getInventory()->getContents() as $slot => &$inv) {
         if ($inv->getId() == $item->getId()) {
             $k += $inv->getCount();
         }
     }
     return $k;
 }
开发者ID:DWWf,项目名称:pocketmine-plugins,代码行数:16,代码来源:InvUtils.php

示例14: onActivate

 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getId() == Item::SPAWN_EGG) {
         $tile = $this->getLevel()->getTile($this);
         if ($tile instanceof MobSpawner) {
             $tile->setEntityId($item->getDamage());
             return true;
         }
     }
     return false;
 }
开发者ID:ClearSkyTeam,项目名称:ClearSky,代码行数:11,代码来源:MonsterSpawner.php

示例15: onActivate

 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getId() === Item::FLINT_STEEL) {
         $item->useOn($this);
         $this->getLevel()->setBlock($this, new Air(), true);
         $mot = (new Random())->nextSignedFloat() * M_PI * 2;
         $tnt = Entity::createEntity("PrimedTNT", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + 0.5), new DoubleTag("", $this->y), new DoubleTag("", $this->z + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", -sin($mot) * 0.02), new DoubleTag("", 0.2), new DoubleTag("", -cos($mot) * 0.02)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)]), "Fuse" => new ByteTag("Fuse", 80)]));
         $tnt->spawnToAll();
         return true;
     }
     return false;
 }
开发者ID:xxFlare,项目名称:PocketMine-MP,代码行数:12,代码来源:TNT.php


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