Skip to main content

RoutineAISystem

The autonomy engine. One tick per NPC, three phases.

RoutineAISystem (tick per NPC)
├── Evaluation — self-heal stuck flags, then sleep/hunger interrupts
├── Decision — pick the task
└── Action — delegate to a helper
├── NPCHungerHelper → FINDING_FOOD, MOVING_TO_FOOD, EATING
├── NPCWorkHelper → MOVING_TO_WORK, FARMING, HUNTING, FISHING, CHOPPING, EXPEDITION, PLANTING, MOVING_TO_DEPOSIT, MOVING_TO_SEEDS
├── NPCSocialHelper → MOVING_TO_SOCIALIZE, SOCIALIZING, WANDERING
├── NPCLeisureHelper → FINDING_LEISURE, MOVING_TO_LEISURE, DOING_HOBBY
└── (inline) → FINDING_BATH, MOVING_TO_BATH, BATHING, FINDING_CONSTRUCTION, MOVING_TO_CONSTRUCTION, BUILDING

Query: SimTale.SIM_NPC_COMPONENT_TYPE.

Interrupts​

Two conditions can drop whatever the NPC is doing.

Sleep​

boolean sleepWindowOpen = NPCSleepHelper.isSleepPeriod(npc, world);
boolean exhausted = NeedsHelper.getNeed(store, npc.entityRef, NeedsHelper.ENERGY_ID) < sleepThreshold;

if ((sleepWindowOpen || exhausted)
&& world.getTick() >= ai.nextBedSearchTick
&& !alreadyHeadedToBed && !inDeathFlow) { ... }

sleepingOnSchedule records why she went to bed, because the two cases wake differently: scheduled sleepers stay down until the window closes; naps end when energy fills.

Hunger​

Same shape, threshold 25, guarded by nextFoodSearchTick.

Sleep is evaluated first and also excludes NPCs already in a bed task. Normal hunger therefore does not fight the night schedule: a hungry NPC goes to bed and eats after waking. /simtale forceeat is the exception — forcedByDebug survives for the whole feeding chain (FINDING_FOOD/MOVING_TO_FOOD/EATING), so the sleep interrupt cannot pull her away mid-walk. Every other forced debug task still clears the flag on the next tick.

Three guards every interrupt (and heavy search) needs​

GuardWithout it
Not already in that task chainRestarts the task every tick
nextXSearchTick cooldownSearch storm when the target is unreachable — 3447/sec observed
!inDeathFlowYanks the NPC out of DYING; the death broadcast repeats forever

(Note: Bath and Leisure searches also rely on the nextXSearchTick cooldown to prevent search storms, even though they are routed from IDLE instead of being global interrupts.)

Movement​

Movement uses a leash point, updated with throttling via lastLeashPos and lastLeashTick.

Copy every field in clone()

Those two fields were once missing from RoutineAIComponent.clone(). Every component replacement reset them to null, navigation stopped updating, and NPCs froze mid-walk. No error, no log.

Sleeping​

  1. Resolve the bed anchor with FurnitureAnchorHelper.anchorOf
  2. BlockMountAPI.mountOnBlock — sets position and rotation synchronously
  3. setSleepingState plus the animation is the pose
  4. pinLeashAt at the resulting position

There is no manual teleport. Every attempt to position the body by hand made it worse; the mount API already does it, provided it is given the anchor.