Sugarcane::class, self::WHEAT_SEEDS => WheatSeeds::class, self::PUMPKIN_SEEDS => PumpkinSeeds::class, self::MELON_SEEDS => MelonSeeds::class, self::MUSHROOM_STEW => MushroomStew::class, self::BEETROOT_SOUP => BeetrootSoup::class, self::CARROT => Carrot::class, self::POTATO => Potato::class, self::BEETROOT_SEEDS => BeetrootSeeds::class, self::SIGN => Sign::class, self::WOODEN_DOOR => WoodenDoor::class, self::BUCKET => Bucket::class, self::IRON_DOOR => IronDoor::class, self::CAKE => Cake::class, self::BED => Bed::class, self::PAINTING => Painting::class, self::COAL => Coal::class, self::APPLE => Apple::class, self::SPAWN_EGG => SpawnEgg::class, self::DIAMOND => Diamond::class, self::STICK => Stick::class, self::BOWL => Bowl::class, self::FEATHER => Feather::class, self::BRICK => Brick::class, self::IRON_SWORD => IronSword::class, self::IRON_INGOT => IronIngot::class, self::GOLD_INGOT => GoldIngot::class, self::IRON_SHOVEL => IronShovel::class, self::IRON_PICKAXE => IronPickaxe::class, self::IRON_AXE => IronAxe::class, self::IRON_HOE => IronHoe::class, self::DIAMOND_SWORD => DiamondSword::class, self::DIAMOND_SHOVEL => DiamondShovel::class, self::DIAMOND_PICKAXE => DiamondPickaxe::class, self::DIAMOND_AXE => DiamondAxe::class, self::DIAMOND_HOE => DiamondHoe::class, self::GOLD_SWORD => GoldSword::class, self::GOLD_SHOVEL => GoldShovel::class, self::GOLD_PICKAXE => GoldPickaxe::class, self::GOLD_AXE => GoldAxe::class, self::GOLD_HOE => GoldHoe::class, self::STONE_SWORD => StoneSword::class, self::STONE_SHOVEL => StoneShovel::class, self::STONE_PICKAXE => StonePickaxe::class, self::STONE_AXE => StoneAxe::class, self::STONE_HOE => StoneHoe::class, self::WOODEN_SWORD => WoodenSword::class, self::WOODEN_SHOVEL => WoodenShovel::class, self::WOODEN_PICKAXE => WoodenPickaxe::class, self::WOODEN_AXE => WoodenAxe::class, self::WOODEN_HOE => WoodenHoe::class, self::FLINT_STEEL => FlintSteel::class, self::SHEARS => Shears::class, self::BOW => Bow::class, ]; foreach(Block::$list as $id => $class){ self::$list[$id] = $class; } } } public static function get($id, $meta = 0, $count = 1){ if(isset(self::$list[$id])){ $class = self::$list[$id]; if($id < 256){ $item = new ItemBlock(new $class($meta), $meta, $count); }else{ $item = new $class($meta, $count); } }else{ $item = new Item($id, $meta, $count); } return $item; } public static function fromString($str, $multiple = false){ if($multiple === true){ $blocks = []; 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(Item::class . "::" . strtoupper($b[0]))){ $item = self::get(constant(Item::class . "::" . 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 = $id & 0xffff; $this->meta = $meta !== null ? $meta & 0xffff : null; $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 getDamage(){ return $this->meta; } public function setDamage($meta){ $this->meta = $meta !== null ? $meta & 0xFFFF : null; } final public function getMaxStackSize(){ return $this->maxStackSize; } final public function getFuelTime(){ if(!isset(Fuel::$duration[$this->id])){ return null; } if($this->id !== self::BUCKET or $this->meta === 10){ return Fuel::$duration[$this->id]; } return null; } /** * @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 === null ? "?" : $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->getDamage() === $item->getDamage()); } }