Skip to main content

Flower Cave

Based on game build 714014 | Last updated: 2026-03-05

Overview

The flower_cave prefab represents a bioluminescent cave plant that emits light when active. It operates via a state machine with three states: ON (emitting light), CHARGED (ready to turn on), and RECHARGING (restoring capacity after use or low light exposure). Its behavior integrates the timer, pickable, halloweenmoonmutable, inspectable, and lootdropper components. The plant interacts with the LightWatcher component to respond to ambient light levels and enters the ON state when exposed to sufficient darkness.

Usage example

local inst = CreateEntity()
inst.entity:AddTransform()
inst.entity:AddAnimState()
inst.entity:AddSoundEmitter()
inst.entity:AddMiniMapEntity()
inst.entity:AddLight()
inst.entity:AddLightWatcher()
inst.entity:AddNetwork()

-- Add required components
inst:AddComponent("timer")
inst:AddComponent("pickable")
inst:AddComponent("halloweenmoonmutable")
inst:AddComponent("lootdropper")
inst:AddComponent("inspectable")

-- Initialize light parameters (see commonfn logic)
inst.light_params = {
falloff = 0.5,
intensity = 0.8,
radius = 3,
}
inst:AddTag("plant")

-- Call initialization logic (e.g., commonfn or prefabricated constructors)
-- Finalize with appropriate prefab type (single/double/triple/withered)

Dependencies & tags

Components used: timer, pickable, halloweenmoonmutable, lootdropper, inspectable, lightwatcher, transform, animstate, soundemitter, minimapentity, light, network
Tags: Adds plant via inst:AddTag("plant")

Properties

PropertyTypeDefault ValueDescription
plantnamestring?nilOptional suffix variant (e.g., "_single", "_springy") affecting animation bank/build.
light_statestringLIGHT_STATES.CHARGEDCurrent state: "ON", "CHARGED", or "RECHARGING".
light_paramstablesee definitionsLight configuration including radius, intensity, falloff, and optional turnoff_time, recharge_time functions.
is_bulb_witheredbooleanfalseIndicates whether the plant is the withered variant (produces spoiled_food).
_lighttimenet_tinybyte0Networked time offset for light fade/revive animation.
_lightframenet_bytemath.floor(LIGHT_MIN_TIME / FRAMES + .5)Current animation frame index.
_islightonnet_boolfalseNetworked flag for whether the light is active.
_lightmaxframenumbermath.floor(LIGHT_MIN_TIME / FRAMES + .5)Maximum frame count for animation transitions.
_lighttaskTask?nilPeriodic task managing light transition animation.

Main functions

SetLightState(inst, state)

  • Description: Updates the plant's animation sequence based on the given state, and records the state in inst.light_state.
  • Parameters:
    state (string) — One of LIGHT_STATES.ON, .CHARGED, or .RECHARGING.
  • Returns: Nothing.

TurnOn(inst)

  • Description: Activates the light if the plant is CHARGED and harvestable. Initiates a fade-in animation, sets the light state to ON, and schedules a timer to turn it off.
  • Parameters: None.
  • Returns: Nothing.
  • Error states: Early returns if pickable:CanBePicked() is false.

TurnOff(inst)

  • Description: Deactivates the light and transitions the plant to RECHARGING. Schedules a recharge timer and resets animation state.
  • Parameters: None.
  • Returns: Nothing.

Recharge(inst)

  • Description: Completes the recharge cycle, transitions the plant to CHARGED. If the plant is in darkness (via LightWatcher), it automatically calls TurnOn.
  • Parameters: None.
  • Returns: Nothing.

ForceOn(inst)

  • Description: Immediately sets the light to ON state, bypassing state checks. Used during entity load or forced activation.
  • Parameters: None.
  • Returns: Nothing.

ForceOff(inst, on_load)

  • Description: Immediately turns off the light and forces RECHARGING or playback of the final animation frame if on_load is true. Used during load, pickup, or regeneration.
  • Parameters:
    on_load (boolean) — Whether this is called during entity load (affects animation).
  • Returns: Nothing.

CanTurnOn(inst)

  • Description: Returns whether the light may transition from CHARGED to ON.
  • Parameters: None.
  • Returns: booleantrue if light_state == LIGHT_STATES.CHARGED.

Events & listeners

  • Listens to:
    • timerdone — Triggers ontimerdone to handle recharge or turn-off logic.
    • enterlight — Triggers enterlight, which calls TurnOn.
    • lightdirty (client) — Refreshes light animation and state (via OnLightDirty).
  • Pushes: None directly (relies on entity-wide events like animover for cleanup).