Skip to main content

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.

Constructors​

MemberWhat it is
TreeSpawner()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

9 private and internal fields
MemberWhat it is
private float maximumRespawnLongest respawn wait in seconds.
private float minimumRespawnShortest respawn wait in seconds.
private TreeSize[] sizesTree sizes this spawner may pick.
private TreeSpecies[] speciesTree species this spawner may pick.
private WoodcutTree treeThe current tree, or null while waiting.
private AltaEvent treeAddedEvent fired when a tree is spawned or adopted.
private NetworkPrefab treePrefabThe network prefab the tree is built on.
private AltaEvent treeRemovedEvent fired when the tree is felled.
private Timeline.IEntry waitToRespawnThe pending respawn timeline entry.

Methods​

MemberWhat 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
MemberWhat 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.