Skip to content

AI Goals

Brennan Hatton edited this page Jun 7, 2026 · 1 revision

AI Goals

How PlayerMob's brain is wired, the one pattern worth copying, and an honest note on what is — and isn't — an extension point.

All goals live in games.brennan.playermob.entity.goal and are registered in PlayerMobEntity.registerGoals().


Goal selector (what the mob does)

Lower priority number = evaluated first / preempts.

Pri Goal Role
0 FloatGoal Swim / don't drown.
1 FleeFromCategoryGoal Shy: flee + hide near cover.
1 SkepticalWatchGoal Skeptical: stop & stare; ready weapon/shield if approached.
1 FriendlyGreetGoal Friendly: approach, crouch-greet, gift.
1 PlayerMobDoorGoal Open (and, if tidy, close) wooden doors on the path.
2 WeaponAwareAttackGoal Combat — crossbow / bow / melee (see below).
3 EatFoodGoal Eat from the backpack when hurt.
3 RaidContainersGoal Loot chests / barrels / shulkers.
3 RaidArmorStandsGoal Swap upgrades off armor stands.
3 CollectFloorItemsGoal Pick up wanted ground items.
6 HarvestCropsGoal Low-priority forage: harvest ripe carrots/potatoes/beetroot.
8 WaterAvoidingRandomStrollGoal Idle wander.
9 LookAtPlayerGoal Idle look.
10 RandomLookAroundGoal Idle look.

The three personality social goals (pri 1) self-gate on the live disposition — they only run when the mob actually feels that way about a nearby entity, and Skeptical/Friendly also yield when a combat target exists. Flipping a disposition at runtime (e.g. via provocation) instantly changes which one fires; nothing is re-registered.

Target selector (who the mob attacks)

Pri Goal Role
1 HurtByTargetGoal Retaliate against attackers.
2 NearestAttackableTargetGoal Acquire anything the mob is Aggressive toward (and, if on a train, on the same train).
3 HuntForFoodGoal Hunt food animals only while hungry — below hostile targeting, so defending beats chasing a cow.

The priority-2 acquisition predicate is:

candidate -> personalityToward(candidate) == Personality.AGGRESSIVE
          && TrainConfinement.allowsTarget(this, candidate)

TrainConfinement is a no-op unless an optional train mod is installed — see Soft-Dependency Integrations. A central sweep in customServerAiStep also drops a target that wanders off the train.


The pattern worth copying: WeaponAwareAttackGoal

PlayerMob fights with whatever is in its main hand, switching weapons mid-combat. Rather than register three vanilla attack goals at different priorities (their canUse() predicates don't know about "am I holding the right weapon?", so they'd thrash the selector), it composes them inside one outer Goal:

  • The outer goal claims MOVE, LOOK, JUMP once, so the selector sees a single stable combat occupant.
  • Each tick it picks a delegate by inspecting the main hand — RangedCrossbowAttackGoal, RangedBowAttackGoal, or MeleeAttackGoal.
  • Before (re)selecting it calls equipBestWeaponForTarget(target) (ranged when far, melee when close); on a weapon change it cleanly stop()s the old delegate and start()s the new one; on stop() it reverts to the best melee.

This composite-delegate shape is the reusable lesson: when several vanilla goals are mutually exclusive on a condition the selector can't see, wrap them in one goal that owns the flags and routes per-tick. Source.


Extending the behaviour

Be aware of what's actually open:

  • registerGoals() is not an extension point. It's a protected override with no registry or event hook. You cannot add a goal to PlayerMob from another mod without either a Mixin (the config at playermob.mixins.json is wired and empty — drop one into games.brennan.playermob.mixin) or a subclass of PlayerMobEntity registered as your own entity type.
  • The reusable, dependency-free bits are the policy classes (ItemPickupPolicy, EquipmentEvaluator, ForagePolicy) and the composite-goal pattern above — see Entity API Reference. If you're building your own mob, copy those; they're stateless and unit-tested.
  • Want a real extension hook (e.g. a goal-registration event, or a setPersonality setter)? That's a reasonable contribution — open an issue on the tracker.

Goal catalogue

Goal One-liner
WeaponAwareAttackGoal Composite crossbow/bow/melee combat.
FleeFromCategoryGoal Shy: flee & hide.
SkepticalWatchGoal Skeptical: stop, stare, ready defence.
FriendlyGreetGoal Friendly: approach, crouch, gift.
PlayerMobDoorGoal Open/close wooden doors.
EatFoodGoal Eat backpack food when hurt.
RaidContainersGoal Loot chests/barrels/shulkers.
RaidArmorStandsGoal Take upgrades off armor stands.
CollectFloorItemsGoal Pick up wanted ground items.
HarvestCropsGoal Harvest ripe food crops when idle.
HuntForFoodGoal Target goal: hunt food animals while hungry.

Clone this wiki locally