Cactus
Based on game build 714014 | Last updated: 2026-03-04
Overview
The cactus.lua file defines the prefabs for cactus plants (cactus, oasis_cactus) and cactus flowers (cactus_flower). It implements the pickable component to manage harvesting and regrowth, handles thorn-based combat interactions when harvested by non-protected players, and supports seasonal flowering behavior (only in summer). Cacti are passive environmental entities that drop cactus_meat upon harvesting, and in summer may produce cactus_flower items. The cactus flower is an edible, perishable item.
Usage example
local cactus = SpawnPrefab("cactus")
cactus.Transform:SetWorldPosition(x, y, z)
-- Force regrowth after picking (e.g., after a regen period)
cactus.components.pickable:MakeEmpty()
Dependencies & tags
Components used: pickable, inspectable, edible, perishable, stackable, inventoryitem, tradable, combat (for damage), inventory (for item giving and tag checking).
Tags added: plant, thorny.
Tags checked: bramble_resistant, shadowminion.
Properties
No public properties are defined directly on the cactus prefab or its prefabs. Behavior is driven entirely by component state and callbacks.
Main functions
ontransplantfn(inst)
- Description: Called when the cactus is transplanted (e.g., via planter). Sets the cactus to an empty, non-pickable state.
- Parameters:
inst(Entity) — the cactus entity. - Returns: Nothing.
onpickedfn(inst, picker)
- Description: Called when the cactus is picked/harvested. Deactivates physics, plays pick animation, damages the picker if not protected, drops
cactus_flower(if flowered), and marks the cactus empty. Also applies wetness to dropped items. - Parameters:
inst(Entity) — the cactus entity.
picker(Entity ornil) — the entity harvesting the cactus (may benilfor non-player drops). - Returns: Nothing.
- Error states: If
pickerisnil, no damage or item giving occurs.
onregenfn(inst)
- Description: Regrows the cactus after harvesting. Sets seasonal animation (
idle_flowerin summer,idleotherwise), activates physics, and updateshas_flowerstate. - Parameters:
inst(Entity) — the cactus entity. - Returns: Nothing.
makeemptyfn(inst)
- Description: Resets the cactus to its empty state (non-pickable). Deactivates physics and plays the "empty" animation.
- Parameters:
inst(Entity) — the cactus entity. - Returns: Nothing.
OnEntityWake(inst)
- Description: Ensures correct animation and flowering state when the cactus wakes (e.g., world deserialization or re-entry to zone). Syncs
has_flowerwith world season if pickable, otherwise sets to empty. - Parameters:
inst(Entity) — the cactus entity. - Returns: Nothing.
MakeCactus(name)
- Description: Factory function that creates a cactus prefab (
cactusoroasis_cactus). Initializes core components, tags, physics, and callbacks. - Parameters:
name(string) — the base name for assets (e.g.,"cactus"or"oasis_cactus"). - Returns:
Prefab— a reusablePrefab definition. - Notes:
- Sets up
pickablewith callbacks (onpickedfn,onregenfn,makeemptyfn,ontransplantfn). - Adds
thornytag andplanttag. - Attaches
MakeLargeBurnable,MakeMediumPropagator,AddToRegrowthManager, andMakeHauntableIgnite. cactus_floweris defined separately viacactusflowerfn.
- Sets up
cactusflowerfn()
- Description: Factory function that creates the
cactus_flowerprefab (an edible, stackable item). - Parameters: None.
- Returns:
Prefab— the cactus flower prefab. - Notes:
- Adds
edible,perishable,stackable,inventoryitem, andtradablecomponents. - Sets perish time to
PERISH_SUPERFASTand replacement tospoiled_food. - Uses
MakeInventoryPhysics,MakeInventoryFloatable,MakeSmallBurnable,MakeSmallPropagator, andMakeHauntableLaunch.
- Adds
Events & listeners
- Listens to:
OnEntityWake(global callback oninst) — handles initial state restoration on entity wake. - Pushes:
thorns— pushed on thepickerentity when they take thorn damage.