new Sugarcane(), self::WHEAT_SEEDS => new WheatSeeds(), self::PUMPKIN_SEEDS => new PumpkinSeeds(), self::MELON_SEEDS => new MelonSeeds(), self::MUSHROOM_STEW => new MushroomStew(), self::BEETROOT_SOUP => new BeetrootSoup(), self::CARROT => new Carrot(), self::POTATO => new Potato(), self::BEETROOT_SEEDS => new BeetrootSeeds(), self::SIGN => new Sign(), self::WOODEN_DOOR => new WoodenDoor(), self::BUCKET => new Bucket(), self::IRON_DOOR => new IronDoor(), self::CAKE => new Cake(), self::BED => new Bed(), self::PAINTING => new Painting(), self::COAL => new Coal(), self::APPLE => new Apple(), self::SPAWN_EGG => new SpawnEgg(), self::DIAMOND => new Diamond(), self::STICK => new Stick(), self::BOWL => new Bowl(), self::FEATHER => new Feather(), self::BRICK => new Brick(), self::IRON_INGOT => new IronIngot(), self::GOLD_INGOT => new GoldIngot(), self::IRON_SHOVEL => new IronShovel(), self::IRON_PICKAXE => new IronPickaxe(), self::IRON_AXE => new IronAxe(), self::IRON_HOE => new IronHoe(), self::DIAMOND_SWORD => new DiamondSword(), self::DIAMOND_SHOVEL => new DiamondShovel(), self::DIAMOND_PICKAXE => new DiamondPickaxe(), self::DIAMOND_AXE => new DiamondAxe(), self::DIAMOND_HOE => new DiamondHoe(), self::GOLD_SWORD => new GoldSword(), self::GOLD_SHOVEL => new GoldShovel(), self::GOLD_PICKAXE => new GoldPickaxe(), self::GOLD_AXE => new GoldAxe(), self::GOLD_HOE => new GoldHoe(), self::STONE_SWORD => new StoneSword(), self::STONE_SHOVEL => new StoneShovel(), self::STONE_PICKAXE => new StonePickaxe(), self::STONE_AXE => new StoneAxe(), self::STONE_HOE => new StoneHoe(), self::WOODEN_SWORD => new WoodenSword(), self::WOODEN_SHOVEL => new WoodenShovel(), self::WOODEN_PICKAXE => new WoodenPickaxe(), self::WOODEN_AXE => new WoodenAxe(), self::WOODEN_HOE => new WoodenHoe(), self::FLINT_STEEL => new FlintSteel(), self::SHEARS => new Shears(), self::BOW => new Bow(), ); foreach(Block::$list as $id => $class){ self::$list[$id] = new ItemBlock($class); } } } public static function get($id, $meta = 0, $count = 1){ if(isset(self::$list[$id])){ $item = clone self::$list[$id]; $item->setMetadata($meta); $item->setCount($count); }else{ $item = new Item($id, $meta, $count); } return $item; } public static function fromString($str, $multiple = false){ if($multiple === true){ $blocks = array(); foreach(explode(",", $str) as $b){ $blocks[] = self::fromString($b, false); } return $blocks; }else{ $b = explode(":", str_replace(" ", "_", trim($str))); if(!isset($b[1])){ $meta = 0; }else{ $meta = ((int) $b[1]) & 0xFFFF; } if(defined("pocketmine\\item\\Item::" . strtoupper($b[0]))){ $item = self::get(constant("pocketmine\\item\\Item::" . strtoupper($b[0])), $meta); if($item->getID() === self::AIR and strtoupper($b[0]) !== "AIR"){ $item = self::get(((int) $b[0]) & 0xFFFF, $meta); } }else{ $item = self::get(((int) $b[0]) & 0xFFFF, $meta); } return $item; } } public function __construct($id, $meta = 0, $count = 1, $name = "Unknown"){ $this->id = (int) $id; $this->meta = (int) $meta; $this->count = (int) $count; $this->name = $name; if(!isset($this->block) and $this->id <= 0xff and isset(Block::$list[$this->id])){ $this->block = Block::get($this->id, $this->meta); $this->name = $this->block->getName(); } if($this->isTool() !== false){ $this->maxStackSize = 1; } } public function getCount(){ return $this->count; } public function setCount($count){ $this->count = (int) $count; } final public function getName(){ return $this->name; } final public function isPlaceable(){ return (($this->block instanceof Block) and $this->block->isPlaceable === true); } public function getBlock(){ if($this->block instanceof Block){ return $this->block; }else{ return Block::get(self::AIR); } } final public function getID(){ return $this->id; } final public function getMetadata(){ return $this->meta; } public function setMetadata($meta){ $this->meta = $meta & 0xFFFF; } final public function getMaxStackSize(){ return $this->maxStackSize; } final public function getFuelTime(){ if(!isset(Fuel::$duration[$this->id])){ return false; } if($this->id !== self::BUCKET or $this->meta === 10){ return Fuel::$duration[$this->id]; } return false; } final public function getSmeltItem(){ if(!isset(Smelt::$product[$this->id])){ return false; } if(isset(Smelt::$product[$this->id][0]) and !is_array(Smelt::$product[$this->id][0])){ return self::get(Smelt::$product[$this->id][0], Smelt::$product[$this->id][1]); } if(!isset(Smelt::$product[$this->id][$this->meta])){ return false; } return self::get(Smelt::$product[$this->id][$this->meta][0], Smelt::$product[$this->id][$this->meta][1]); } /** * @param Entity|Block $object * * @return bool */ public function useOn($object){ return false; } /** * @return bool */ public function isTool(){ return false; } /** * @return int|bool */ public function getMaxDurability(){ return false; } public function isPickaxe(){ return false; } public function isAxe(){ return false; } public function isSword(){ return false; } public function isShovel(){ return false; } public function isHoe(){ return false; } public function isShears(){ return false; } final public function __toString(){ return "Item " . $this->name . " (" . $this->id . ":" . $this->meta . ")"; } public function getDestroySpeed(Block $block, Player $player){ return 1; } public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ return false; } public final function equals(Item $item, $checkDamage = false){ return $this->id === $item->getID() and ($checkDamage === false or $this->getMetadata() === $item->getMetadata()); } }