Hunger, sleep and death
Sleep by the clock
NPCSleepHelper.isSleepPeriod answers whether this NPC's sleep window is open:
Float hour = currentHour(world);
if (hour == null) return false;
boolean night = hour < DAY_START_HOUR || hour >= NIGHT_START_HOUR;
return isNightWatch(npc) ? !night : night;
The night boundary reuses the same split InteractionManager already used for night-time greetings,
so dialogue and routine never disagree about the time.
When the time resource cannot be read, it returns false — degrading to exhaustion-only behaviour
rather than trapping the village in bed.
Guards (Profession.GUARD) run the inverted shift. Their energy drains and refills normally, just
on the opposite schedule, which is why no special rule for zero energy was needed.
Food classification
Map<InteractionType, String> interactions = item.getInteractions();
String id = interactions.get(InteractionType.Secondary);
// Root_Secondary_Consume_Food_T1..T3
The tier arrives free as a raw-versus-cooked signal: raw meat, ingredients and crops inherit T1 from their templates; anything cooked declares T2 or T3.
scoreFor ranks tier → taste → distance. Tier dominates deliberately: a hated pie beats a
beloved slab of raw beef, which is the behaviour a village sim wants.
Thresholds and pacing
| Hunger | Behaviour |
|---|---|
< 70 | Idle NPCs start FINDING_FOOD (RoutineSleepHelpers.handleIdle) |
< 25 | Any NPC drops its task and goes to eat (RoutineAISystem interrupt) |
<= 5 | tickStarvation keeps it IDLE, sad and crying |
From 100, the first search happens after roughly 4h10, and the interrupt after ~10h25. Both values
scale with hungerDecayMultiplier in simtale-config.json (1.0 = original pacing, 10.0 ≈
25 minutes to the first search, 0 = frozen).
Where food comes from
NPCHungerHelper scans ChestRegistry.CHESTS within 24 blocks and keeps only chests
HouseManager.canOpenChest allows:
- a private chest owned by the NPC's house;
- an explicitly shared chest (
/simtale chestshare); - a village-global chest: inside a village, owned by no house.
The last rule is derived live by ChestRegistry.isVillageGlobal; it is not persisted. Move the chest
into a house and it becomes private again. This is also how homeless NPCs (guards, miners) get food.
getInteractions() returns Map<InteractionType, String>, not Map<String, String>. Using
get("Secondary") compiles and classifies every item as inedible.
Starvation
Hunger is not lethal, by design. Aging and disease will own death; a third cause competing with them would make all three harder to reason about.
NPCHungerHelper.tickStarvation breaks a starving NPC out of whatever it was doing, sets SAD and
plays the crying animation. What it costs the NPC is its usefulness, not its life — job, hobby and
social life stop until someone feeds it.
Three families of task are excluded from the interruption:
| Excluded | Why |
|---|---|
FINDING_FOOD, MOVING_TO_FOOD, EATING | Otherwise it finds a chest and is pulled back to IDLE before reaching it |
| The five sleep tasks | Yanking a sleeping NPC to IDLE leaves the sleeping flag orphaned |
DYING, DEAD, REAPING | Dying is not a task to interrupt |
The DYING → DEAD → REAPING flow is fully wired to the engine's health system. Whenever an NPC reaches 0 HP — through combat, fall damage, or /simtale forcekill — RoutineAISystem intercepts it and routes it into the death flow, rather than leaving a broken, not-quite-dead entity wandering around.
Earlier versions of this page documented a Needs.starvationDamage counter that killed at 200
accumulated damage. Needs.java was removed in the migration to native EntityStats, and the
leftover hunger <= 0 → DYING trigger — which killed instantly, the opposite of the intent — went
with it, along with the now-unreferenced STARVATION_DAMAGE, STARVATION_INTERVAL_TICKS and
LETHAL_STARVATION_DAMAGE.
Feeding by hand
InteractionManager.tryFeed runs before the normal gift rules. At 70 hunger or below, edible gifts
are eaten on the spot: hunger and health restored by tier, larger affinity gain.
It uses the same NPCFoodHelper as the chest routine, so a player cannot force-feed something the
NPC would refuse on her own.
Persistence
Needs live in the entity's EntityStatMap, but SimTale keeps its own snapshot in
SimNPCData.needs and writes it on every saveNPC. On load, NeedsHelper.restoreSavedNeeds applies
the snapshot only when all five live needs are still at the asset default (100) — the signature of
a stat map the engine reset. If the engine restored real values, those win instead of being rolled
back to an older JSON snapshot.
This also covers the detached-component paths (commands and lifecycle helpers) that save without a
live entityRef: they reuse the snapshot already loaded rather than writing 100 over it.
Forced feeding
/simtale forceeat zeroes hunger, backdates the search cooldown so the chest scan runs immediately,
and keeps forcedByDebug set while the NPC is in FINDING_FOOD / MOVING_TO_FOOD / EATING.
That is what prevents the night sleep interrupt from pulling her into bed before she reaches the
chest.
Constants
See Balancing for the full table.