new Sugarcane(), WHEAT_SEEDS => new WheatSeeds(), PUMPKIN_SEEDS => new PumpkinSeeds(), MELON_SEEDS => new MelonSeeds(), MUSHROOM_STEW => new MushroomStew(), BEETROOT_SOUP => new BeetrootSoup(), CARROT => new Carrot(), POTATO => new Potato(), BEETROOT_SEEDS => new BeetrootSeeds(), SIGN => new Sign(), WOODEN_DOOR => new WoodenDoor(), BUCKET => new Bucket(), IRON_DOOR => new IronDoor(), CAKE => new Cake(), BED => new Bed(), PAINTING => new Painting(), COAL => new Coal(), APPLE => new Apple(), SPAWN_EGG => new SpawnEgg(), DIAMOND => new Diamond(), STICK => new Stick(), BOWL => new Bowl(), FEATHER => new Feather(), BRICK => new Brick(), IRON_INGOT => new IronIngot(), GOLD_INGOT => new GoldIngot(), IRON_SHOVEL => new IronShovel(), IRON_PICKAXE => new IronPickaxe(), IRON_AXE => new IronAxe(), IRON_HOE => new IronHoe(), WOODEN_SWORD => new WoodenSword(), WOODEN_SHOVEL => new WoodenShovel(), WOODEN_PICKAXE => new WoodenPickaxe(), WOODEN_AXE => new WoodenAxe(), FLINT_STEEL => new FlintSteel(), ); 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 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::$class[$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(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 !== 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]); } public function useOn($object, $force = false){ if($this->isTool() or $force === true){ if(($object instanceof Entity) and !$this->isSword()){ $this->meta += 2; } else{ $this->meta++; } return true; } elseif($this->isHoe()){ if(($object instanceof Block) and ($object->getID() === GRASS or $object->getID() === DIRT)){ $this->meta++; } } return false; } final public function isTool(){ return ($this->id === FLINT_STEEL or $this->id === SHEARS or $this->isPickaxe() !== false or $this->isAxe() !== false or $this->isShovel() !== false or $this->isSword() !== false); } final public function getMaxDurability(){ if(!$this->isTool() and $this->isHoe() === false and $this->id !== BOW){ return false; } $levels = array( 2 => 33, 1 => 60, 3 => 132, 4 => 251, 5 => 1562, FLINT_STEEL => 65, SHEARS => 239, BOW => 385, ); if(($type = $this->isPickaxe()) === false){ if(($type = $this->isAxe()) === false){ if(($type = $this->isSword()) === false){ if(($type = $this->isShovel()) === false){ if(($type = $this->isHoe()) === false){ $type = $this->id; } } } } } return $levels[$type]; } final public function isPickaxe(){ //Returns false or level of the pickaxe switch($this->id){ case IRON_PICKAXE: return 4; case WOODEN_PICKAXE: return 1; case STONE_PICKAXE: return 3; case DIAMOND_PICKAXE: return 5; case GOLD_PICKAXE: return 2; default: return false; } } final public function isAxe(){ switch($this->id){ case IRON_AXE: return 4; case WOODEN_AXE: return 1; case STONE_AXE: return 3; case DIAMOND_AXE: return 5; case GOLD_AXE: return 2; default: return false; } } final public function isSword(){ switch($this->id){ case IRON_SWORD: return 4; case WOODEN_SWORD: return 1; case STONE_SWORD: return 3; case DIAMOND_SWORD: return 5; case GOLD_SWORD: return 2; default: return false; } } final public function isShovel(){ switch($this->id){ case IRON_SHOVEL: return 4; case WOODEN_SHOVEL: return 1; case STONE_SHOVEL: return 3; case DIAMOND_SHOVEL: return 5; case GOLD_SHOVEL: return 2; default: return false; } } public function isHoe(){ switch($this->id){ case IRON_HOE: case WOODEN_HOE: case STONE_HOE: case DIAMOND_HOE: case GOLD_HOE: return true; default: return false; } } public function isShears(){ return ($this->id === SHEARS); } 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()); } }