Jan 19, 2022 Edit: Anyone looking for something similar, you can now use (as of 1.17): Code (Java): Bukkit.getCraftingRecipe(ItemStack[], World) /edit I'd like to save recipes as an arraylist but not sure how to get a Recipe object from it or if it's even possible. As a simplified example, I would save the recipe for a Stone Pickaxe as: (Stone, Stone, Stone, Air, Stick, Air, Air, Stick, Air). I'd like to be able to convert that back into a recipe to get the Stone Pickaxe result from it. Edit: I've decided to try a different approach.
I don't think I'm understanding what you want here? Do you want to store information about a specific already existing recipe? Or do you want to store information about recipes that you are creating and adding to the game? If the first option, I would suggest creating some sort of RecipeTracker class or something along the lines of that. Keep an array of nine ItemStacks in said class, (obviously with a getter so you can compare contents in a PrepareItemCraftEvent), and just keep a list of RecipeTrackers I suppose If the second option, use ShapedRecipe and ShapelessRecipe
I want to get an existing recipe from an array of itemstacks. For example: If I display a dispenser inventory to a player and they place items in the slots in the same pattern as an existing recipe, then I create an array list containing the items in the 9 slots when they close the inventory, I want to be able to use that array list to determine what item it would craft as a recipe.
Yeah that doesn't help anyone whoever don't know what hashmap is. HashMap is used to store values to the keys Code (Java): HashMap<Key, Value> name = new HashMap<Key, Value>(); but you can either make a gui then save the 9 slot that has items to the config as list or hashmap like what @liwaa said. then at the onEnable() { ShapedRecipe , ShapelessRecipe , and FurnaceRecipe could be used. spigot wiki is capable of teaching you how to use these things.
Guys, I think you're misunderstanding the question here. I can't save the recipe or result to a hashmap because I don't have the recipe object, yet. All I have is the ingredients saved in an arraylist in the same order they'd be in in a recipe's shape. Here's an example of what I'm trying to do: Display a dispenser/dropper inventory to a player. Player inputs items in the various slots in the shape of a recipe, as if it were a workbench. When the player closes the inventory, the ItemStacks are saved to an arraylist. What I'm trying to figure out is how I can use that arraylist to determine what recipe the player was inputting. If there was a Recipe.fromArray() method, that's what I'd be needing in this case. The position of the ItemStack in the arraylist correlates to the position of the ItemStack in the recipe's shape.
Can you explain for what reason you are trying to do this? The way you're trying to explain it is very difficult to understand and doesn't make much sense.