Getting Bukkit Material from Minecraft item ID?

Discussion in 'Spigot Plugin Development' started by daviga404, Mar 23, 2015.

Thread Status:
Not open for further replies.
  1. In a plugin I am creating, I am parsing NBT files, specifically <player>.dat files (I cannot use something other than these files such as an OfflinePlayer; they are stored in other locations than the server's world directory). In these files, I look for the player's enderchest items through the key "EnderItems".

    Each of the items stored has an ID value, which does not appear to correlate with the Bukkit Material values.
    For example:
    Code (Text):
    Minecraft ID              | Bukkit ID
    minecraft:cooked_porkchop | Material.GRILLED_PORK
    minecraft:planks          | Material.WOOD
    minecraft:baked_potato    | Material.BAKED_POTATO
    Is it possible to convert between the Minecraft ID values (e.g. minecraft:cooked_porkchop) and Bukkit Material values (e.g. Material.GRILLED_PORK)?
     
  2. Not sure if this helps, but you could try getting the item's id instead of bukkit's id.
    Code (Java):

    @Deprecated
    if(e.getItem().getTypeId().equals(320))
    //Your code
     
    This is checking if the item in question is a cooked porkchop, but I'm not sure how you could get a minecraft id to translate into this.
     
    • Useful Useful x 2
    • Like Like x 1
    • Creative Creative x 2
    • Winner Winner x 1
    • Informative Informative x 1
  3. Looked a bit into the default give command source and come up with this:
    Code (Text):
    MinecraftKey mk = new MinecraftKey(minecraftID);
    ItemStack item = CraftItemStack.asNewCraftStack(Item.REGISTRY.get(mk));
    Material mat = item.getType();
     
    • Winner Winner x 3
    • Useful Useful x 2
    • Agree Agree x 1
  4. This seems to work, thanks!
     
Thread Status:
Not open for further replies.