Exemple #1
0
    public bool CanCraftRecipe(CraftingRecipe recipe)
    {
        List <ItemStack> ingredients = recipe.IngredientsCopy;

        if (!HasItems(ingredients))
        {
            return(false);
        }

        List <Storage>   relatedInventories = new List <Storage>();
        List <ItemStack> results            = recipe.ResultsCopy;

        for (int i = 0; i < ingredients.Count; i++)
        {
            Item.Type type = ingredients[i].ItemType;
            Storage   inv  = GetAppropriateInventory(type);
            if (relatedInventories.Contains(inv))
            {
                continue;
            }
            List <ItemStack> invStacks = inv.CreateCopyOfStacks();
            ItemStack.RemoveItems(invStacks, ingredients);
            relatedInventories.Add(inv);

            for (int j = 0; j < results.Count; j++)
            {
                Item.Type resultItemType = results[i].ItemType;
                Storage   inv2           = GetAppropriateInventory(resultItemType);
                if (inv != inv2)
                {
                    continue;
                }
                if (!ItemStack.CanFit(invStacks, results[i]))
                {
                    return(false);
                }
            }
        }
        return(true);
    }