Farmplanttendable
Overview
This component determines if a farm plant entity is currently tendable. It manages the tendable state and dynamically adds or removes the "tendable_farmplant" tag from the entity based on that state. It also supports tend operations via the TendTo method, which can mark the plant as no longer tendable upon successful tend.
Dependencies & Tags
- Adds/removes tag:
"tendable_farmplant" - No other components required or added.
- Uses optional function reference
ontendtofn(not initialized here—expected to be set externally, e.g., by the farm plant entity or its parent logic).
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
tendable | boolean | true | Whether the plant is currently tendable. State is persisted via OnSave/OnLoad. |
Main Functions
SetTendable(tendable)
- Description: Sets the
tendablestate and updates the"tendable_farmplant"tag accordingly. - Parameters:
tendable(boolean) – The desired tendability state.
TendTo(doer)
- Description: Attempts to tend to the plant. If
tendableistrueand the optionalontendtofncallback returnstrue, setstendabletofalseand returnstrue. Otherwise, returnsnil. - Parameters:
doer(Entity) – The entity performing the tend action (e.g., the player).
OnSave()
- Description: Returns a serializable table containing the current
tendablestate for save/load persistence. - Returns:
table–{ tendable = self.tendable }.
OnLoad(data)
- Description: Restores the
tendablestate from saved data (if provided). - Parameters:
data(table?) – Optional saved data table, expected to contain atendablekey.
Events & Listeners
- Listens to changes in the
tendableproperty via the internalontendablefunction (used as a setter hook in the class metatable), which triggers tag updates whentendableis assigned. - Does not actively listen for or push events via
inst:ListenForEventorinst:PushEvent.