New Crafting Recipe

Discussion in 'Plugin Development' started by KeybordPiano459, Sep 4, 2012.

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

    KeybordPiano459

    Why isn't this working? It's in my onEnable():
    Code:
    final ShapedRecipe mossycobble = new ShapedRecipe(new ItemStack(Material.MOSSY_COBBLESTONE, 1));
            mossycobble.shape("AXX", "BXX", "XXX");
            mossycobble.setIngredient('A', Material.VINE);
            mossycobble.setIngredient('B', Material.DIRT);
            mossycobble.setIngredient('X', Material.AIR);
            getServer().addRecipe(recipe);
     
  2. Offline

    dayofdarkfire

    getServer().addRecipe(recipe);

    should be

    getServer().addRecipe(mossycobble);
     
    MordorKing78 likes this.
  3. Offline

    KeybordPiano459

    still doesnt work
     
  4. Offline

    VoidWhisperer

    Why are you using a shaped recipe.. just use shapeless for something like that.
     
  5. Offline

    KeybordPiano459

    How do I make a shapeless recipe? I thought that made it shapeless...
     
  6. Offline

    dayofdarkfire

    ShapelessRecipe recipe = new ShapelessRecipe(new ItemStack(Material.<output material>, <int>));
    recipe.addIngredient(Material.<input material>);
    getServer().addRecipe(recipe);
     
  7. Offline

    KeybordPiano459

    It still doesn't add any recipe.
     
  8. Offline

    travja

    The only thing I can think is that you need to do this.getServer but that doesnt' make any sense..
     
  9. Offline

    KeybordPiano459

    Yeah I tried and it still didn't add it.
     
  10. Offline

    travja

    Add a delay? Have you tried making the mossy cobble in game or are you going off of the 195 recipies loaded thing?
     
  11. Offline

    KeybordPiano459

    I've gone off the 195 recipes thing and I've tried making it. Also, what do you mean by a delay?

    I just tried a debug message in the recipe, and it printed, no idea what's wrong...
    By the way, my code is now this:
    Code:
    public void MossyCobble() {
            ShapelessRecipe recipe = new ShapelessRecipe(new ItemStack(Material.MOSSY_COBBLESTONE, 1));
            recipe.addIngredient(Material.VINE);
            recipe.addIngredient(Material.DIRT);
            getServer().addRecipe(recipe);
            this.getServer();
        }
    And yes, I have MossyCobble(); in my onEnable()

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  12. Offline

    travja

    K.... KeybordPiano459 I myself haven't tried adding recipes, however, I might be able to mess around with it a bit tomorrow if you want...
     
  13. Offline

    KeybordPiano459

    Please do, I really want to know =/
     
  14. Offline

    dayofdarkfire

    You don't need to make it as a method. Have you tried simply putting the code in the onEnable()?
     
  15. Offline

    travja

    Code:java
    1. package me.Travja.MossyCobble;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Material;
    6. import org.bukkit.inventory.ItemStack;
    7. import org.bukkit.inventory.ShapedRecipe;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class Main extends JavaPlugin{
    11. Logger log;
    12. public void onEnable(){
    13. log = this.getLogger();
    14. this.MossyCobble();
    15. log.info("MossyCobble Loaded and Added recipe!");
    16. }
    17. public void onDisable(){
    18. log.info("MossyCobble Disabled!");
    19. }
    20. public void MossyCobble() {
    21. ShapedRecipe recipe = new ShapedRecipe(new ItemStack(Material.MOSSY_COBBLESTONE, 1));
    22. recipe.shape("AAA", "ABA", "AAA");
    23. recipe.setIngredient('A', Material.VINE);
    24. recipe.setIngredient('B', Material.COBBLESTONE);
    25. this.getServer().addRecipe(recipe);
    26. }
    27. }


    That is my whole plugin right there, I loaded it up on an R2 server(don't know if that makes a difference) put a cobble in the middle and vines all around it and out came mossy cobble..... So I changed the recipe a little but it worked. It's basically the same as yours...
     
    MaliciousMan likes this.
  16. Offline

    KeybordPiano459

    Wait it worked...
     
  17. Offline

    travja

    Cool! Well happy coding!!
     
  18. Offline

    the_merciless

    What if instead of setting the empty slots to air, you set them to null?
     
  19. Offline

    travja

    Should work the same but it might be erroring because it isn't air....
     
  20. Offline

    the_merciless

    I just thought that maybe it was air that was causing the problem, if you were to return an empty block in a players inventory wouldnt it return null rather than air?
     
  21. Offline

    KeybordPiano459

    When I said wait it worked... I meant it as a surprise. That exact code doesn't work for me.
     
  22. Offline

    KeybordPiano459

  23. Offline

    XbannisherX

    I think Digi Knows alot of this :)
    he can prob ''enlight'' you with his knowledge ^^
     
  24. Yes the problem was the air, since unexistent items in the crafting grid are identified as null, the recipe was actually waiting for you to give it the item "air", which you just can't.

    The last code provided should work just fine... it's the only way and you're most likely doing something wrong.

    Also, you don't *have* to fill all the shapes, it can have 1 to 3 characters and you don't have to fill all 3 rows.
    If you want to specify air, just leave a space.
    Here's an example with your original shape:
    Code:
    ShapedRecipe recipe = new ShapedRecipe(new ItemStack(Material.MOSSY_COBBLESTONE, 1));
    recipe.shape("A", "B");
    recipe.setIngredient('A', Material.VINE);
    recipe.setIngredient('B', Material.COBBLESTONE);
    getServer().addRecipe(recipe);
    Vine on top of cobblestone makes mossy cobblestone.
    If you want it to not have a shape, just use ShapelessRecipe class instead.

    If it still "doesn't work", post your entire test plugin, preferably the jar :}
     
Thread Status:
Not open for further replies.

Share This Page