Solved Get Recipe from ArrayList?

Discussion in 'Spigot Plugin Development' started by BlackBeltPanda, May 20, 2016.

Thread Status:
Not open for further replies.
  1. Jan 19, 2022 Edit: Anyone looking for something similar, you can now use (as of 1.17):
    Code (Java):
    Bukkit.getCraftingRecipe(ItemStack[], World)

    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.
    #1 BlackBeltPanda, May 20, 2016
    Last edited: Jan 19, 2022
  2. Choco


    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
  3. You could play with the Recipe Matrix too but I haven't done that in a while :x
    • Like Like x 1
  4. 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.
  5. HashMap<ItemStack, String[]>
  6. How does that help me?
  7. I think he ment the String[] is the recipe and the ItemStack is the result
  8. 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.
    • Like Like x 1
  9. 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.
    #9 BlackBeltPanda, May 21, 2016
    Last edited: May 21, 2016
  10. 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.
Thread Status:
Not open for further replies.