Getting Started

Discussion in 'Plugin Development' started by Zachster, Dec 17, 2011.

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

    Zachster

    Hi. I'm working on my first plugin and I was wondering, how would you add a new furnace recipe? It's a simple plugin that turns coal into diamond. Here is my code.

    Code:
    package me.Zachster.CoalToDiamond;
    
    import java.util.logging.Logger;
    import org.bukkit.Material;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class CoalToDiamond extends JavaPlugin {
        Logger log = Logger.getLogger("Minecraft");
        public void onEnable() {
            log.info("Coal To Diamond v1.0 is now enabled!");
        }
        public void onDisable() {
            log.info("Coal To Diamond v1.0 is now disabled!");
        }
        public void FurnaceRecipe(ItemStack result, Material source) {
        result = new ItemStack(Material.DIAMOND, 1);
        source = Material.COAL;
        }
    }
     
  2. Offline

    Patrick Wrobel

    This should help
    Code:
    public void addRecipesToServer(CoalToDiamond plugin)
        {
    
                int sourceId = 263; //coal
                int resultId = 264; //diamond
                int resultQuantity = 1;
    
                ItemStack item = new ItemStack(resultId, resultQuantity);
                FurnaceRecipe recipe = new FurnaceRecipe(item, new MaterialData(sourceId));
    
                plugin.getServer().addRecipe(recipe);
        }
     
  3. Offline

    Zachster

    Code:
    package me.Zachster.CoalToDiamond;
    
    import java.util.logging.Logger;
    import org.bukkit.inventory.FurnaceRecipe;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.material.MaterialData;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class CoalToDiamond extends JavaPlugin {
        Logger log = Logger.getLogger("Minecraft");
        public void onEnable() {
            log.info("Coal To Diamond v1.0 is now enabled!");
        }
        public void onDisable() {
            log.info("Coal To Diamond v1.0 is now disabled!");
        }
        public void addRecipesToServer(CoalToDiamond plugin)
        {
    
                int sourceId = 263; //coal
                int resultId = 264; //diamond
                int resultQuantity = 1;
    
                ItemStack item = new ItemStack(resultId, resultQuantity);
                FurnaceRecipe recipe = new FurnaceRecipe(item, new MaterialData(sourceId));
    
                plugin.getServer().addRecipe(recipe);
        }
    }
    It didn't work. Did I put the code in the right place?
     
  4. Offline

    Patrick Wrobel

    It's a method so you have to call it. Ideally, it should be called when your plugin is loaded.
     
  5. Offline

    Zachster

    Ok. I know it says null but that's what Eclipse suggested. Sorry for all the questions. I'm half asleep right now.

    Code:
    package me.Zachster.CoalToDiamond;
    
    import java.util.logging.Logger;
    import org.bukkit.inventory.FurnaceRecipe;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.material.MaterialData;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class CoalToDiamond extends JavaPlugin {
        public void addRecipesToServer(CoalToDiamond plugin)
        {
    
                int sourceId = 263; //coal
                int resultId = 264; //diamond
                int resultQuantity = 1;
    
                ItemStack item = new ItemStack(resultId, resultQuantity);
                FurnaceRecipe recipe = new FurnaceRecipe(item, new MaterialData(sourceId));
    
                plugin.getServer().addRecipe(recipe);
        }
        Logger log = Logger.getLogger("Minecraft");
        public void onEnable() {
            addRecipesToServer(null);
            log.info("Coal To Diamond v1.0 is now enabled!");
        }
        public void onDisable() {
            log.info("Coal To Diamond v1.0 is now disabled!");
        }
    }
     
  6. Offline

    Patrick Wrobel

    Yeah, that was my mistake. When I gave you the example, I was in the mindset of putting it in its own or another class, but in your case the argument to the addRecipesToServer method is unnecessary . Anyways you have two options: move the method to another class, or edit the method so that it takes no arguments and so that its last line is just getServer().addRecipe(recipe);
     
  7. Offline

    Zachster

    It worked. Thank you so very much.
     
Thread Status:
Not open for further replies.

Share This Page