Witherable
Based on game build 714014 | Last updated: 2026-03-03
Overview
Witherable enables an entity to dynamically transition between active (healthy) and withered states in response to environmental conditions — primarily temperature and rain. It integrates with the crop and pickable components to apply state changes (e.g., crop turning into cutgrass, or pickable entering barren state) and supports temporary protection against withering. The component operates asynchronously using scheduled tasks and persists state across saves.
Usage example
local inst = CreateEntity()
inst:AddComponent("witherable")
-- Entity is now subject to temperature- and rain-based withering/rejuvenation cycles
inst.components.witherable:Enable(true) -- explicitly enable
inst.components.witherable:Protect(60) -- prevent withering for 60 seconds
Dependencies & tags
Components used: crop, pickable, rainimmunity
Tags: Adds witherable (always), withered (conditionally based on state)
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
enabled | boolean | true | Whether the component is active and schedules tasks. |
withered | boolean | false | Whether the entity is currently in a withered state. |
wither_temp | number | Random value in [TUNING.MIN_PLANT_WITHER_TEMP, TUNING.MAX_PLANT_WITHER_TEMP] | Threshold temperature above which withering may occur. |
rejuvenate_temp | number | Random value in [TUNING.MIN_PLANT_REJUVENATE_TEMP, TUNING.MAX_PLANT_REJUVENATE_TEMP] | Threshold temperature below which rejuvenation may occur. |
delay_to_time | number or nil | nil | Epoch time at which the current delay period ends (used for weather/forced delays). |
task_to_time | number or nil | nil | Epoch time at which the next scheduled wither/rejuvenate task should run. |
task | Task or nil | nil | Scheduled task handle for wither/rejuvenate logic. |
restore_cycles | number or nil | nil | Stores pickable cycles count before withering for later restoration. |
is_watching_rain | boolean or nil | nil | Whether the component listens for startrain world state events. |
protect_to_time | number or nil | nil | Epoch time until which the entity is protected from withering. |
protect_task | Task or nil | nil | Scheduled task handle for ending protection. |
Main functions
Enable(enable)
- Description: Enables or disables the component. When disabled, all scheduled tasks are cancelled and no new tasks are started.
- Parameters:
enable(boolean) —trueto enable,falseto disable. - Returns: Nothing.
IsWithered()
- Description: Returns whether the entity is currently in a withered state.
- Parameters: None.
- Returns:
trueif withered, otherwisefalse.
IsProtected()
- Description: Returns whether the entity is currently under protection (e.g., from
Protect()). - Parameters: None.
- Returns:
trueif protected, otherwisefalse.
CanWither()
- Description: Returns whether the entity can wither (i.e., is not already withered and is active).
- Parameters: None.
- Returns:
trueif withering is possible, otherwisefalse.
CanRejuvenate()
- Description: Returns whether the entity can rejuvenate (i.e., is currently withered and is not a
crop). - Parameters: None.
- Returns:
trueif rejuvenation is possible, otherwisefalse.
ForceWither()
- Description: Immediately triggers the withering process, bypassing temperature and rain checks. Requires
CanWither()to be true. - Parameters: None.
- Returns: Nothing.
- Error states: No-op if
CanWither()isfalse.
ForceRejuvenate()
- Description: Immediately triggers the rejuvenation process, bypassing temperature and rain checks. Requires
CanRejuvenate()to be true. - Parameters: None.
- Returns: Nothing.
- Error states: No-op if
CanRejuvenate()isfalse.
DelayWither(delay)
- Description: Schedules the next withering attempt no earlier than
delayseconds from now. Does not prevent withering — only delays the next scheduled check. RequiresCanWither()to be true. - Parameters:
delay(number) — delay in seconds. - Returns: Nothing.
DelayRejuvenate(delay)
- Description: Schedules the next rejuvenation attempt no earlier than
delayseconds from now. Respects rain state: if exposed to rain, no delay is scheduled (rejuv can proceed). RequiresCanRejuvenate()to be true. - Parameters:
delay(number) — delay in seconds. - Returns: Nothing.
Protect(duration)
- Description: Applies temporary protection: prevents withering for
durationseconds and immediately triggers forced rejuvenation. Multiple calls extend protection. - Parameters:
duration(number) — protection duration in seconds. - Returns: Nothing.
Start()
- Description: Starts the component’s behavior by scheduling the next task (wither, rejuvenate, or delay) based on current conditions and
delay_to_time/task_to_time. Only runs ifenabled, not sleeping, and no task is pending. - Parameters: None.
- Returns: Nothing.
Stop()
- Description: Cancels the currently scheduled task (
self.task) and stops watching world state events (startrain). Does not modify state. - Parameters: None.
- Returns: Nothing.
OnSave()
- Description: Returns a table containing relevant state data (
withered,restore_cycles,delay_time_remaining,task_time_remaining,protect_time_remaining) for persistence. - Parameters: None.
- Returns: Table or
nil(if no data to save).
OnLoad(data)
- Description: Restores state after loading from a save. Handles
withered,restore_cycles, delay and task timing, and protection. - Parameters:
data(table) — saved state data. - Returns: Nothing.
GetDebugString()
- Description: Returns a human-readable debug string summarizing the current state (e.g.,
"withered: true wither temp: 15 rejuve temp: 5 PROTECTED: 20.00 DELAYING: 12.34"). - Parameters: None.
- Returns: String.
Events & listeners
- Listens to:
startrain(world state) — triggers immediate reschedule (OnStartRain). - Pushes: None directly (but triggers
onwitheredcallbacks viacrop:MakeWithered()). - Hooks:
OnEntitySleep,OnEntityWake— delegates toStop()andStart()respectively.