Create Custom Items

Discussion in 'Plugin Development' started by Lokikol, Jul 29, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Lokikol

    Hello,
    I've searched for a while now, but haven't found any good tutorial/example on how to create custom Items with Bukkit.

    There are a few things I need to know:

    First: Is it possible to create custom Items. And with custom Items I really mean stuff like my own armor, my own weapons, my own food?

    Is it possible to use my own material for it? If not why?

    Even if I can't use my own material (at this point I'd just use any given material from Minecraft) how would I create this custon Item? Would I need to create a given Item (maybe a Leather Armor) and manipulate it to what I need, or can I program the Item "from scratch"?

    Thank you
     
  2. Lokikol
    To answer your questions:
    Yes, it is possible to create 'custom items' (in a sense, read on...). You cannot use your own material as it is bound by the limits of Minecraft (e.g. if the material does not already exist, then you cannot use it; however resourcepacks aren't holding anyone back).

    The methods to create a custom item is either:
    [1] Crafting it in a crafting table (by adding a recipe)
    [2] Having it given to a player (e.g. give command etc.)

    Allowing the specific item to have a different effect (e.g. a sword which does more damage, armor which heals yourself every time you get hit, a feather that lets you fly) can be done by using a Listener.

    Recipe example:
    Code:java
    1. ItemStack item = new ItemStack(Material.WATCH, 1);
    2. item.addUnsafeEnchantment(Enchantment.SILK_TOUCH, 2);
    3. ItemMeta im = item.getItemMeta();
    4. im.setDisplayName("Time Transfer Device");
    5. String itemlore[] = {
    6. (new StringBuilder()).append(ConfigHandler.getConfig().getString("clockLore")).toString()
    7. };
    8. im.setLore(Arrays.asList(itemlore));
    9. item.setItemMeta(im);
    10. ShapedRecipe recipeitem = new ShapedRecipe(item);
    11. recipeitem.shape(new String[] {
    12. " G ", "GRG", " G "
    13. });
    14. recipeitem.setIngredient('G', Material.GOLD_INGOT);
    15. recipeitem.setIngredient('R', Material.REDSTONE_BLOCK);
    16. getServer().addRecipe(recipeitem);

    You create the itemStack normally and you are free to add whatever lore/displayname/enchantments as you wish. You then create a recipe and add it to the server (I don't quite know how to make a shapeless recipe).

    Alternatively, you could just give the player the itemStack with a command.
     
  3. Offline

    Lokikol

    Alright, thank you. I'll try that

    So for your example, if I want to add special behaviour, I'd add a listener which asks for the Event I want to listen, and then checks the Item the Player is holding (if it is type() == Material.WATCH) and also ask if the display Name equals to Time Transfer Device to be sure it's my custom Item.

    Right?
     
Thread Status:
Not open for further replies.

Share This Page