Minecraft ID-String to Material

Discussion in 'Spigot Plugin Development' started by Sumafu, Apr 10, 2015.

  1. 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.
  2. 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.
  3. 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));
    #4 Cybermaxke, Apr 10, 2015
    Last edited: Apr 10, 2015
    • Like Like x 1
  4. item0 can be null, you need to do the same for blocks, when item0 is equal null
  5. @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. ;)
  6. And what is, if item==null? Then it would not work, i think.
  7. @Sumafu Then is the item type not available.
    • Informative Informative x 1
  8. 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);
        myMaterial =  CraftItemStack.asNewCraftStack(item).getType();
        myMaterial = Material.STONE;