Spoiledfood
Based on game build 722832 | Last updated: 2026-04-27
Overview
spoiledfood.lua registers three spawnable spoiled food entity prefabs. The main fn() constructor builds the base entity with shared components (fertilizer, edible, inventory, stackable); variant-specific init functions customize animation, loot, and behavior for spoiled_food (disappears in rain, works as fishing lure), spoiled_fish (hammerable for loot), and spoiled_fish_small (smaller variant with random loot). All variants are fertilizer researchable and can be used to fertilize crops.
Usage example
-- Spawn spoiled food at world origin:
local inst = SpawnPrefab("spoiled_food")
inst.Transform:SetPosition(0, 0, 0)
-- Spawn spoiled fish variant:
local fish = SpawnPrefab("spoiled_fish")
-- Reference assets at load time:
local assets = {
Asset("ANIM", "anim/spoiled_food.zip"),
Asset("ANIM", "anim/oceanfishing_lure_mis.zip"),
Asset("SCRIPT", "scripts/prefabs/fertilizer_nutrient_defs.lua"),
}
Dependencies & tags
External dependencies:
prefabs/fertilizer_nutrient_defs.lua-- providesFERTILIZER_DEFStable with nutrient definitions for each variantevent_server_data("quagmire", ...)-- applies Quagmire event mode modifications on master
Components used:
fertilizer-- nutrient values for crop fertilization (all variants)edible-- sets spoiled food status, health/hunger values (all variants)inventoryitem-- allows carrying in inventory (all variants)stackable-- enables stacking up toTUNING.STACK_SIZE_SMALLITEM(all variants)fertilizerresearchable-- enables fertilizer research viaSetResearchFn(all variants)selfstacker-- automatic stacking behavior (all variants)fuel-- burnable as fuel withTUNING.SMALL_FUELvalue (all variants)burnable-- small burn time viaMakeSmallBurnable(all variants)propagator-- fire spreading viaMakeSmallPropagator(all variants)tradable-- enables trading (all variants)smotherer-- extinguishes fires (all variants)inspectable-- provides inspection status (all variants)disappears-- rain-based disappearance forspoiled_foodonlyoceanfishingtackle-- fishing lure setup forspoiled_foodonlydriedsalticon-- salt icon display forspoiled_foodonlylootdropper-- loot drops on hammer for fish variants onlyworkable-- hammer action for fish variants onlyfloater-- floating animation scale (all variants, added via MakeInventoryFloatable in fn()).
Tags:
icebox_valid-- added infn()for icebox storagesaltbox_valid-- added infn()for saltbox storageshow_spoiled-- added infn()for spoiled food displayfertilizerresearchable-- added infn()for research systemselfstacker-- added infn()for auto-stackingspoiledfood-- added infn()for edible component optimizationoceanfishing_lure-- added infood_init()for fishing systemspoiled_fish-- added infish_init()andfish_small_init()for fish identification
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
assets | table | --- | Array of Asset(...) entries for spoiled_food prefab (anim, script). |
fish_assets | table | --- | Array of Asset(...) entries for spoiled_fish prefab. |
fish_small_assets | table | --- | Array of Asset(...) entries for spoiled_fish_small prefab. |
prefabs | table | {"gridplacer_farmablesoil"} | Dependent prefab names loaded with spoiled_food. |
fish_prefabs | table | {"boneshard", "spoiled_food"} | Dependent prefab names loaded with fish variants. |
fish_loot | table | {"spoiled_food", "boneshard"} | Loot table for spoiled_fish hammer drops. |
FERTILIZER_DEFS | table | --- | Imported nutrient definitions from fertilizer_nutrient_defs.lua. |
Main functions
fn(common_init, mastersim_init, nutrients, kind)
- Description: Main entity constructor. Creates the base entity with transform, animstate, network, and physics. Attaches shared components (fertilizer, edible, inventory, stackable, fuel, etc.). Calls
common_initon all sims andmastersim_initonly on server. Returnsinstfor prefab registration. - Parameters:
common_init-- function called on all sims (client and server) for variant-specific setupmastersim_init-- function called only on master sim for server-only component setupnutrients-- table of nutrient values fromFERTILIZER_DEFSkind-- string identifier (e.g.,"food"for spoiled_food variant)
- Returns: entity instance
- Error states: Errors if
common_initormastersim_initis nil when called (no nil guard before callback invocation).
food_init(inst)
- Description: Client-side initialization for
spoiled_foodvariant. Adds ocean fishing lure tag anddriedsalticoncomponent configured to not collect on dried. - Parameters:
inst-- entity instance fromfn() - Returns: None
- Error states: None
food_mastersim_init(inst)
- Description: Server-only initialization for
spoiled_foodvariant. Addsoceanfishingtacklecomponent with lure data, addsdisappearscomponent with dissolve animation and sound, sets up rain event listeners (gainrainimmunity,loserainimmunity,ondropped), watches worldisrainingstate, and configures inventory put callback for rain immunity. - Parameters:
inst-- entity instance fromfn() - Returns: None
- Error states: None
fish_init(inst)
- Description: Client-side initialization for
spoiled_fishvariant. Sets animation bank/build tospoiled_fish, addsspoiled_fishtag, configures floater scale to 0.6, and sets transform scale to 1.3. - Parameters:
inst-- entity instance fromfn() - Returns: None
- Error states: None
fish_mastersim_init(inst)
- Description: Server-only initialization for
spoiled_fishvariant. Addslootdropperwith fixed loot table (fish_loot), addsworkablecomponent with HAMMER action and work callback (fish_onhit), listens forstacksizechangeevent to update work left. - Parameters:
inst-- entity instance fromfn() - Returns: None
- Error states: None
fish_small_init(inst)
- Description: Client-side initialization for
spoiled_fish_smallvariant. Sets animation bank/build tospoiled_fish_small, addsspoiled_fishtag, configures floater scale to 0.35, and sets transform scale to 1.3. - Parameters:
inst-- entity instance fromfn() - Returns: None
- Error states: None
fish_small_mastersim_init(inst)
- Description: Server-only initialization for
spoiled_fish_smallvariant. Sets inspectable name override to"spoiled_fish", addslootdropperwith random loot (50%spoiled_food, 50%boneshard), addsworkablewith HAMMER action and work callback, listens forstacksizechangeevent. - Parameters:
inst-- entity instance fromfn() - Returns: None
- Error states: None
fish_onhit(inst, worker, workleft, workdone)
- Description: Work callback for fish variants when hammered. Calculates loot count based on work done clamped to
TUNING.SPOILED_FISH_LOOT.WORK_MAX_SPAWNS, launches entity if max spawns reached, drops loot vialootdropper, and removes consumed stack items. - Parameters:
inst-- fish entity being hammeredworker-- player/entity performing the workworkleft-- remaining work unitsworkdone-- work units completed this action
- Returns: None
- Error states: Errors if
insthas nostackableorlootdroppercomponents; errors ifLaunchAtfunction is undefined.
fish_stack_size_changed(inst, data)
- Description: Event handler for
stacksizechangeevent on fish variants. Updatesworkablecomponent's work left based on new stack size multiplied byTUNING.SPOILED_FISH_WORK_REQUIRED. - Parameters:
inst-- fish entitydata-- event data table withstacksizefield
- Returns: None
- Error states: None
GetFertilizerKey(inst)
- Description: Returns the prefab name as the fertilizer research key. Used by
fertilizerresearchablecomponent to identify this fertilizer type. - Parameters:
inst-- entity instance - Returns: string prefab name
- Error states: None.
fertilizerresearchfn(inst)
- Description: Research function wrapper that calls
GetFertilizerKey. Assigned tofertilizerresearchablecomponent viaSetResearchFn. - Parameters:
inst-- entity instance - Returns: string fertilizer key from
GetFertilizerKey - Error states: None.
GetStatus(inst, viewer)
- Description: Inspectable status function. Returns
"CAN_PROCESS"if viewer haseatercomponent and is a spoiled processor; returnsnilotherwise. - Parameters:
inst-- entity being inspectedviewer-- player/entity doing the inspecting
- Returns:
"CAN_PROCESS"string ornil - Error states: None
food_IsExposedToRain(inst, israining)
- Description: Checks if
spoiled_foodentity is exposed to rain. Returns true if raining, entity has norainimmunitycomponent, and is not held in inventory. - Parameters:
inst-- entity instanceisraining-- boolean rain state (defaults toTheWorld.state.israiningif nil)
- Returns: boolean
- Error states: Errors if
insthas norainimmunityorinventoryitemcomponents (accessed without nil guards).
food_OnIsRaining(inst, israining)
- Description: World state watcher callback for
israining. Callsdisappears:PrepareDisappear()if exposed to rain, otherwise callsdisappears:StopDisappear(). - Parameters:
inst-- entity instanceisraining-- boolean rain state
- Returns: None
- Error states: None
food_OnRainImmunity(inst)
- Description: Event handler for
gainrainimmunityevent and inventory put callback. Stops the disappear timer when entity gains rain immunity or is placed in inventory. - Parameters:
inst-- entity instance - Returns: None
- Error states: None
food_OnRainVulnerable(inst)
- Description: Event handler for
loserainimmunityandondroppedevents. Re-evaluates rain exposure by callingfood_OnIsRainingwith current world rain state. - Parameters:
inst-- entity instance - Returns: None
- Error states: None
Events & listeners
- Listens to (spoiled_food):
gainrainimmunity-- stops disappear timer viafood_OnRainImmunity - Listens to (spoiled_food):
loserainimmunity-- re-evaluates rain exposure viafood_OnRainVulnerable - Listens to (spoiled_food):
ondropped-- re-evaluates rain exposure viafood_OnRainVulnerable - Listens to (spoiled_fish, spoiled_fish_small):
stacksizechange-- updates work left viafish_stack_size_changed - Watches world state (spoiled_food):
israining-- triggersfood_OnIsRainingwhen rain state changes - Pushes: None identified in this file