Creating a recipe with a custom item extending ItemStack

Discussion in 'Plugin Development' started by PinkNeonDinosaur, Mar 24, 2018.

Thread Status:
Not open for further replies.
  1. Problem
    Hello, I am trying to make a custom crafting recipe with a custom item as output. To make things simple for me, I use a custom item that extends ItemStack. This works all fine, but when I add methods to the custom item, the custom recipe does not work anymore (it did before) and does not give any error messages. I tried to do some debugging and found out that when all methods of the custom item class were commented away, it does work, but when I have a normal method, it does not.

    Code
    Main class (open)

    Code:
    public class MobEggs extends JavaPlugin {
        @Override
        public void onEnable() {
            getLogger().info("***MobEggs plugin has been enabled***");
            loadRecipes();
        }
      
        @Override
        public void onDisable() {
            getLogger().info("***MobEggs plugin has been disabled***");
        }
      
        private void loadRecipes() {
            ItemStack mobEgg = new MobEggItem();
            ShapedRecipe mobEggRecipe = new ShapedRecipe(new NamespacedKey(this, "mobEggRecipe"), mobEgg);
            mobEggRecipe.shape(" L ", "LOL", " L ");
            mobEggRecipe.setIngredient('L', Material.LEASH);
            mobEggRecipe.setIngredient('O', Material.EGG);
            Bukkit.getServer().addRecipe(mobEggRecipe);
        }
    }

    MobEggItem class (open)

    Code:
    public class MobEggItem extends ItemStack {
      
        private LivingEntity entity;
        private int amount;
      
        public MobEggItem() {
            super(Material.MONSTER_EGG, 1);
            ItemMeta meta = this.getItemMeta();
            meta.setDisplayName("Mob egg");
            meta.setLore(Arrays.asList("Right click a mob to catch it."));
            this.setItemMeta(meta);
            entity = null;
            amount = 0;
        }
    
    //    public LivingEntity getMob() {
    //        return entity;
    //    }
    //  
    //    public void addAmount(int value) {
    //        amount += value;
    //    }
      
    //    public int getAmount() {
    //        return amount;
    //    }
    }
    


    I hope someone can help me with this problem, all replies are appreciated!

     
  2. Offline

    WattMann

    add
    PHP:
    this.getServer().addRecipe("recipe");
    to yours onEnable()

    and remove LoadRecipes() method

    i hope it will works fine

    good luck with your plugin

    oh, but you are doing it more difficult i hope this helps you
    https://bukkit.org/threads/how-to-make-custom-crafting-recipes.301328/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Mar 24, 2018
  3. I do not see how moving the code from the LoadRecipes() method to my onEnable() method would change anything, the problem lies in the MobEggItem class.
     
Thread Status:
Not open for further replies.

Share This Page