TreeSpawner
A class in Root.Township, Alta.Woodcutting.
Server entity that keeps one tree growing at its spot. When the tree is felled it waits a random time and spawns a new random preset of the allowed species and sizes.
- Listed in Crafting and making
- Inherits or implements
NetworkEntityBehaviour,ISavable<TreeSpawnerSaveData>,ISavableSave<TreeSpawnerSaveData>,ISavableSaveBase - Derived types
TreeSpawnerSaveData - Documented in Farming, woodcutting and carpentry
Constructors
| Member | What it is |
|---|---|
TreeSpawner() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
9 private and internal fields
| Member | What it is |
|---|---|
private float maximumRespawn | Longest respawn wait in seconds. |
private float minimumRespawn | Shortest respawn wait in seconds. |
private TreeSize[] sizes | Tree sizes this spawner may pick. |
private TreeSpecies[] species | Tree species this spawner may pick. |
private WoodcutTree tree | The current tree, or null while waiting. |
private AltaEvent treeAdded | Event fired when a tree is spawned or adopted. |
private NetworkPrefab treePrefab | The network prefab the tree is built on. |
private AltaEvent treeRemoved | Event fired when the tree is felled. |
private Timeline.IEntry waitToRespawn | The pending respawn timeline entry. |
Methods
| Member | What it is |
|---|---|
override void InitializeAsServer(SpawnData spawnData) | Adopts an existing child tree (destroying duplicates), or spawns a new one once the entity is in a chunk. |
void Spawn(PresetTree preset) | Spawns a tree from a preset with one of the allowed species. Starts the wait instead if none fits. |
void SpawnRandom() | Spawns a random preset matching the allowed sizes and species. |
7 private and internal methods
| Member | What it is |
|---|---|
private void BaseSplit(DamageData hit) | Treats the tree as gone when its base is killed. |
private void CheckBaseCut(WoodcutTree tree) | When a cut leaves the tree with no root, destroys the tree and starts the respawn wait. |
private void InitializeTree() | Fires treeAdded and watches the tree for cuts and death. |
private void OnDestroy() | Cancels the respawn timer. |
private void SpawnOnChunkLoad(Chunk chunk) | Spawns a tree once the entity joins a chunk. |
private void StartWait() | Schedules SpawnRandom after a random time between the minimum and maximum respawn. Saved with the spawner. |
private void TreeDestroyed() | Unhooks the old tree, fires treeRemoved and starts the respawn wait. |