Hi guys, currently I make a plugin for Bukkit/Spigot, and it would be nice if I can convert a Minecraft-Id-String into a material, like "minecraft:clock" -> Material.WATCH. I found only one solution in the internet, but it doesn't work.
Did you see this: http://www.spigotmc.org/threads/getting-bukkit-material-from-minecraft-item-id.56684/ ?
Yes, I saw it, but it doesn't work. When I create an ItemStack and try to get the ItemMeta, the ItemMeta-Object is null.
Maybe then something like this? Code (Text): String minecraftId = ...; org.bukkit.inventory.ItemStack result = null; if (minecraftId != null) { MinecraftKey key= new MinecraftKey(minecraftId); Item item = Item.REGISTRY.get(key); if (item != null) { result = CraftItemStack.asCraftMirror(new ItemStack(item)); } }
@bram0101 Better? And you do not have to look for the block types, for every block that can be used as item is a ItemBlock instance in the register.
With some little changes it works now (I only need the material): Code (Text): Material myMaterial = null; MinecraftKey key = new MinecraftKey(itemId); Item item = (Item) Item.REGISTRY.get(key); if(item!=null){ myMaterial = CraftItemStack.asNewCraftStack(item).getType(); }else{ myMaterial = Material.STONE; }