Farmplantable
Based on game build 714014 | Last updated: 2026-03-03
Overview
Farmplantable allows an entity (typically a seed) to be planted onto a valid soil target. It handles the logic of removing the seed, spawning the target plant prefab, positioning it correctly, and notifying the game of the planting action through events. The component is self-contained and does not rely on any other components internally.
Usage example
local inst = CreateEntity()
inst:AddComponent("farmplantable")
inst.components.farmplantable.plant = "corn"
-- Later, when planting:
local success = inst.components.farmplantable:Plant(soil_entity, planter)
Dependencies & tags
Components used: None identified
Tags: None identified
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
plant | string or function | nil | The prefab name (string) or a function that returns a prefab name, used to spawn the planted entity. Set externally after construction. |
Main functions
Plant(target, planter)
- Description: Attempts to plant the seed onto the given target entity. The target must have the
soiltag; if successful, the seed is removed and a new plant prefab is spawned and positioned at the soil's location. - Parameters:
target(Entity) — the soil entity to plant on. Must have thesoiltag.planter(Entity) — the entity performing the planting action (e.g., a player or tool).
- Returns:
boolean—trueif planting succeeded,falseotherwise (e.g.,plantisnil, target lackssoiltag, orplant_prefabresolves tonil). - Error states:
Returnsfalseifself.plantisnil, if the target does not have thesoiltag, or if the resolvedplant_prefabisnil.
Events & listeners
- Listens to: None
- Pushes:
"on_planted"on the spawned plant instance — passes{ doer = planter, seed = self.inst, in_soil = true }."itemplanted"onTheWorld— passes{ doer = planter, pos = pt }at the planting location.