Edible
Based on game build 714014 | Last updated: 2026-03-03
Overview
The edible component defines the nutritional and thermal characteristics of consumable items. It calculates restoration values (health, hunger, sanity) based on food quality (fresh, stale, spoiled), eater affinity, and spicing. It integrates with eater, perishable, foodaffinity, stackable, and temperature components to handle consumption logic, spoilage degradation, and belly temperature effects.
Usage example
local inst = CreateEntity()
inst:AddComponent("edible")
inst.components.edible.healthvalue = 15
inst.components.edible.hungervalue = 10
inst.components.edible.sanityvalue = 5
inst.components.edible.foodtype = FOODTYPE.MEAT
inst.components.edible.temperaturedelta = 5
inst.components.edible.temperatureduration = 60
inst:AddTag("edible_"..FOODTYPE.MEAT)
Dependencies & tags
Components used: eater, perishable, foodaffinity, stackable, temperature
Tags added/removed: badfood, edible_<foodtype>, edible_BERRY (handled during removal)
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
healthvalue | number | 10 | Base health restored by consumption; triggers badfood tag if < 0. |
hungervalue | number | 10 | Base hunger restored by consumption. |
sanityvalue | number | 0 | Base sanity restored by consumption; triggers badfood tag if < 0. |
foodtype | FOODTYPE enum | FOODTYPE.GENERIC | Primary food type; adds edible_<foodtype> tag. |
secondaryfoodtype | FOODTYPE enum or nil | nil | Secondary food type; adds edible_<foodtype> tag. |
oneaten | function or nil | nil | Callback when food is eaten: function(inst, eater). |
degrades_with_spoilage | boolean | true | Whether food values degrade when stale or spoiled. |
gethealthfn | function or nil | nil | Override for health calculation: function(food, eater). |
getsanityfn | function or nil | nil | Override for sanity calculation: function(food, eater). |
stale_hunger | number | TUNING.STALE_FOOD_HUNGER | Multiplier or value for hunger when stale (used if eater has no override). |
stale_health | number | TUNING.STALE_FOOD_HEALTH | Multiplier or value for health when stale (used if eater has no override). |
spoiled_hunger | number | TUNING.SPOILED_FOOD_HUNGER | Multiplier or value for hunger when spoiled (used if eater has no override). |
spoiled_health | number | TUNING.SPOILED_FOOD_HEALTH | Multiplier or value for health when spoiled (used if eater has no override). |
temperaturedelta | number | 0 | Temperature impact on eater's belly (positive = heater, negative = cooler). |
temperatureduration | number | 0 | Duration (in seconds) of temperature effect. |
chill | number | 0 | Chill factor [0, 1] reducing effective temperature impact. |
spice | string or nil | nil | Spice type used for multipliers from TUNING.SPICE_MULTIPLIERS. |
Main functions
GetHealth(eater)
- Description: Computes health restoration for the eater, applying spoilage, spicing, and eater-specific overrides.
- Parameters:
eater(Entity ornil) – the entity consuming this food. May benilfor preview/use. - Returns: number – final health value.
- Error states: Returns
0for stale food with positivehealthvalue; returns-TUNING.SANITY_SMALLif spoiled andsanityvalueis involved.
GetHunger(eater)
- Description: Computes hunger restoration, factoring in spoilage, eater affinity, and spicing.
- Parameters:
eater(Entity ornil) – the entity consuming this food. May benilfor preview/use. - Returns: number – final hunger value.
- Error states: If spoiled, hunger restoration may be reduced based on
spoiled_hunger.
GetSanity(eater)
- Description: Computes sanity restoration, factoring in spoilage, spicing, and eater
ignoresspoilagestatus. - Parameters:
eater(Entity ornil) – the entity consuming this food. May benilfor preview/use. - Returns: number – final sanity value.
- Error states: Returns
0if stale andsanityvalue > 0; returns-TUNING.SANITY_SMALLif spoiled.
OnEaten(eater)
- Description: Processes consumption logic: triggers
oneatencallback, applies belly temperature effects, and firesoneatenevent. - Parameters:
eater(Entity) – the entity consuming this food. - Returns: Nothing.
- Error states: Applies temperature only if
temperaturedelta ~= 0,temperatureduration ~= 0,chill < 1, and eater hastemperaturecomponent.
HandleEatRemove(eatwholestack)
- Description: Handles entity removal after eating; called internally by
eatercomponent. - Parameters:
eatwholestack(boolean) – whether the entire stack should be consumed. - Returns: Nothing.
- Error states: Calls
handleremovefnif set, otherwise usesstackable:Get():Remove()orinst:Remove().
GetStackMultiplier()
- Description: Determines the stack size multiplier for food value calculations.
- Parameters: None.
- Returns: number – stack size or
1if no stack. - Error states: Returns
1if neitheroverridestackmultiplierfnnorstackableis present.
SetOnEatenFn(fn)
- Description: Sets the callback invoked when the item is eaten.
- Parameters:
fn(function) – signature:function(inst, eater). - Returns: Nothing.
SetGetHealthFn(fn)
- Description: Sets the custom health calculation function, overriding
healthvalue. - Parameters:
fn(function) – signature:function(food, eater). - Returns: Nothing.
SetGetSanityFn(fn)
- Description: Sets the custom sanity calculation function, overriding
sanityvalue. - Parameters:
fn(function) – signature:function(food, eater). - Returns: Nothing.
AddChill(delta)
- Description: Increases the chill factor, reducing effective temperature impact over time.
- Parameters:
delta(number) – amount to increase chill. - Returns: Nothing.
- Error states: Only applies if
temperaturedelta > 0andnochillis false or unset.
DiluteChill(item, count)
- Description: Averages chill values across multiple food items in a stack.
- Parameters:
item(Entity) – the additional food item.count(number) – number of items added. - Returns: Nothing.
- Error states: Only applies if
temperaturedelta > 0,nochillis false, both items havestackableandediblecomponents.
OnSave() / OnLoad(data)
- Description: Save/load hooks for replication; persists
chillstate. - Parameters:
data(table ornil) – loaded data containing{ chill = number }. - Returns:
OnSavereturns{ chill = number }ornilifchill <= 0;OnLoadreturns nothing.
Events & listeners
- Pushes:
oneaten– fired on consumption with{ eater = eater }data. - Listens to: None explicitly (event listeners are handled via property callbacks
oncheckbadfoodandonfoodtypeduring assignment).