pocketmine\item\Item::get PHP Method

get() public static method

public static get ( $id, $meta, integer $count = 1, $tags = "" ) : Item
$count integer
return Item
    public static function get($id, $meta = 0, int $count = 1, $tags = "") : Item
    {
        try {
            if (is_string($id)) {
                $item = Item::fromString($id);
                $item->setCount($count);
                $item->setDamage($meta);
                return $item;
            }
            $class = self::$list[$id];
            if ($class === null) {
                return (new Item($id, $meta, $count))->setCompoundTag($tags);
            } elseif ($id < 256) {
                return (new ItemBlock(new $class($meta), $meta, $count))->setCompoundTag($tags);
            } else {
                return (new $class($meta, $count))->setCompoundTag($tags);
            }
        } catch (\RuntimeException $e) {
            return (new Item($id, $meta, $count))->setCompoundTag($tags);
        }
    }

Usage Example

Example #1
4
 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;
 }
All Usage Examples Of pocketmine\item\Item::get