public bool Craft(CraftingRecipe recipe) { List <ItemStack> ingredients = recipe.IngredientsCopy; for (int i = 0; i < ingredients.Count; i++) { ItemStack stack = ingredients[i]; Item.Type type = stack.ItemType; Storage inv = GetAppropriateInventory(type); if (ItemStack.Count(inv.ItemStacks, type) < stack.Amount) { return(false); } } defaultInventory.RemoveItems(ingredients); List <ItemStack> results = recipe.ResultsCopy; if (!defaultInventory.CanFit(results)) { defaultInventory.AddItems(ingredients); return(false); } OnItemsCrafted?.Invoke(results); defaultInventory.AddItems(results); return(true); }
public bool HasItems(List <ItemStack> stacks) { for (int i = 0; i < stacks.Count; i++) { Item.Type type = stacks[i].ItemType; Storage inv = GetAppropriateInventory(type); int expectedAmount = ItemStack.Count(stacks, type); if (ItemStack.Count(inv.ItemStacks, type) < expectedAmount) { return(false); } } return(true); }