Skip to content

Commit 26fbca8

Browse files
authored
Merge pull request #58 from xefensor/fix/ai-behavior-stability
Improve mob combat and movement AI
2 parents 45da50a + dd5610e commit 26fbca8

54 files changed

Lines changed: 5315 additions & 263 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 18 additions & 4 deletions
Large diffs are not rendered by default.

docs/compatibility.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ false so Retold's defaults and entries from other compatibility packs remain ava
126126

127127
## Faction Entity Tags
128128

129+
`retold:shared_defense_species` is an additive exact-species defense tag. When a tagged entity takes
130+
real health damage, nearby adult entities of that same type may protect it if they hear the call at
131+
close range or see the attacker. Retold defaults this tag to Wolves and Polar Bears. Tamed tagged
132+
animals cooperate only when both are tame with the same owner; sitting allies remain unavailable.
133+
Adding an entity type means its ordinary adult mobs can acquire and pursue attackers, so passive
134+
species that should flee together rather than fight must not be included.
135+
129136
Compatibility datapacks can classify an entity type into one Retold faction by appending it to one
130137
of these tags:
131138

@@ -149,11 +156,20 @@ of these tags:
149156
| `retold:factions/enders` | Ender faction relationships. |
150157
| `retold:alliances/illager_loose_allies` | Permanent non-hostile Illager alignment with combat cooperation only while both entities share the same active raid. This does not grant Illager territory membership. |
151158

152-
Faction describes diplomacy, target selection, assistance, retaliation, and configured territory
153-
membership. It does not assign a Retold mob profile or take over the entity's daily-life AI. A
159+
Faction describes diplomacy, target selection, retaliation, configured territory membership, and
160+
shared defense for explicitly cooperative factions. Broad Undead, Enders, Guardians, and other
161+
specialist identities retain their narrower species, stage, or encounter owners instead of gaining
162+
generic faction-wide defense. Faction membership does not assign a Retold mob profile or take over
163+
the entity's daily-life AI. A
154164
compatibility pack may therefore classify a third-party mob without opting it into hunger,
155165
foraging, homes, or another profile. Unknown and untagged entity types remain unfactioned.
156166

167+
Target distance remains bounded even when a compatibility pack adds a faction identity. Mobs with
168+
a Retold profile use that profile's acquisition and retention limits. Unknown or unprofiled mobs
169+
fall back to their declared `FOLLOW_RANGE`, clamped to 12–48 blocks for acquisition and at most
170+
64 blocks for retention. A compatibility addon that needs a deliberate longer-range specialist
171+
should provide a Retold profile or a narrow code integration rather than inflating faction scans.
172+
157173
Add an entity type exactly as for the block example, using the entity-type path. For example, this
158174
classifies `examplemod:ashen_guard` as an Undead entity:
159175

docs/internal/design_implementation_status.md

Lines changed: 10 additions & 3 deletions
Large diffs are not rendered by default.

docs/internal/mob_ai_handoff_prompt.md

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ Current position:
3535
Guardians. Explicit Retold-owned retaliation remains available at this generic boundary. The
3636
focused relationship selector passes; latest exact Cube Mob and Guardian-family TPS peaks are
3737
4.488, 5.665, 4.580, and 5.040 ms/tick respectively.
38+
- `RetoldTargetRangePolicy` now applies species/profile-aware acquisition and retention ceilings to
39+
raw Mob targets, Brain memories, Retold-owned combat, faction scans, and relayed assistance.
40+
Ordinary acquisition is 12–24 blocks; Stage 1/2 Zombies use 12/18 and Skeletons 14/22, urgent
41+
defense receives a bounded retention margin, and genuine long-range specialists retain explicit
42+
exceptions. Unknown modded mobs use clamped `FOLLOW_RANGE`. The exact boundary and focused
43+
adjacent behavior regressions pass; natural mixed combat, multiplayer, and dedicated servers
44+
remain unverified.
3845
- There are 82 data-driven mob profiles. Zombie Nautilus is the newest unmanaged
3946
`SPECIAL_VANILLA` profile; Skeleton Horse, Zombie Horse, and Camel Husk are the newest
4047
`UNDEAD_MOUNT` profiles.
@@ -56,6 +63,14 @@ Current position:
5663
close-range fake-Flint-and-Steel path for Nitwits.
5764
Every completed Retold feed now stops the mob for two seconds and
5865
turns it toward the remembered food position, with urgent ownership able to interrupt.
66+
- Shared urgent flight now keeps aligned eight-tick refreshes in a straight escape corridor without
67+
fresh lateral randomness, adopts matching active paths, and updates their speed without rebuilding
68+
them. A genuinely rejected direct dry route can try at most two deterministic side detours; work
69+
deferral remains neutral. Ordinary prey, wounded predators, Creeper awareness, and Cat retreat
70+
clear the shared destination memory when their reaction ends, while water validation and the
71+
existing 40-tick stuck recovery remain authoritative. Both exact route regressions and
72+
representative Cow/Wolf/Salmon/Cat TPS runs pass with a 6.472 ms/tick peak, but natural obstacle,
73+
crowd, and circling-attacker behavior still needs developer verification.
5974
- `animal_feeder` is a one-slot wooden trough crafted from five planks. Right-click with compatible
6075
food inserts one item; sneak-right-click with compatible food inserts as much of the held stack
6176
as fits; sneak-right-click with an empty hand or incompatible item retrieves it. Hungry managed non-monster land animals use
@@ -165,11 +180,26 @@ Current position:
165180
multiplayer, and dedicated-server behavior remain unverified.
166181
- Phantom spawning no longer depends on insomnia when Retold handles a still-default NeoForge
167182
decision. Vanilla retains its hostile-spawn gamerule, 60–120-second cadence, dark-sky gate,
168-
spectator exclusion, placement checks, and generated group size; Retold requires open sky,
169-
night-or-storm context, local difficulty, and a one-in-eight rarity result. Explicit decisions
170-
from other mods remain untouched. Stalking no longer gives players an arbitrary score bonus and
171-
keeps Undead diplomacy. Both exact focused tests pass; natural frequency, storms, multiplayer,
183+
spectator exclusion, and placement checks; Retold requires open sky, night-or-storm context,
184+
local difficulty, and a one-in-sixteen rarity result, then limits its approved attempt to one
185+
Phantom. Explicit decisions and spawn counts from other mods remain untouched. Stalking no longer
186+
gives players an arbitrary score bonus and keeps Undead diplomacy. Three exact focused tests pass;
187+
natural frequency, storms, multiplayer,
172188
and dedicated servers remain unverified.
189+
- A target-holding mob now gives its intended mob victim a bounded chance to react before damage.
190+
Within 24 blocks and cached victim-to-attacker sight, shared prey flee, healthy ordinary
191+
predators defend, eligible combat-faction victims countertarget through `THREAT_RESPONSE`, and
192+
Wolves or Polar Bears can warn available members of their exact species. Failed perception is
193+
retried at most every five ticks, walls block it, existing duties remain protected, the response
194+
cannot counter-rally the original attacker's side, and later real damage promotes the response to
195+
`RETALIATION`. This reads real mob target state and does not infer player intent from weapons or
196+
crosshairs. The exact pre-hit test and adjacent defense/faction/warning regressions pass.
197+
- Generic post-hit social defense triggers only after the victim takes real health damage. Wolves and
198+
Polar Bears use exact-species membership through `retold:shared_defense_species`; Nether
199+
Remnants, Illagers, Spider families, Silverfish, Endermites, Hoglins, Breezes, and Village
200+
Defenders use cooperative faction alignment. One cached 32-block scan recruits at most eight
201+
idle adult allies with close hearing or sight. The caller, the attacker's side, babies, busy or
202+
controlled allies, sitting/differently owned Wolves, and specialist factions are excluded.
173203
- Zoglins and wild Zombie Nautiluses are explicit members of the data-driven Undead faction;
174204
taming removes a Zombie Nautilus's generic faction identity. Zombie-horde, Skeleton-ranged,
175205
Ghast-artillery, and Zoglin-rampage proactive scorers no longer give players an arbitrary bonus.
@@ -187,6 +217,14 @@ Current position:
187217
25% of its original weight; vanilla caps, placement, and pack sizes remain authoritative. Its
188218
exact stage-boundary test passes. Stat buffs are intentionally absent; natural spawn composition
189219
and mixed-crowd balance remain unverified.
220+
- Skeletons, Strays, and Bogged now hold a real ranged shot when another Undead intersects the
221+
shooter-eye-to-target-eye segment. The ranged owner keeps `UNDEAD_RANGED` control and requests a
222+
budgeted lateral/back-step route, trying the opposite side only after a genuine unreachable
223+
result; moving the ally clear restores vanilla arrow creation. The exact firing-lane test and
224+
neighboring coordination, target-parity, and weapon-pose regressions pass. Latest 50-mob
225+
Skeleton, Stray, and Bogged reruns peak at 3.512, 3.612, and 3.963 ms/tick. Natural crowded
226+
formations, elevation, obstacle-heavy repositioning, modded ranged-attack compatibility,
227+
multiplayer, and dedicated servers remain unverified.
190228
- Withers now use a specialized ten-tick bounded cached selector instead of Retold's generic
191229
forced-faction loop. Recent attackers and creatures actively targeting the Wither outrank merely
192230
nearby prey, current-target inertia limits churn, players receive no categorical bonus, and the

docs/internal/mob_tps_benchmark.md

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,22 @@ The later Stage 2 natural-spawn weight hook changes only NeoForge's potential-sp
367367
does not add loaded-mob tick work, so these eight exact coordination benchmarks were not repeated.
368368
Its separate exact test covers the stage, tag, category, weight, and preserved-spawn-data boundaries.
369369

370+
### Ranged Undead Firing-Lane Focused Runs
371+
372+
Allied firing-lane avoidance adds a cached bounded entity query and possible lateral/back-step path
373+
request only to Skeleton, Stray, and Bogged ranged combat. Their three exact selectors were rerun on
374+
2026-08-30; Zombie-family coordination and shared cache/budget primitives were unchanged, so the
375+
other profiles were not selected.
376+
377+
| Mob | Idle/rest | Dropped food/forage | Hunt/targeting | Danger/social | Habitat/day-night | Peak |
378+
| --- | ---: | ---: | ---: | ---: | ---: | ---: |
379+
| Skeleton | 3.512 | 2.305 | 3.442 | 2.502 | 1.273 | 3.512 |
380+
| Stray | 3.575 | 2.344 | 3.612 | 2.819 | 1.443 | 3.612 |
381+
| Bogged | 3.963 | 2.242 | 3.648 | 2.215 | 1.301 | 3.963 |
382+
383+
All fifteen phases sustained 20 TPS below the 50 ms/tick gate. Bogged idle/rest was the
384+
3.963 ms/tick overall peak; absolute wall-clock values remain host-load-dependent.
385+
370386
### Wounded-Predator Flight Focused Runs
371387

372388
The damage phase now lowers all seven wild ordinary predator profiles through their strict 25%
@@ -456,8 +472,9 @@ work. The complete profile matrix was not selected because only the Villager sto
456472
### Dry-Land Flight Focused Rerun
457473

458474
The exact `retold:mob_tps_cow` and `retold:mob_tps_wolf` selectors were rerun on 2026-08-23 after
459-
urgent ground flight began using bounded land-position sampling and rejecting paths that enter
460-
water when the mob starts on land. These profiles cover a passive grazer and a predator using the
475+
the initial urgent-ground-flight implementation added bounded land-position sampling and rejected
476+
paths that enter water when the mob starts on land. The later stable flee-route rerun below
477+
supersedes that selector with straight corridors and deterministic detours. These profiles cover a passive grazer and a predator using the
461478
shared flight adapter; the complete matrix was not selected because ordinary movement, shared scan
462479
caches, and work-budget primitives did not change.
463480

@@ -466,6 +483,51 @@ dropped-food/forage, 2.638 hunt/targeting, 5.806 danger/social, and 3.083 habita
466483
ms/tick. Wolf averaged 4.624, 4.549, 5.476, 4.753, and 2.921 ms/tick in the same phase order.
467484
Cow danger/social was the combined 5.806 ms/tick peak.
468485

486+
### Visible Attack-Intent Complete Matrix Rerun
487+
488+
The complete 83-profile matrix was selected on 2026-08-30 because visible attack-intent
489+
perception adds a bounded check to the shared target-holding `PathfinderMob` tick path rather than
490+
to one species-local dispatcher. All 83 tests and 415 phases passed in 2.675 minutes, every phase
491+
remained below the 50 ms/tick gate, and all results reported sustainable 20 TPS. Bat
492+
habitat/day-night was the 8.311 ms/tick overall peak; Villager idle/rest and danger/social followed
493+
at 7.747 and 7.711 ms/tick. The exact pre-hit behavior test and adjacent defense, flight, faction,
494+
village-defender, and territory-warning regressions remain the correctness evidence; this matrix
495+
establishes only the isolated 50-mob performance boundary.
496+
497+
### Species-Aware Target-Distance Focused Runs
498+
499+
The exact Zombie, Skeleton, Piglin, Ghast, Phantom, Wither, Warden, Ender Dragon, and Wildfire selectors were run
500+
separately on 2026-08-30 after the shared target hook gained profile-aware assignment checks and a
501+
staggered five-tick retention cleanup. These deliberately cover both Mob and Brain targeting,
502+
Stage-scaled Undead, managed and unmanaged profiles, and every current long-range specialist
503+
category touched by the policy. The complete matrix was not selected because the maintained
504+
strategy requires exact representative selectors for shared changes.
505+
506+
All 45 phases sustained 20 TPS and remained below 50 ms/tick. Peak phases were Zombie 5.037,
507+
Skeleton 4.802, Piglin 8.178, Ghast 5.604, Phantom 4.807, Wither 6.638, Warden 5.111, Ender Dragon
508+
2.480, and Wildfire 6.194 ms/tick. Piglin hunt/targeting was the combined 8.178 ms/tick peak. The exact target-distance test and the
509+
focused Undead, Phantom, Wildfire, Wither, faction, visible-intent, village-defender, territory,
510+
and threat-retargeting tests remain the correctness evidence.
511+
512+
### Stable Flee-Route Focused Runs
513+
514+
The exact Cow, Wolf, Salmon, and Cat selectors were run separately on 2026-08-30 after the
515+
developer confirmed that destination commitment alone still allowed consecutive randomized
516+
segments to alternate sides. Shared urgent flight now uses a straight escape corridor on clear
517+
ground, retains matching active paths across speed updates, and tests only bounded deterministic
518+
detours after actual route rejection. They represent land prey, wounded-predator continuation,
519+
aquatic prey, and Cat/Creeper retreat. The complete matrix was not selected because the change adds
520+
no scan, dispatcher cadence, LOD, or work-budget expansion and the maintained strategy calls for
521+
these exact representatives.
522+
523+
All 20 phases sustained 20 TPS and remained below 50 ms/tick. Cow averaged 4.269 idle/rest, 4.918
524+
dropped-food/forage, 2.909 hunt/targeting, 6.472 danger/social, and 3.376 habitat/day-night ms/tick.
525+
Wolf averaged 5.287, 4.403, 5.996, 5.932, and 3.782; Salmon averaged 5.552, 3.561, 5.141,
526+
5.577, and 2.592; Cat averaged 4.194, 4.036, 5.350, 5.859, and 2.875 ms/tick in the same phase
527+
order. Cow danger/social was the combined 6.472 ms/tick peak. The two exact stability tests and
528+
focused damage, water, visible-intent, Creeper, Cat, wounded-predator, and stuck-recovery regressions
529+
remain the correctness evidence.
530+
469531
## Results
470532

471533
The table below records the original clean baseline described above; later rerun summaries are

0 commit comments

Comments
 (0)