Crafting Recipe Strange not working :/

Discussion in 'Plugin Development' started by ShredNyx, Dec 10, 2013.

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

    ShredNyx

    Code:java
    1. private ShapelessRecipe stick = new ShapelessRecipe(stick()).addIngredient(Material.APPLE).addIngredient(Material.STICK);
    2.  
    3. public ItemStack stick() {
    4. ItemStack i = new ItemStack(Material.STICK);
    5. ItemMeta im = i.getItemMeta();
    6. im.setDisplayName("Something");
    7. i.setItemMeta(im);
    8. return i;
    9. }
    10.  
    11.  
    12. public void onEnable(){
    13. Bukkit.getPluginManager().registerEvents(this, this);
    14. getServer().addRecipe(stick);
    15. }
    16. @Override
    17. public void onDisable() {
    18. getServer().clearRecipes();
    19. }
    20.  
    21.  
    22.  

    Dooes not craft :O
    Title says it all
     
  2. Offline

    AzubuSan

    ShredNyx I'd look into the API a bit more...you seem to be pretty new to this. ;)
    But hey, we were all new to this at some point so check this out and see if it works for you:

    Code:java
    1.  
    2.  
    3. @Override
    4. public void onEnable() {
    5.  
    6. // Register the recipe
    7. stickrecipe();
    8. }
    9.  
    10. private void stickrecipe() {
    11.  
    12. Itemstack stickitem = new ItemStack(Material.STICK, 1);
    13. ItemMeta stickmeta = stick.getItemMeta(); // This is something I just randomly added
    14. stickmeta.setDisplayName("Custom Crafting Recipe Stick!");
    15. stick.setItemMeta(stickmeta);
    16.  
    17. ShapelessRecipe stickrecipe = new ShapelessRecipe(stick);
    18. stickrecipe.addIngredient(1, Material.WOOD); // Change to whatever
    19. stickrecipe.addIngredient(1, Material.STONE); // Change to whatever
    20.  
    21. Bukkit.getServer().addRecipe(stickrecipe);
    22. }
     
  3. Offline

    ShredNyx

    Register recipe how? getServer().addRecipe(stick); ? With this?
    AzubuSan
     
  4. Offline

    mydeblob

    ShredNyx
    The way AzubuSan made it, it's registering the recipe in the method
     
  5. Offline

    AzubuSan

    ShredNyx Yes, the method private void stickrecipe() { // codestuffs } registers the recipe by including stickrecipe(); in the onEnable().
     
  6. Offline

    ShredNyx

    Still doesnt work mydeblob @AzbuSan
     
  7. Offline

    mydeblob

    ShredNyx
    Did you get any errors in console?
     
  8. Offline

    AzubuSan

    ShredNyx Mind posting the errors? Or is it "just not doing anything?"
     
  9. Offline

    ShredNyx

    No mydeblob @AzbuSan

    Nothing AzubuSan

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  10. Offline

    AzubuSan

    ShredNyx Oh, im so sorry, I made a mistake in my own code up there >_<
    Code:java
    1. public class Recipe extends JavaPlugin implements Listener {
    2.  
    3. public void onEnable() {
    4.  
    5. this.getLogger().info("Enabled!");
    6. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    7.  
    8. // ShapeLess Recipe //
    9.  
    10. stickrecipe();
    11. }
    12.  
    13. private void stickrecipe() {
    14.  
    15. ItemStack stickitem = new ItemStack(Material.STICK, 1);
    16. ItemMeta stickmeta = stickitem.getItemMeta(); // This is something I just randomly added
    17. stickmeta.setDisplayName("Custom Crafting Recipe Stick!");
    18. stickitem.setItemMeta(stickmeta);
    19.  
    20. ShapelessRecipe stickrecipe = new ShapelessRecipe(stickitem);
    21. stickrecipe.addIngredient(1, Material.WOOD); // Change to whatever
    22. stickrecipe.addIngredient(1, Material.STONE); // Change to whatever
    23.  
    24. Bukkit.getServer().addRecipe(stickrecipe);
    25.  
    26. }
    27.  
    28. }
     
  11. Offline

    ShredNyx

  12. Offline

    AzubuSan

    ShredNyx Are you using my code or yours right now? For me it's working fine. Well, anyway one last time ;)

    Code:java
    1. public class Recipe extends JavaPlugin implements Listener {
    2.  
    3. public void onEnable() {
    4.  
    5. this.getLogger().info("Enabled!");
    6. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    7.  
    8. // ShapeLess Recipe //
    9.  
    10. stickrecipe();
    11. }
    12.  
    13. private void stickrecipe() {
    14.  
    15. ItemStack stickitem = new ItemStack(Material.STICK, 1);
    16. ItemMeta stickmeta = stickitem.getItemMeta(); // This is something I just randomly added
    17. stickmeta.setDisplayName("Custom Crafting Recipe Stick!");
    18. stickitem.setItemMeta(stickmeta);
    19.  
    20. ShapelessRecipe stickrecipe = new ShapelessRecipe(stickitem);
    21. stickrecipe.addIngredient(1, Material.APPLE); // Change to whatever
    22. stickrecipe.addIngredient(1, Material.STICK); // Change to whatever
    23.  
    24. Bukkit.getServer().addRecipe(stickrecipe);
    25.  
    26. }
    27.  
    28. }
    29.  
     
  13. Offline

    ShredNyx

    I hav a diff class do they have to be linked in order to work? AzubuSan
     
  14. Offline

    sgavster

    ShredNyx The class with the recipe
    NEEDS to be main; because that is the only class that should extend JavaPlugin, and have onEnable.
     
  15. Offline

    ShredNyx

Thread Status:
Not open for further replies.

Share This Page