Pickable
Overview
The Pickable component governs harvestable entities in the game world, handling their growth cycles (including regrowth timers), interaction constraints, regeneration logic, fertilization, and product spawning upon harvesting. It dynamically manages entity tags (pickable, barren, quickpick, jostlepick) and integrates with world time and task scheduling to support dynamic regrowth behavior.
Dependencies & Tags
- Tags managed:
pickable,barren,quickpick,jostlepick - Tag removal on component removal: All four tags (
pickable,barren,quickpick,jostlepick) are removed when the component is removed from the entity. - Common external component interactions:
burnable(used inFertilizeto stop smoldering)lootdropper(used inSpawnProductLoot)witherable(used inFertilize,OnSave,OnLoad, andMakeEmpty)
- No internal
inst:AddComponent(...)calls, but relies on presence of optional components during runtime.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
canbepicked | boolean? | nil | Indicates if the object can currently be picked. Changed via Regen() and MakeEmpty()/Pick(). |
regentime | number? | nil | Current regrowth duration (may be modified by SpringGrowthMod). |
baseregentime | number? | nil | Base regrowth duration (original, unmodified). |
product | string? | nil | Prefab name of the item dropped upon picking. |
onregenfn | function? | nil | Callback invoked when regrowth completes (Regen()). |
onpickedfn | function? | nil | Callback invoked after picking (Pick()). |
makeemptyfn | function? | nil | Callback invoked when making empty (start of regrowth). |
makefullfn | function? | nil | Callback invoked when regenerating ( Becomes canbepicked). |
cycles_left | number? | nil | Remaining harvest cycles for transplanted plants. |
max_cycles | number? | nil | Maximum harvest cycles for transplanted plants. |
transplanted | boolean | false | True if the object has been transplanted (and consumes cycles on harvest). |
caninteractwith | boolean | true | Controls whether the entity is currently interactable. |
numtoharvest | number | 1 | Number of items produced per harvest. |
quickpick | boolean | false | If true, adds quickpick tag to the entity. |
jostlepick | boolean | false | If true, adds jostlepick tag to the entity. |
wildfirestarter | boolean | false | Controls whether the object is a wildfire starter (also true if entity has withered tag). |
dropped | boolean? | nil | Indicates if loot should be dropped via lootdropper. |
dropheight | number? | nil | Vertical offset for looting drop position. |
paused | boolean | false | Whether the regrowth timer is paused. |
pause_time | number? | nil | Remaining time when paused (pre-calculation). |
targettime | number? | nil | Absolute world time when regrowth should complete. |
protected_cycles | number? | nil | Number of cycles preserved during withering (e.g., via fertilization). |
task | DoTaskInTime? | nil | Scheduled regrowth task. |
useexternaltimer | boolean | false | If true, uses external functions (startregentimer, getregentimertime, etc.) instead of internal tasks. |
Main Functions
Pickable:SetUp(product, regen, number)
- Description: Initializes core properties for a fully grown, immediately harvestable item. Sets
canbepickedtotrue. - Parameters:
product(string): Prefab name of the item produced on harvest.regen(number): Base regrowth time (in seconds).number(number?, optional): Number of items to produce per harvest. Defaults to1.
Pickable:CanBePicked()
- Description: Returns whether the object can currently be picked.
- Returns:
boolean: True ifcanbepickedis true.
Pickable:Pick(picker)
- Description: Handles the harvesting of the item. Decrements cycles (if transplanted), spawns loot, triggers callbacks, and schedules regrowth. Fires
"picked"event. - Parameters:
picker(Entity?): The entity doing the harvesting (may benilorTheWorld).
Pickable:Regen()
- Description: Marks the object as ready to pick (
canbepicked = true), cancels any pending regrowth task, and callsmakefullfnandonregenfncallbacks. - No parameters.
Pickable:MakeEmpty()
- Description: Initiates regrowth by setting
canbepicked = false, callingmakeemptyfn, and scheduling a regrowth task (ifbaseregentimeis set and not paused). - No parameters.
Pickable:MakeBarren()
- Description: Permanently disables regrowth by setting
cycles_left = 0andcanbepicked = false. Cancels any pending task. Callsmakebarrenfnif present. - No parameters.
Pickable:Fertilize(fertilizer, doer)
- Description: Restores or extends harvest cycles (especially for withered plants), cancels withering, and calls
MakeEmpty(). - Parameters:
fertilizer(Entity): The fertilizer entity used (accessed forfertilizer.components.fertilizer.withered_cycles).doer(Entity?): The entity applying fertilizer (used for sound playback).
Pickable:OnTransplant()
- Description: Marks the object as transplanted and calls
ontransplantfnif defined. Typically invoked on player transplant actions. - No parameters.
Pickable:LongUpdate(dt)
- Description: Updates regrowth progress using world time delta. Handles rescheduling and immediate regrowth if timer expires. Respects
useexternaltimermode. - Parameters:
dt(number): Delta time (time since last update).
Pickable:FinishGrowing()
- Description: Immediately finishes regrowth if the object is not yet ready (
canbepickedis false). Cancels any pending task and callsRegen(). - Returns:
boolean:trueif regrowth was completed during this call.
Pickable:Pause() / Pickable:Resume()
- Description: Pauses or resumes regrowth timing logic. Respects both internal (
task-based) and external timer modes. - Parameters: None for either method.
Pickable:IsWildfireStarter()
- Description: Returns whether the object is a wildfire starter.
- Returns:
boolean: True ifwildfirestarteristrueor the entity has thewitheredtag.
Pickable:IsBarren()
- Description: Checks if the object is barren (regrowth cycles exhausted).
- Returns:
boolean: True ifcycles_left == 0.
Pickable:SpawnProductLoot(picker)
- Description: Spawns the product item(s) on the ground or into the picker’s inventory, respecting
numtoharvest,dropped, anduse_lootdropper_for_productflags. - Parameters:
picker(Entity?): The entity harvesting (used for inventory placement or event firing).
Pickable:ConsumeCycles(cycles)
- Description: Manually decrements
cycles_left(if transplanted) andprotected_cycles. - Parameters:
cycles(number): Number of cycles to consume.
Pickable:SetStuck(stuck)
- Description: Sets or clears the
stuckstate. Prevents picking if true. - Parameters:
stuck(boolean): New stuck state.
Pickable:IsStuck()
- Description: Returns whether the object is stuck and unpickable.
- Returns:
boolean.
Pickable:GetDebugString()
- Description: Returns a debug string summarizing internal state (e.g., paused, regen time remaining, cycles).
- Returns:
string.
Pickable:OnSave() / Pickable:OnLoad(data)
- Description: Serialize/deserialize full state for persistence. Supports saving/restoring
cycles, regrowth timers, paused state, protection, and transplanted status. - Parameters:
data(table): State data to load (forOnLoad).
Events & Listeners
- Events listened to (via
inst:ListenForEventimplied by property setters in Class()):canbepickedcaninteractwithcycles_leftquickpickjostlepick
- Events triggered (via
inst:PushEvent):"picked"with payload{ picker = ..., loot = ..., plant = ... }"picksomething"(inSpawnProductLoot) with payload{ object = self.inst, loot = ... }when inventory is involved.
- Timer events (handled internally via
DoTaskInTime):OnRegen— triggersRegen()when scheduled timer completes.