Pollinator
Overview
This component enables an entity to collect nearby flowers, store them, and spawn a new flower at its location once sufficient pollination has occurred. It enforces distance- and density-based constraints to regulate flower spawning, ensuring ecological balance in the world.
Dependencies & Tags
- Adds the tag
"pollinator"to the entity on construction. - Removes the
"pollinator"tag when the component is removed from the entity. - Relies on external functionality:
TheSim:FindEntities,SpawnPrefab,GetRandomItem, and entity properties such asIsOnValidGroundandTransform.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | nil | Reference to the entity the component is attached to. |
flowers | table | {} | List of flower prefabs collected by the pollinator. |
distance | number | 5 | Radius (in world units) used when checking flower density around the entity. |
maxdensity | number | 4 | Maximum number of nearby flowers allowed for density checks. |
collectcount | number | 5 | Minimum number of collected flowers required to trigger flower spawning. |
target | Entity? | nil | Reference to a currently targeted flower; reset to nil on pollination. |
Main Functions
Pollinate(flower)
- Description: Adds a valid flower to the internal
flowerscollection and clears thetargetfield. - Parameters:
flower(Entity): The flower entity to collect. Must pass theCanPollinatecheck.
CanPollinate(flower)
- Description: Validates whether a given entity can be collected as a flower.
- Parameters:
flower(Entity?): The entity to validate. Must be non-nil, tagged"flower", and not already inself.flowers.
HasCollectedEnough()
- Description: Checks if the number of collected flowers exceeds
collectcount. - Returns:
boolean—trueif more thancollectcountflowers are stored.
CreateFlower()
- Description: Spawns a new flower at the pollinator’s current position if sufficient flowers have been collected and the entity stands on valid ground. The internal
flowerslist is cleared after spawning. - Notes: Uses random selection from the stored flower prefabs; spawns with
planted = true.
CheckFlowerDensity()
- Description: Determines whether the pollinator’s surrounding area has fewer than
maxdensityflowers withindistanceunits. Used to prevent excessive local flower density. - Returns:
boolean—trueif density is acceptable for spawning. - Implementation Details: Uses
TheSim:FindEntitieswith a fixed set ofFLOWERDENSITY_ONEOF_TAGS({"FX", "NOBLOCK", "INLIMBO", "DECOR"}).
GetDebugString()
- Description: Returns a human-readable debug string summarizing current pollinator state.
- Returns:
string— e.g.,"flowers: 3, cancreate: false".
Events & Listeners
None identified.