Custom Recipe not working

Discussion in 'Plugin Development' started by WiseHollow, Feb 10, 2013.

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

    WiseHollow

    I am trying to figure out how to make custom recipes so i found a snippet online to test it and yet it's not working. I have addRecipe() being called onEnable(). Does anyone know why it's not working when I try to do the recipe ingame? (no errors in console, and using Bukkit 1.4.7 RB)

    Code:
    package me.WiseHollow.FP;
     
    import java.util.Arrays;
    import java.util.List;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapelessRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
     
    public class Coffee
    {
        public static void addRecipe()
        {
            ItemStack coffee = new ItemStack(Material.MUSHROOM_SOUP, 1);
     
            ItemMeta meta = coffee.getItemMeta();
            meta.setDisplayName(ChatColor.GOLD + "Coffee");
            List<String> lore = Arrays.asList(ChatColor.GRAY + "Makes you feel awesome...", ChatColor.GRAY + "... and gives you energy!");
            meta.setLore(lore);
     
            coffee.setItemMeta(meta);
     
            ShapelessRecipe recipe = new ShapelessRecipe(coffee).addIngredient(Material.BOWL).addIngredient(Material.COCOA);
           
            Bukkit.getServer().addRecipe(recipe);
     
        }
    }
    
     
  2. Offline

    gomeow

    Did you remember to call that?
     
  3. Offline

    WiseHollow

    On my onEnable() i have it being called.

    Code:
        @Override
        public void onEnable()
        {
            PluginDescriptionFile desc = this.getDescription();
            log.info(desc.getName() + " v" + desc.getVersion() + " is now enabled.");
            plugin = this;
            Coffee.addRecipe();
           
        }
     
  4. Offline

    bleachisback

    Do you mean "not working" as in when you put the recipe in, it doesn't show anything in the output, or do you mean it as in "it doesn't show the name 'coffee' or the lore"?

    If the latter, I believe this is because ItemMeta does not carry through item recipes, for whatever reason.
     
  5. Offline

    Scipione

    does it fire any errors on startup if the recipes isn't shown ingame ?
    ItemMeta does carry through recipes, i use it myself
     
  6. Offline

    bleachisback

    Can you show what code you use to do this? Because I tried, and it didn't work.
     
  7. Offline

    ZeusAllMighty11

    This happened to me before, restart server?
     
  8. Offline

    Scipione

    Well my code is quite big, because it parses a yml file for recipe entries, but i can share you some parts
    Code:java
    1.  
    2. if(getConfig().getString("Item."+skey+".Displayname")!=null){
    3. ItemMeta meta = stack.getItemMeta();
    4. if(getConfig().getString("Item."+skey+".Displayname")!=null){
    5. meta.setDisplayName(getConfig().getString("Item."+skey+".Displayname"));
    6. ArrayList<String>desc=new ArrayList<String>();
    7. desc.add(getConfig().getString("Item."+skey+".Lore"));
    8. meta.setLore(desc);
    9. }
    10.  
    11. stack.setItemMeta(meta);

    .....
    Code:java
    1.  
    2. ShapelessRecipe stackrecipe = new ShapelessRecipe(stack);
    3. ......
    4. getServer().addRecipe(stackrecipe);
     
  9. Offline

    WiseHollow

    Scipione bleachisback No errors in the slightest. The "coffee item" does not show up when I put together the recipe.

    EDIT: I think it's one of the items for the recipe that is the problem. I changed them to cobble and sand and it worked fine. O.0 Very weird.

    EDIT: I just tried the following code and it worked good. :)
    Code:
    recipe.addIngredient(Material.getMaterial(281));
    recipe.addIngredient(Material.getMaterial(351), 3);
     
Thread Status:
Not open for further replies.

Share This Page