1.16.5 Custom Recipes RecipeChoice.ExactChoice Alternative

Discussion in 'Spigot Plugin Development' started by MrPeterss, Jun 10, 2021.

  1. Hey all,

    I need to create a recipe that is shapeless and uses a custom item I have created. Here is what I have:

    Code (Java):
    ShapelessRecipe horser = new ShapelessRecipe(new NamespacedKey(Main.plugin, "horser"),HorseElytra);
            horser.addIngredient(new RecipeChoice.ExactChoice(horsehead));
            horser.addIngredient(Material.ELYTRA);
            Bukkit.addRecipe(horser);
    This kinda works, lemme explain.

    It adds the recipe, but not with the custom item. It just sets the Ingredient to the Material of my custom item and not the item itself... This is a problem because I have multiple custom items with custom recipes that are all the same Material. I think this has something to do with RecipeChoice.ExactChoice being depricated, but I have no Idea how else I would put my custom Item there...

    Can anyone assist me?

    Thanks,
    MrPeterss
     
  2. https://stackoverflow.com/questions/59214993/bukkit-add-custom-item-with-custom-recipe

    You must add onEnable this code
     
  3. Choco

    Moderator

    upload_2021-6-9_23-41-35.png
     
  4. Ah thank you. Kinda weird that there is not way to put a custom item in a shapeless recipe

    might suggest that as a feature
     
    #4 MrPeterss, Jun 10, 2021
    Last edited: Jun 10, 2021
  5. I think that you will find that this condition also applies to ShapedRecipe()
    (The ShapeLess and Shaped methods allow 'patterns' of Material to be registered in the server to set a possible output ItemStack() )
    The solution is to use PrepareItemCraftEvent
    Code (Text):
    @EventHandler
        public void customCrafting(PrepareItemCraftEvent prepareItemCraftEvent) {
            if (prepareItemCraftEvent.getInventory().getResult() == null) return;
            CraftingInventory craftingInventory = prepareItemCraftEvent.getInventory();
     
    Use conditional testing for the result, and for the contained ingedients.
    This method allows you to identify ItemStack() properties from the CraftingInventory().
     
    #5 Goldentoenail, Jun 11, 2021
    Last edited: Jun 11, 2021