Can I use custom recipes in a custom recipe?

Discussion in 'Plugin Development' started by MondernDayMC, Mar 23, 2017.

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

    MondernDayMC

    Is there anyway I can use custom recipes to create a custom crafting recipe? In a perfect world I'd like to work like this:

    Code:
    ItemStack item1 = new ItemStack(Material.DIAMOND_PICKAXE);
            ItemMeta one = item1.getItemMeta();
            one.setDisplayName("§6Super Pick");
            ShapedRecipe itemone = new ShapedRecipe(item1);
            itemone.shape("EEE", "EPE", "EEE");
            itemone.setIngredient('E', Material.EMERALD);
            itemone.setIngredient('P', Material.DIAMOND_PICKAXE);
            Bukkit.getServer().addRecipe(itemone);
        
            //Create upgraded super pick
            ItemStack item2 = new ItemStack(Material.DIAMOND_PICKAXE);
            ItemMeta two = item2.getItemMeta();
            two.setDisplayName("§6Upgraded Super Pick");
            two.addEnchant(Enchantment.DIG_SPEED, 10, true);
            ShapedRecipe itemtwo = new ShapedRecipe(item2);
            itemtwo.shape("OOO","OPO","OOO");
            itemtwo.setIngredient('O', Material.OBSIDIAN);
                                     //Use the super pick to upgrade the super pick
            itemtwo.setIngredient('P', itemone);
    (This is how I'd like it to work, but it does not)

    Is there anyway to get as close to that result as possible and as easy as possible.

    Any help is greatly appreciated. Thanks.
     
  2. Offline

    Zombie_Striker

    @MondernDayMC
    1. Add the recipe the normal way
    2. Create a new event for PrepareItemCraftEvent.
    3. If the ingredient at the spot where the pickaxe should be is not the special one you are looking for (to do this, check if the displaynames are the same), then set the result to air.
     
  3. Offline

    MondernDayMC

    Okay, now, would put the crafting recipe in the PrepareItemCraftEvent event or how would I use that?
     
  4. Offline

    Zombie_Striker

  5. Offline

    MondernDayMC

    @Zombie_Striker I always do them in the onEnable. Would I then do something like this in the onEnable?
    Code:
    @Override
    public void onEnable(){
       @EventHandler
      public void  PrepareItemCraft(PrepareItemCraftEvent e){
       /*****Recipes here*****/
       }
    }
    Or is there some other way that I should try doing it? Feel free to give a working example, It would help me the most.
     
  6. Offline

    timtower Administrator Administrator Moderator

  7. Offline

    MondernDayMC

    Thats what I thought. I appologize. Im not that great with java. Im learning though!

    So. Basically you're saying that I have to register the recipe in onEnable then if I want to use one of those crafting recipes in another crafting recipe I have to have that crafting recipe an PrepareItemCraftEvent outside of onEnable. Correct?
     
  8. Offline

    timtower Administrator Administrator Moderator

    @MondernDayMC Yes. And I also want to advice to learn the Java basics before you continue.
     
Thread Status:
Not open for further replies.

Share This Page