Cooking
Based on game build 722832 | Last updated: 2026-04-28
Overview
cooking.lua defines the global cooking system that tracks all recipes, ingredients, and cookbook entries for cookers (cookpot, portablecookpot, archive_cookpot, portablespicer). It provides functions to register new recipes and ingredients, query valid recipes for given ingredients, and calculate final cooking results. This file is a configuration source — it is not a component and does not attach to entities; it is required by cooking-related components and prefabs that need to resolve recipe outcomes.
Usage example
local cooking = require("cooking")
-- Check if a prefab is a valid cooking ingredient
if cooking.IsCookingIngredient("meat") then
print("meat can be used in cooking")
end
-- Get a specific recipe by cooker and product name
local recipe = cooking.GetRecipe("cookpot", "meatballs")
-- Check if any mod cooker foods are registered
local has_mod_foods = cooking.HasModCookerFood()
-- Calculate what recipe will be produced from given ingredients
local product, cooktime = cooking.CalculateRecipe("cookpot", {"meat", "meat", "carrot", "ice"})
-- Access exported tables directly
local all_recipes = cooking.recipes["cookpot"]
local all_ingredients = cooking.ingredients
Dependencies & tags
External dependencies:
tuning-- global balance constants (imported but not directly used in exported functions)prefabs/oceanfishdef-- provides ocean fish definitions for ingredient registrationpreparedfoods-- standard cookpot recipes loaded into cookerrecipes tablepreparedfoods_warly-- Warly's portable cookpot exclusive recipesspicedfoods-- portable spicer recipespreparednonfoods-- non-food cooking products (e.g., soap, fuels)
Components used: None identified
Tags: None identified
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
official_foods | table | {} | Tracks prefab names of official (non-mod) foods. Used by IsModCookerFood() to distinguish mod-added recipes. |
cookerrecipes | table | {} | Maps cooker names ("cookpot", "portablecookpot", "archive_cookpot", "portablespicer") to tables of recipe definitions keyed by product name. |
cookbook_recipes | table | {} | Maps cookbook category names to recipe tables. Excludes recipes with no_cookbook = true and portablespicer recipes. |
recipe_cards | table | {} | Array of recipe card entries {recipe_name = name, cooker_name = cooker}. Used for cookbook UI display. |
ingredients | table | {} | Maps ingredient prefab names to tag value tables. Includes cooked/dried variants when cancook/candry flags are set. |
aliases | table (local) | {...} | Maps inconsistent prefab naming conventions (e.g., cookedsmallmeat → smallmeat_cooked). Used internally by IsCookingIngredient and GetIngredientValues for name resolution. |
MOD_COOKBOOK_CATEGORY | constant (local) | "mod" | Category name used for mod-added recipes in the cookbook. |
Main functions
IsModCookerFood(prefab)
- Description: Checks if a prefab name corresponds to a mod-added cooking product (not in official_foods table).
- Parameters:
prefab-- string prefab name of cooking product - Returns:
trueif mod-added,falseif official food or unknown - Error states: None.
HasModCookerFood()
- Description: Checks if any mod cooker foods are currently registered in the cookbook.
- Parameters: None
- Returns:
trueifcookbook_recipes["mod"]exists,falseotherwise - Error states: None.
IsCookingIngredient(prefabname)
- Description: Checks if a prefab name is registered as a valid cooking ingredient (exists in
ingredientstable after alias resolution). - Parameters:
prefabname-- string prefab name to check - Returns:
trueif valid ingredient,falseotherwise - Error states: None.
GetRecipe(cooker, product)
- Description: Retrieves a specific recipe definition by cooker name and product name.
- Parameters:
cooker-- string cooker nameproduct-- string product prefab name
- Returns: Recipe table or
nilif not found - Error states: None.
GetIngredientValues(prefablist)
- Description: Aggregates ingredient tags and counts from a list of prefab names. Resolves aliases and sums tag values for matching ingredients.
- Parameters:
prefablist-- table array of ingredient prefab names - Returns: Table with
tags(table of tag name to value sums) andnames(table of prefab name to count). - Error states: None.
GetCandidateRecipes(cooker, ingdata)
- Description: Finds all potentially valid recipes matching given ingredients. Filters recipes by testing against ingredient names and tags, then sorts by priority and returns highest-priority candidates.
- Parameters:
cooker-- string cooker nameingdata-- table from GetIngredientValues withtagsandnamesfields
- Returns: Array of recipe tables sorted by priority (highest first). Returns empty table if no matches.
- Error states: None.
CalculateRecipe(cooker, names)
- Description: Determines the final cooking result from a list of ingredient prefab names. Gets ingredient values, finds candidate recipes, then uses weighted random selection based on recipe
weightvalues. - Parameters:
cooker-- string cooker namenames-- table array of ingredient prefab names
- Returns:
product_name(string or nil),cooktime(number or nil). When no recipes match, returns nil, nil (no explicit return in source when candidates table is empty). - Error states: None.
AddCookerRecipe(cooker, recipe, is_mod_food)
- Description: Registers a recipe definition for a specific cooker. Adds the recipe to
cookerrecipestable and optionally tocookbook_recipesandofficial_foodsbased onis_mod_foodflag. - Parameters:
cooker-- string cooker name (e.g., "cookpot", "portablecookpot", "archive_cookpot", "portablespicer")recipe-- table recipe definition with fields:name(string),test(function),priority(number),weight(number),cooktime(number),no_cookbook(boolean),card_def(table)is_mod_food-- boolean, if true setscookbook_categoryto "mod" and skips official_foods registration
- Returns: None
- Error states: Errors if
cookerorrecipeis nil (no nil guards in source —cookerrecipes[cooker]andrecipe.namewill nil-dereference).
AddIngredientValues(names, tags, cancook, candry)
- Description: Registers ingredient prefab names with tag values for cooking system. Creates entries in
ingredientstable and optionally generates cooked/dried variants whencancook/candryflags are set. - Parameters:
names-- table array of ingredient prefab namestags-- table mapping tag names to numeric values (e.g.,{meat=1, veggie=0.5})cancook-- boolean, if true createsprefab_cookedvariant withprecooktagcandry-- boolean, if true createsprefab_driedvariant withdriedtag
- Returns: None
- Error states: Errors if
namesortagsis nil (no nil guards in source —pairs(names)andpairs(tags)will error on nil).
Events & listeners
None.