Beefalobrain
Based on game build 7140014 | Last updated: 2026-03-03
Overview
BeefaloBrain is a behavior tree (BT) implementation that defines the decision-making logic for beefalo entities in DST. It orchestrates high-priority responses (e.g., panic, combat), interaction states (greeting feeders with a bell, loitering), and movement behaviors (wandering, following). It interacts heavily with components like domesticatable, follower, hitchable, knownlocations, rideable, and writeable, using helper functions to determine target positions, states, and priority actions.
Usage example
-- Typically added automatically to beefalo prefabs
local inst = CreateEntity()
inst:AddComponent("brain")
inst.components.brain:SetBrain("beefalobrain")
-- No direct manual interaction needed; the game engine handles activation
Dependencies & tags
Components used: combat, domesticatable, follower, hitchable, inventory, inventoryitem, knownlocations, rideable, writeable
Tags: Checks hitched, notarget, playerghost, bell, pocketdimension_container; uses ACTIONS.HITCH
Properties
No public properties. All state and data are managed internally via local constants, component properties, and closure-scoped variables.
Main functions
OnStart()
- Description: Initializes the behavior tree root node with a priority-based hierarchical task network for beefalo AI. It constructs a complex
PriorityNodewith sub-trees for panic responses, combat, naming, hitching, following, greeting, loitering, wandering, and saltlick anchoring. - Parameters: None.
- Returns: Nothing.
- Error states: None — assumes all required components exist or are properly guarded by
IfNode/WhileNodeconditions.
GetFaceTargetFn(inst)
- Description: Determines a target for the beefalo to face (e.g., a nearby player). Returns
nilif the beefalo is domesticated or seeking salt, or if no valid player is within range and not taggednotarget. - Parameters:
inst(entity instance) — the beefalo entity. - Returns:
entity?— closest player withinSTART_FACE_DIST, ornil. - Error states: Returns
nilif the player is ghosted or hasnotarget.
KeepFaceTargetFn(inst, target)
- Description: Continues facing a target only if both entities are valid, within
KEEP_FACE_DIST, not domesticated/seeking salt, and the target is neither a ghost nor taggednotarget. - Parameters:
inst(entity) — the beefalo.target(entity) — current facing target.
- Returns:
boolean—trueif continue facing, elsefalse. - Error states: Returns
falseif either entity is invalid or out of range.
GetGreetTarget(inst)
- Description: Finds the target the beefalo should greet — either its Beef Bell owner (if bell is nearby) or the closest player on land within
GREET_SEARCH_RADIUS. - Parameters:
inst(entity). - Returns:
entity?— bell owner or closest player, ornil. - Error states: Returns
nilif no bell or player is within search radius.
GetLoiterAnchor(inst)
- Description: Maintains and updates the loiter anchor position using
knownlocations. Resets it if too far from the current anchor (LOITER_ANCHOR_RESET_DIST), or if herd location is nearby, updates anchor to herd position. - Parameters:
inst(entity). - Returns:
vec3?— stored anchor position fromknownlocations. - Error states: None — ensures anchor is always present.
ShouldWaitForHeavyLifter(inst, target)
- Description: Determines if the beefalo should pause to wait for a heavy-lifting entity approaching it (e.g., a player carrying a large item).
- Parameters:
inst(entity) — the beefalo.target(entity) — potential target (e.g., player holding item).
- Returns:
boolean—trueif target is heavy lifting and moving toward the beefalo. - Error states: Returns
falseif target is invalid, not heavy lifting, or not moving in the right direction.
InState(inst, state)
- Description: Helper to determine if the beefalo is currently in a given state (
GREETING,LOITERING, orWANDERING) by comparing elapsed time since_startgreettime. - Parameters:
inst(entity).state(string) — one of"greeting","loitering","wandering".
- Returns:
boolean— whether current state matches expected state. - Error states: If
_startgreettimeisnil, initializes it to a large negative value to forceWANDERINGinitially.
TryBeginGreetingState(inst)
- Description: Begins greeting state if domestication level > 0 and a greet target exists; sets
_startgreettime. - Parameters:
inst(entity). - Returns:
boolean—trueif greeting started, elsefalse. - Error states: Returns
falseif in mood or no valid greet target.
TryBeginLoiterState(inst)
- Description: Transitions from greeting to loitering state if greeting duration has elapsed or is still active; resets timer if loitering prematurely.
- Parameters:
inst(entity). - Returns:
boolean—trueif loitering should start or timer reset,falseif still in mood. - Error states: Returns
falseif in mood; resets timer to avoid loiter state exit.
Events & listeners
- Listens to:
newcombattarget— stops listening viaRemoveEventCallbackwhen unhitching (handled inHitchable:Unhitch, not directly in this file). - Pushes: None — this brain does not emit events itself. Actions (
Follow,Wander, etc.) may fire their own callbacks internally.