Mob control
MobControl gives one mob orders to run, keep away, walk to a point, hold still, leap, attack,
or calm down, the same way whether its AI runs on goals or a brain. MobOwnership tells
whether a player keeps a mob, so a mod can leave pets and mounts alone.
At a glance
Section titled “At a glance”| Type | Summary | Status | Since | Side | Thread |
|---|---|---|---|---|---|
MobControl |
Orders that move, alarm, hold, target, and calm a mob, whether its AI runs on goals or a brain. | Experimental | 1.2.0 | server | server |
MobOwnership |
Whether a mob is kept by a player. | Experimental | 2.0.0 | both | server |
TargetVeto |
A rule that forbids MobControl#attack from making a mob attack a target, for example no player in Peaceful. |
Experimental | 1.2.0 | server | server |
Quick start
Section titled “Quick start”In your mod’s common initializer:
MobHurtCallback.EVENT.register((mob, source, amount, attacker) -> { if (!(mob instanceof Animal) || !(attacker instanceof Player)) return; if (MobOwnership.isKeptByPlayer(mob)) return; // 8 blocks away at a brisk walk, for 200 ticks (10 seconds). MobControl.avoid(mob, attacker, 8, 1.2, 200);});MobControl
Section titled “MobControl”Experimental · Since 1.2.0 · Side: server · Thread: server
MobControl gives one mob an order from any server code, such as an event listener or a
reaction. With mob a Mob the mod herds home and pen the BlockPos of its pen, run on
the mod’s own schedule:
if (!MobControl.hasMoveOrder(mob) && !MobControl.moveStoppedShort(mob, 200)) { MobControl.moveTo(mob, pen.getX() + 0.5, pen.getY(), pen.getZ() + 0.5, 1.0, 200);}Stope drives each kind of AI through the parts vanilla already has:
- A goal mob gets two Stope goals the first time it receives an order: a movement goal at
priority 0 with the
MOVEandLOOKflags, and a target goal at priority 0 with theTARGETflag. - A goal mob’s own melee and bow attacks pause during a movement order because Stope’s movement goal holds the flags they need.
- A brain mob (any mob whose brain registers
WALK_TARGET) is driven through memories at the end of its tick:WALK_TARGETfor movement,IS_PANICKINGwhile alarmed,AVOID_TARGETwhile avoiding,LOOK_TARGETwhile holding, andATTACK_TARGET,ANGRY_AT, andRAM_TARGETfor attacks. Stope sets each memory only when that brain registers it.
Ordering and timing
Section titled “Ordering and timing”- A movement order (alarm, avoid, move) stops a horse, donkey, mule, llama, or camel from
eating (
AbstractHorse#isEating), checked on every tick the order lasts: an eating horse cannot move, and starts eating at random. - A brain mob loses any walk target its idle behaviors set while a hold lasts.
- A brain mob that has not reached a
MobControl#moveTopoint gets its walk target back at most every 10 ticks. - A goal mob on the ground with no path at all tries again after 10 ticks.
- A goat with an attack order aims each ram at the target’s position as that ram starts.
- A goat’s ram that ends without hitting (the target moved, or vanilla aborted the ram) is asked for again 10 ticks later.
- An attack order on a new target, or one given after the last order ended, clears the ram cooldown.
- An attack order on the same target while its order lasts only extends that order.
Edge cases
Section titled “Edge cases”- An attack order that runs out leaves what it set in place for vanilla AI: a goal mob’s
target, a neutral mob’s anger, and a brain mob’s
ATTACK_TARGETandANGRY_AT.MobControl#calmclears them. - An attack order that ends early (its target dies, leaves the level, becomes vetoed, or is replaced by another target) takes back the memories Stope set.
See also
Section titled “See also”- Mob groups: giving orders to a whole group.
- Reaction binding format: the primitive reactions, which give these orders.