Tutorial Custom crafting!

Discussion in 'Resources' started by xXDevastationXx, Mar 1, 2015.

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

    xXDevastationXx

    Hello :) This is my very first resource post and I thought I would start with something simple that I like to do!
    Custom crafting recipe's!
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Step 1: In your onEnable() method, you must first "create" the recipe
    Code:
    Code:
      public void onEnable() {
    hrecipe();
    }
    
    Note: It can be called anything, but remember what you call it, Here I'm calling it hrecipe
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Step 2: Use the recipe you made just a second ago here, we are making the output here.
    Code:
    Private void hrecipe()  //Use the recipe name you made
    {
    ItemStack helmet = new ItemStack(Material.CHAIN_HELMET, 1); //this is what the recipe will create, and how much.
    }
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Step 3: well you have created the ItemStack of the new item you will create, but now we make the ItemMeta
    Code:
     ItemMeta meta = helmet.getItemMeta();
    ok! now put this code UNDER the code that made the itemstack (remember this is all in 1 method)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Step 4: Now for some Customizing!
    here we will set the display name (the actual name of the item)
    Code:
    meta.setDisplayName(ChatColor.GOLD + "TutorialHelmet");
    You can name it anything you want, but here im naming it TutorialHelmet

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Step 5: Lores! the lore of an item is the text UNDER the name
    Code:
        List<String> lore = new ArrayList();  lore.add("§4The best helmet ever");

    you can put anything in the quotes, but I felt like putting "the best helmet ever"

    By the way, "§" is like the "&" symbol, it makes color, but you can't use the & symbol for color in Java
    Step 6: this step is also here because you need to set the lore, just put this under the lore.add("Lore");
    Code:
    meta.setLore(lore);

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Step 7: here we are going to set the meta, AND create the ACTUAL recipe! almost done!
    Code:
    helmet.setItemMeta(meta);


    Step 8: finishing the recipe, We create the recipe to make the item
    Code:
        ShapedRecipe hrecipe = new ShapedRecipe(helmet);[/COLOR][/COLOR][/COLOR][/COLOR][/COLOR]
    [COLOR=#b3b300][COLOR=#8000ff][COLOR=#000000][COLOR=#8000ff][COLOR=#000000]hrecipe.shape(new String[] {
          "@@@",
          "@ @"
    });

    Since this is a shaped recipe, we put ShapedRecipe hrecipe = new ShapedRecipe(helmet);
    hrecipe is the recipe we named in the start, and (helmet) is the name of the itemstack

    Step 9: what do the @ symbols mean?
    the @ symbols are used because we can drag + drop minecraft items onto the code, so now that we have the symbols, we need to tell what it means.
    Code:
       hrecipe.setIngredient('@', Material.IRON_BLOCK);

    this means that @ = Material.IRON_BLOCK, and you can change iron block to any minecraft material
    EXTRA: You can have different items in 1 recipe, just use different symbols, like #, *, or !, and specify what they mean like we did with "@"
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Step 10: Add the recipe to minecraft

    Code:
    Bukkit.getServer().addRecipe(hrecipe);

    done! the entire code should look something like this(unless you customized it)
    Code:
        public void onEnable() {[/COLOR][/COLOR][/COLOR][/COLOR][/COLOR]
    [COLOR=#b3b300][COLOR=#8000ff][COLOR=#000000][COLOR=#8000ff][COLOR=#000000]hrecipe();
    }
    
    private void hrecipe()
      {
        ItemStack helmet = new ItemStack(Material.CHAINMAIL_HELMET, 1);
        ItemMeta meta = helmet.getItemMeta();
        meta.setDisplayName(ChatColor.GOLD + "Tutorial Helmet");
        List<String> lore = new ArrayList();
        lore.add("§4The best helmet ever");
        meta.setLore(lore);
        helmet.setItemMeta(meta);
    
        ShapedRecipe hrecipe = new ShapedRecipe(helmet);
        hrecipe.shape(new String[] {
          "@@@",
          "@ @" });
    
        hrecipe.setIngredient('@', Material.IRON_BLOCK);
        Bukkit.getServer().addRecipe(hrecipe);
      }

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Thanks for reading! I hoped this helped someone <3

    *this is my first Resource thread, tell me if I messed up or if there is a better way*



    huh.. why is there random [Color = ] things...

    <Edit by mrCookieSlime: Merged posts. Please don't double post. There is an Edit Button right next to the Date.>
     
    Last edited by a moderator: Mar 1, 2015
    ChipDev likes this.
  2. Offline

    MrDplugins

    @xXDevastationXx Question. Is it possible to use other itemstack items to craft another itemstack?

    @bwfcwalshy Here say I have a custom itemstack

    ItemStack wand = new ItemStack(Material.STICK);
    ItemMeta wandmeta = wand.getItemMeta();
    wandmeta.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD + "Magic Wand");
    wandmeta.setLore(Arrays.asList(ChatColor.GOLD + "Spawns gold"));
    wand.setItemMeta(wandmeta);
    That is what I wand to craft. simple

    But the ingredients are also itemstacks.

    ItemStack wand = new ItemStack(Material.GOLD_INGOT);
    ItemMeta wandmeta = wand.getItemMeta();
    wandmeta.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD + "Gold Core");
    wandmeta.setLore(Arrays.asList(ChatColor.GOLD + "Used in magic wand"));
    wand.setItemMeta(wandmeta);

    ItemStack wand = new ItemStack(Material.BLAZE_ROD);
    ItemMeta wandmeta = wand.getItemMeta();
    wandmeta.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD + "Gold Wand");
    wandmeta.setLore(Arrays.asList(ChatColor.GOLD + "used in magic wand"));
    wand.setItemMeta(wandmeta);

    Okay I wand to use those itemstacks as ingredients.
    I'm asking is that possible?

    <Edit by mrCookieSlime: Merged posts.>
     
    Last edited by a moderator: Mar 4, 2015
  3. Offline

    mrCookieSlime

    Not via this method only.
    Youd have to listen for the PrepareItemCraftEvent
    and check for the Items in that inventory, compare it with your premade ItemStacks and set the result to null it it does not match.
     
  4. Offline

    MrDplugins

  5. Offline

    Yallahall

    Can I use this same method to create a new block? One that doesn't exist yet, I assume I'd have to create this block and then just use this to change or make a recipe for it, any tutorials or example code on doing so?
     
  6. Nope.
     
Thread Status:
Not open for further replies.

Share This Page