Hello there.
I'm currently trying to check if a player would be able to craft an item based on the items the player has in their inventory.
This should be done without using a crafting table or gui. The check is triggered automatically after a specific event (for example right-clicking with an item).
I'm using a 3x3 "InventoryCrafting" matrix to craft items.
It's pretty simple if every slot of a crafting recipe has only 1 valid input. I loop through all slots of the recipe and through the player's inventory to check if all items are available.
The problem occurs if a recipe uses the ore dictionary and has multiple valid inputs for a single slot.
Let's say there is a recipe which requires "anyFoodItem" in Slot 1 and an "apple" in the 2nd slot.
The player has a bread and an apple in it's inventory. Now I loop through the recipe slots + inventory.
It looks for any food item, finds the bread and puts it into the first slot. Afterwards it finds the apple and puts it into the second slot => The recipe works.
But there's a problem. It will not work if both items in the player's inventory are swapped. So instead of "bread, apple" => "apple, bread"
It looks for any food item, finds the apple and puts it into the first slot. Now it finds the bread, but is unable to put it into the second slot since apples are the only valid item for that slot.
This results into a non-working recipe even if the player would be able to craft the item.
To fix this problem I would need to arrange the items in a smart way.
My idea was to check every slot in the crafting matrix and fill the ones which have the least possible items first. But I'm not sure if that works well or if there's a better method.