public class Item
{
    public ItemData data;
    public int currentAmount = 0;
    public double elapsedCraftTime = 0;
    public int amountCrafted = 0;

    public CraftingResult Craft(int amount, double delta)
    {
        elapsedCraftTime += delta;
        if (elapsedCraftTime >= data.CraftTime)
        {
            elapsedCraftTime -= data.CraftTime;
            if (!GameData.inventory.AddItem(this, 1))
            {
                return CraftingResult.FAILED;
            }

            foreach (Ingredient ingredient in data.Inputs)
            {
                GameData.inventory.RemoveItem(ingredient.Item, ingredient.Amount);
            }

            amountCrafted++;
            if (amountCrafted >= amount)
            {
                amountCrafted = 0;
                elapsedCraftTime = 0;
                return CraftingResult.FINISHED;
            }
        }

        return CraftingResult.CRAFTING;
    }
}
