Minestom wiki
Comment on page



Entity AI is done by giving an entity an ordered list of goals to do if a condition is validated. Once an action is found, the entity will be affected by it until asked to stop.
For example, a very simple aggressive creature could have:
  1. 1.
    Attack target
  2. 2.
    Walk randomly around
  3. 3.
    Do nothing
Every tick, the entity will find the goal to follow based on its priority. If the entity has a target the first goal will be used, and the rest be ignored.


You might find yourself wanting to have multiple goals being executed at the same time. For example, having an entity attacking its target while swimming to avoid dying. This is done by adding multiple EntityAIGroup to the entity, each group contains a list of goals to be executed independently.


In this example, instances of ZombieCreature will attack nearby players or walk around based on if a player is nearby.
package demo.entity;
import net.minestom.server.entity.ai.EntityAIGroupBuilder;
import net.minestom.server.entity.ai.goal.RandomLookAroundGoal;
import net.minestom.server.entity.type.monster.EntityZombie;
import net.minestom.server.entity.EntityType;
public class ZombieCreature extends EntityCreature {
public ZombieCreature() {
new MeleeAttackGoal(this, 1.6, 20, TimeUnit.SERVER_TICK), // Attack the target
new RandomStrollGoal(this, 20) // Walk around
new LastEntityDamagerTarget(this, 32), // First target the last entity which attacked you
new ClosestEntityTarget(this, 32, entity -> entity instanceof Player) // If there is none, target the nearest player