本文整理匯總了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;
}
示例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;
}
示例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));
}
示例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;
}
示例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;
}
示例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];
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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());
}
}
示例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;
}
示例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;
}
示例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;
}