Tree Rocks
Based on game build 714014 | Last updated: 2026-03-07
Overview
The tree_rocks.lua file defines prefabs for rock trees (tree_rock1, tree_rock2, and variants), which function as environmental structures that can be chopped, mined, fall over, and regenerate. These prefabs incorporate multiple components: lootdropper (for drop generation), workable (for chopping and mining actions), growable (for growth stages), plantregrowth (for regrowth after falling), and burnable (for fire interaction). They also support area-of-effect knockback and damage on impact, interact with nearby Leif entities via the sleeper component, and generate custom vine loot based on world topology. The tree_rock_seed can plant a new tree, which then grows through stages from short to normal height.
Usage example
Rock trees are typically instantiated via the returned prefabs (tree_rock1, tree_rock2, etc.) rather than direct component manipulation. However, a minimal example of adding and configuring a rock tree manually would be:
local tree = SpawnPrefab("tree_rock1")
tree.Transform:SetPosition(x, y, z)
tree.components.lootdropper:SetChanceLootTable("tree_rock1_chop")
tree.components.workable:SetWorkLeft(TUNING.TREE_ROCK.CHOP)
tree.components.growable:SetStage(2)
Dependencies & tags
Components used: lootdropper, workable, growable, plantregrowth, burnable, propagator, sleeper, combat, inventory, hauntable, inspectable, soundemitter, animator, minimapentity, transform, network.
Tags added/checked: tree, rock_tree, shelter, nodangermusic, boulder, burnt, tree_rock_breaker, tree_rock_bouncer. Also uses leif for wake-up logic.
Properties
No public properties are defined in the constructor or elsewhere — this file is primarily a prefab factory and contains no component class definition. All runtime state is stored on the inst object (e.g., inst.build, inst.anims, inst.vine_loot) but not exposed as component properties.
Main functions
MakeRockTree(name, build, stage)
- Description: Factory function that returns a
Prefabfor a rock tree (e.g.,tree_rock1). It initializes all required components (lootdropper, workable, growable, plantregrowth, burnable, etc.), sets animations and loot tables, and registers save/load callbacks. - Parameters:
name(string) – prefab name (e.g.,"tree_rock1").build(string, optional) – key from thebuildstable ("rock1"or"rock2"), determining growth and AOE stats.stage(number, optional) – initialgrowablestage (1= short,2= normal).
- Returns: A
Prefabinstance. - Error states: None documented.
MakeRock(inst, no_change_physics)
- Description: Transforms the entity from a standing rock tree into a boulder after falling or burning. Removes burnable, propagator, workable (chopping), and shelter components; adds a new
workablefor mining; adjusts physics to obstacle type; and sets loot table to"tree_rock1_mine". - Parameters:
inst(Entity) – the rock tree instance to convert.no_change_physics(boolean) – iftrue, skips physics collider removal/replacement.
- Returns: Nothing.
OnChop(inst, chopper, chopsleft, numchops)
- Description: Callback invoked each time the tree is chopped. Plays chop animation and sound, spawns
tree_rock_chopFX, and wakes nearbyleifentities viasleeper.WakeUp. Also suggestschopperas a target to leifs'combatcomponent. - Parameters:
inst(Entity) – the rock tree instance.chopper(Entity, optional) – the entity doing the chopping.chopsleft(number) – remaining chops before falling.numchops(number) – total chops required (fromTUNING.TREE_ROCK.CHOP).
- Returns: Nothing.
OnChopDown(inst, chopper)
- Description: Callback invoked after the final chop. Triggers the fall animation sequence (
fall_pre), drops loot and vine loot, and callsMakeRock(inst, true)to transition to boulder state. - Parameters:
inst(Entity) – the rock tree instance.chopper(Entity, optional) – the entity that finished chopping.
- Returns: Nothing.
OnBurnt(inst, immediate)
- Description: Handles conversion to burnt state. If
immediateistrue(e.g., on load), it instantly converts to a boulder with appropriate mining animation. Otherwise, it plays afall_pre_burntanimation and transitions after a delay. - Parameters:
inst(Entity) – the rock tree instance.immediate(boolean) – iftrue, skips fall animation.
- Returns: Nothing.
OnMine(inst, miner, minesleft, nummines)
- Description: Callback for mining (boulder state). When
minesleft <= 0, spawns rock break FX, drops loot, and removes the entity. Otherwise, plays animation and triggers spooked FX for players withspookedcomponent. - Parameters:
inst(Entity) – the rock tree instance.miner(Entity, optional) – the mining entity.minesleft(number) – remaining mine actions before destruction.nummines(number) – total mine actions required.
- Returns: Nothing.
SetupVineLoot(inst, loots)
- Description: Initializes vine loot (gems, resources) on the tree based on world topology (
GetLootWeightedTable). UpdatesAnimStateto show or hide gem vines and override symbols. - Parameters:
inst(Entity) – the rock tree instance.loots(table, optional) – precomputed loot list (usesGetVineLoots(inst)if omitted).
- Returns: Nothing.
GetLootWeightedTable(inst)
- Description: Determines the weighted loot table using the rock tree’s position, queried against world topology (
TheWorld.Map:GetTopologyIDAtPoint). Falls back toWEIGHTED_VINE_LOOT.DEFAULTif no match. - Parameters:
inst(Entity) – the rock tree instance. - Returns: table – weighted loot table (e.g.,
WEIGHTED_VINE_LOOT.vent_proximity). - Error states: Returns
WEIGHTED_VINE_LOOT.DEFAULTif topology lookup fails.
GetAffectedEntities(inst)
- Description: Finds entities within the tree’s
drop_damage_rangethat are valid targets for knockback/damage. Filters by required and forbidden tags (_combatmust be present;INLIMBO,flight,invisible, etc. are forbidden). - Parameters:
inst(Entity) – the rock tree instance. - Returns: table – array of valid entities within range.
Events & listeners
- Listens to:
animover(viainst:ListenForEvent("animover", OnAnimOver)) – triggers fall/bounce/break logic and animation chaining.death(handled byburnablecomponent) – cancels burn task when killed.
- Pushes:
onextinguish– triggered on fire extinguish (viaburnable).onwakeup– triggered on leif wake-up (viasleeper).on_loot_dropped,loot_prefab_spawned,broke_tree_rock,knockback– triggered during interaction and falling.- Entity-level events:
onload,onsave– viainst.OnLoad/inst.OnSave.