Custom Crafting Recipe

Discussion in 'Plugin Development' started by benthomas7777, May 26, 2013.

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

    benthomas7777

    When I run this and craft the item, nothing happens, I don't get any item.
    Code:
    package me.benthomas7777.ironchests;
     
    import java.util.logging.Logger;
     
    import org.bukkit.Material;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class main extends JavaPlugin {
        public Logger log = Logger.getLogger("Minecraft");
        public ItemStack ironChest;
       
        @Override
        public void onDisable() {
            getServer().clearRecipes();
        }
       
        @Override
        public void onEnable() {
            PluginManager pm = this.getServer().getPluginManager();
            log.info("[IronChests]: Version "+pm.getPlugin("IronChests").getDescription().getVersion()+" enabled!");
           
            ItemStack iron_chest = new ItemStack(Material.CHEST);
            ItemMeta meta = iron_chest.getItemMeta();
            meta.setDisplayName("Iron Chest");
            iron_chest.setItemMeta(meta);
           
           
            ShapedRecipe recipe = new ShapedRecipe(new ItemStack(iron_chest));
            recipe.shape("###", "#%#", "###");
            recipe.setIngredient('#', Material.IRON_INGOT);
            recipe.setIngredient('%', Material.CHEST);
            getServer().addRecipe(recipe);
        }
     
       
    }
     
  2. Try to use: Bukkit.getServer().addRecipe(recipe);
     
  3. Offline

    benthomas7777

    CaptainBern
    No, that doesn't work. (forgot to mention running craftbukkit version 1.5.2R1
     
  4. Offline

    alf980103

    Your recipe need to be a void, for example:

    Code:
    public void ironChest() {
    ItemStack iron_chest = new ItemStack(Material.CHEST);
    ItemMeta meta = iron_chest.getItemMeta();
    meta.setDisplayName("Iron Chest");
    iron_chest.setItemMeta(meta);
     
    ShapedRecipe recipe = new ShapedRecipe(new ItemStack(iron_chest));
    recipe.shape("###", "#%#", "###");
    recipe.setIngredient('#', Material.IRON_INGOT);
    recipe.setIngredient('%', Material.CHEST);
    getServer().addRecipe(recipe);
    }
          
    And then in onEnable()
    put this: ironChest();

    example:

    Code:
    public void onEnable() {
            ironChest();
    Regards hope this works
     
  5. Offline

    benthomas7777

    @alf980103
    Hi, thanks for you help, but it is still not working! I have been looking every where and can't find fix.
     
  6. Offline

    alf980103

    Did you added the plugin.yml ?
     
  7. Offline

    benthomas7777

    Yes, I just checked that to make sure that the yml was right.
     
  8. Offline

    alf980103


    Code:
    public void ironChest() { 
            ItemStack i = new ItemStack(Material.CHEST, 1);
            ItemMeta meta = i.getItemMeta();
            meta.setDisplayName("§fIronChest");
            ArrayList<String> lore = new ArrayList<String>();
            lore.add("§eAn IC2 Chest! :D");
            meta.setLore(lore);
            i.setItemMeta(meta);
            ShapelessRecipe sr = new ShapelessRecipe(i);
            sr.addIngredient(8, Material.IRON);
            sr.addIngredient(1, Material.CHEST);
            Bukkit.addRecipe(sr);
     
        }
    It's a shapeless recipe, this is how i do it, but i think you can change the shapeless recipe to a shaped recipe :D
     
  9. Offline

    benthomas7777

    @alf980103
    I just tested the code that you gave me and it doesn't work, even if I don't change any thing. Does it work for you.
     
  10. Offline

    ZeusAllMighty11

    alf980103

    It does not have to be in a void method.
     
  11. Offline

    benthomas7777

    @TheGreenGamerHD
    What else would you put over than void and do you know how to fix this. Because I can't even do recipes that don't make renamed items
     
  12. Offline

    lenis0012

    Use this code:

    Code:
    package me.benthomas7777.ironchests;
     
    import java.util.logging.Logger;
     
    import org.bukkit.Material;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class main extends JavaPlugin {
        public Logger log = Logger.getLogger("Minecraft");
        public ItemStack ironChest;
     
        @Override
        public void onDisable() {
            getServer().clearRecipes();
        }
     
        @Override
        public void onEnable() {
            PluginManager pm = this.getServer().getPluginManager();
            log.info("[IronChests]: Version "+pm.getPlugin("IronChests").getDescription().getVersion()+" enabled!");
         
            ItemStack iron_chest = new ItemStack(Material.CHEST);
            ItemMeta meta = iron_chest.getItemMeta();
            meta.setDisplayName("Iron Chest");
            iron_chest.setItemMeta(meta);
         
         
            ShapedRecipe recipe = new ShapedRecipe(new ItemStack(iron_chest));
            recipe.shape(new String[] {"III", "ICI", "III"});
            recipe.setIngredient('I', Material.IRON_INGOT);
            recipe.setIngredient('C', Material.CHEST);
            getServer().addRecipe(recipe);
        }
     
     
    }
     
    benthomas7777 likes this.
  13. Offline

    benthomas7777

    lenis0012
    Hi, I tested your code and it still doesn't work, does it work for you?
     
  14. Offline

    lenis0012

    Then you are doing something wrong
     
  15. Offline

    MrDynamo

    Code:JAVA
    1. package me.benthomas7777.ironchests;
    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.inventory.meta.ItemMeta;
    9. import org.bukkit.plugin.PluginManager;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class main extends JavaPlugin {
    13. public Logger log = Logger.getLogger("Minecraft");
    14. public ItemStack ironChest;
    15.  
    16. @Override
    17. public void onDisable() {
    18. getServer().clearRecipes();
    19. }
    20.  
    21. @Override
    22. public void onEnable() {
    23. PluginManager pm = this.getServer().getPluginManager();
    24. log.info("[IronChests]: Version "+pm.getPlugin("IronChests").getDescription().getVersion()+" enabled!");
    25.  
    26. ItemStack iron_chest = new ItemStack(Material.CHEST);
    27. ItemMeta meta = iron_chest.getItemMeta();
    28. meta.setDisplayName("Iron Chest");
    29. iron_chest.setItemMeta(meta);
    30.  
    31.  
    32. ShapedRecipe recipe = new ShapedRecipe(new ItemStack(IRON_CHEST)).shape("###", "#%#", "###").setIngredient('#', Material.IRON_INGOT).setIngredient('%', Material.CHEST);
    33. getServer().addRecipe(recipe);
    34. }
    35.  
    36.  
    37. }


    May not be the easiest way, but it works AFAIK.
     
    extreme_victory likes this.
  16. Offline

    stickman561

    You can change your on enable to simplify it, just put your shaped recipe method inside of a method called addrecipes then add this to onEnable(): addrecipes(); Here's an example from stickman's items, made by me, just put the addRecipes() method in your on enable.
    Code:java
    1. private void addRecipes() {
    2. if(this.getConfig().getBoolean("dirtsword")) {
    3. ShapedRecipe dirtsword = new ShapedRecipe(dirtsword());
    4. dirtsword.shape(" D ", " D ", " S ");
    5. dirtsword.setIngredient('S', Material.STICK);
    6. dirtsword.setIngredient('D', Material.DIRT);
    7. dirtsword.shape(new String[] { " D ", " D ", " S " });
    8. getServer().addRecipe(dirtsword);
    9. }
    10. }
    11.  
    12. private ItemStack dirtsword() {
    13. ItemStack d = new ItemStack(Material.WOOD_SWORD, 1);
    14. d.setDurability((short) 49);
    15. ItemMeta m = d.getItemMeta();
    16. m.setDisplayName(ChatColor.DARK_GREEN + "Dirt sword");
    17. List<String> s = new ArrayList<String>();
    18. s.add(ChatColor.GREEN + "It is a very crappy sword.");
    19. m.setLore(s);
    20. d.setItemMeta(m);
    21. return d;
    22.  
    23. }
     
Thread Status:
Not open for further replies.

Share This Page