Mushrooms
Based on game build 714014 | Last updated: 2026-03-06
Overview
The mushrooms.lua file defines three related prefabs per mushroom type (red, green, blue)—the in-ground mushroom, the detached cap, and the cooked version—through reusable functional templates (mushcommonfn, capcommonfn, cookedcommonfn). These prefabs implement seasonal and phase-based growth (day/dusk/night), rain-dependent regeneration, haunted transformation, and cooking behavior. The system heavily integrates with pickable, hauntable, edible, perishable, cookable, fuel, and workable components.
Usage example
local red_mushroom = SpawnPrefab("red_mushroom")
red_mushroom.Transform:SetPosition(0, 0, 0)
-- Interact with its components after it spawns
if red_mushroom.components.pickable and red_mushroom.components.pickable:CanBePicked() then
red_mushroom:PushEvent("dig") -- triggers workable callback
end
Dependencies & tags
Components used:
inspectable, pickable, lootdropper, workable, hauntable, fuel, edible, perishable, tradable, stackable, inventoryitem, cookable, snowmandecor
Tags added: cookable, mushroom (on caps only)
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
rain | number | 0 | Tracks remaining rain cycles needed for regrowth after being picked. |
growtask | Task | nil | Delayed task used for opening/closing phases in caves. |
data | table | {} | Holds type-specific settings (e.g., open_time, sanity, health, pickloot). |
opentaskfn | function | defined in constructor | Callback to transition the mushroom to the fully visible open state. |
closetaskfn | function | defined in constructor | Callback to bury the mushroom underground. |
Main functions
mushcommonfn(data)
- Description: Creates and configures the in-ground mushroom prefab. Handles growth, rain-dependent regeneration, phase-based visibility, haunting, and digging rewards.
- Parameters:
data(table) — Containsname,animname,pickloot,open_time,health,hunger,sanity, etc. - Returns: Entity instance (
inst) with all components attached and logic wired. - Error states: Returns early with only networked components on the client (
TheWorld.ismastersim == false).
capcommonfn(data)
- Description: Creates the detached mushroom cap prefab used as a loot item or cooked ingredient. Edible, perishable, stackable, and hauntable.
- Parameters:
data(table) — Mirrorsmushcommonfndata, usinghealth,hunger,sanity, and cooked variants. - Returns: Entity instance with edible, perishable, stackable, tradable, and cookable components.
- Error states: Returns early with minimal components on the client.
cookedcommonfn(data)
- Description: Creates the cooked mushroom cap prefab. Edible, perishable, stackable, fuel, and hauntable.
- Parameters:
data(table) — Usescookedhealth,cookedhunger,cookedsanity. - Returns: Entity instance with edible, perishable, stackable, fuel, and tradable components.
OnHauntMush(inst, haunter)
- Description: Handles haunting of in-ground mushrooms: may transform into another mushroom type, open/close, or spawn
small_puff. May also ignite under rare conditions (commented out). - Parameters:
inst(Entity) — The mushroom being haunted;haunter(Entity) — The haunter. - Returns:
trueon successful haunt; otherwisefalse. - Error states: Returns
falseif haunt chance fails or mushroom is not interactable.
OnHauntCapOrCooked(inst, haunter)
- Description: Handles haunting of caps and cooked mushrooms. Transforms them to another color variant, preserving stack size, moisture, and percent-perished.
- Parameters:
inst(Entity),haunter(Entity). - Returns:
trueon successful transformation; otherwisefalse.
Events & listeners
- Listens to:
"iscave<phase>"— TriggersOnIsOpenPhaseto open/close in caves."spawnedfromhaunt"— CallsOnSpawnedFromHauntto launch the new entity.
- Pushes:
"despawnedfromhaunt"— Fired when an old mushroom is replaced via haunting."perishchange"— Fired byperishablewhen percent changes."stacksizechange"— Fired bystackablewhen size changes."loot_prefab_spawned"— Fired bylootdropperwhen loot is dropped.