Mob AI

From Minecraft Wiki
(Redirected from Anger)
Jump to navigation Jump to search
For other uses, see AI.
This article is a work in progress.
Anyone is encouraged to edit this page and add more content into the topic.
This article needs cleanup to comply with the style guide.
[discuss]
Please help improve this page. The talk page may contain suggestions.

Mob AI is the mechanism through which mobs behave and adapt their behavior according to their environment. Despite its name, it refers to the traditional use of artificial intelligence in video games, rather than the generative AI commonly referred to simply as "AI" in recent years.

This article describes the various components of a mob's AI that control its behavior.

Brain

[edit | edit source]

Some mobs use a complex AI system called a brain. A mob's brain stores memories (data), a list of tasks that can be performed, and a list of sensors used to determine which tasks it can perform.

Memory

[edit | edit source]

A brain stores data as memories. The type a memory represents is called the memory module type. The data itself is stored within a corresponding memory slot. Within the memory slot the data value can be empty, signaling that the memory is empty, or it can have a value signaling that the memory is present. Additionally the memory may have a time-to-live. The time-to-live indicates the number of ticks after which the memory is forgotten, and the memory value will become empty again. If the time-to-live is not specified, it is assumed to be infinite, i.e. the memory is permanent.

Memories are the only NBT-driven component of the brain system. To modify a mob's memories, the /data command can be used. Note that this will erase all non-persistent memories and reset all activity and behavior states, as the mob's brain is completely reconstructed.

Example:

/data merge entity <TARGET> {Brain:{memories:{"minecraft:dig_cooldown":{value:{},ttl:0L}}}}

Executing this command with a warden as its target will cause the warden to immediately burrow. This is because the 60 second cooldown timer gets reduced to 0 ticks, causing the memory to expire in the next tick, at which the warden can initiate its despawning process.

Memory statuses

[edit | edit source]

Registered memory module types can have three states in a brain:

  1. REGISTERED: The brain contains a memory slot for the type.
  2. VALUE_PRESENT: The brain holds a value in the memory module type's corressponding memory slot.
  3. VALUE_ABSENT: The brain does not hold a value in the memory module type's corressponding memory slot.

These statuses will become relevant in the activity and behavior sections.

Memory module types

[edit | edit source]

Notes

  • Memory module types that are not serializable will not be saved when the entity is unloaded.
  • For memory module types of type Unit, the data stored, is the presence of the memory itself. For example, an entity is considered in water if the memory value for is_in_water is present.

Sensor

[edit | edit source]

Sensors are used to detect if a mob with a brain can perform certain tasks. Examples of sensors include a sensor to detect if an armadillo should be scared, a sensor to detect the nearest player, and a sensor to detect if a mob is in water.

By default, sensors run once every 20 game ticks (1 second), although individual sensor classes can have a different scan rate. When a sensor runs, it updates its targeting conditions to match the mob's current follow_range attribute before performing its targeting condition. The first execution of each sensor is delayed by a random number of ticks, preventing multiple sensors from running simultaneously; the random number is an integer between 0 (inclusive) and the scam rate (exclusive).

List of Sensors in Java Edition
Sensor Class Uses
dummy DummySensor default sensor type
nearest_items NearestItemSensor
mobs NearestLivingEntitySensor
nearest_players PlayerSensor
nearest_bed NearestBedSensor Villager
hurt_by HurtBySensor
villager_hostiles VillagerHostilesSensor Villager
villager_babies VillagerBabiesSensor Villager
secondary_pois SecondaryPoiSensor Villager
golem_detected GolemSensor Villager
armadillo_scare_detected MobSensor Armadillo
piglin_specific_sensor PiglinSpecificSensor Piglin
piglin_brute_specific_sensor PiglinBruteSpecificSensorregister Piglin
hoglin_specific_sensor HoglinSpecificSensor Hoglin
nearest_adult AdultSensor
nearest_adult_any_type AdultSensorAnyType Happy Ghast
axolotl_attackables AxolotlAttackablesSensor Axolotl
food_temptations TemptingSensor
frog_temptations TemptingSensor
nautilus_temptations TemptingSensor
frog_attackables FrogAttackablesSensor Frog
is_in_water IsInWaterSensor Frog
warden_entity_sensor WardenEntitySensor Warden
breeze_attack_entity_sensor BreezeAttackEntitySensor Breeze

Sensor parameters

[edit | edit source]

Some sensor classes have parameters, namely MobSensor and TemptingSensor. The list of parameters is below:

Technically, all sensor classes have the scanRate parameter, which defines how many ticks the sensor runs. However, most vanilla sensors use the class's default scanRate value (20 by default, but this can change in certain classes; see below). The only sensor that sets its scanRate is armadillo_scare_detected.

Targeting condition

[edit | edit source]

Many sensors need to filter entities based on certain tests. The test conditions can change depending on the sensor's objective.

Each targeting condition has the tags [Boolean] isCombat, [Boolean] checkLineOfSight, [Boolean] testInvisible, [Double] range and selector which are used to perform the test. The selector consists of a predicate that depends on the target, but it can be null.

For sensor targeting conditions, except TemptingSensor, the [Double] range is initially defined as 16.0, but it is updated to the value of the attribute follow_range before the sensor's doTick, selector is null, [Boolean] isCombat is true when testing an attack target, [Boolean] testInvisible is false when the target is in the targeter's attack_target memory, and [Boolean] checkLineOfSight is true.

The test value is a boolean value that depends on the target and the targeter (and can be null), both living entity such that:

  • If target and targeter are the same entity, it returns false.
  • If the target is not alive or is a player in Spectator mode or an invisible or marker armor stand, returns false.
  • If the selector is not null, and the target is valid in the selector test, return false.
  • If the targeter is null, [Boolean] isCombat is true, and target is invulnerable, or the difficulty is peaceful, it returns false. The following points assume that targeter is not null.
  • If [Boolean] isCombat is true, the targeter can not attack the target or the targeter is allied to the target, return true. See below for more details.
  • If [Double] range > 0 and the euclidean distance from targeter to target is greater than max(range × modifier, 2.0), it returns false.
    • If [Boolean] testInvisible is false, the modifier is 1.0; else the modifier starts with 1.0 (double) and is cumulative:
      • Multiplying by 0.8 if target is a sneaking player,
      • Multiplying by 0.07 if target is invisible and without equipament in humanoid armor slot,
      • Multiplying by 0.175p if target is invisible and has p≥1 equipaments in humanoid armor slot,
      • Multiplying by 0.5 if target is using the corresponding mob head in the head slot (for skeleton, zombie, piglin, piglin brute, and creeper)
        • This depends on the component mob_visibility, more specifically, for each target's equipment slot s there is an item with the component equippable.slot equal to s, and the targeter is contained in mob_visibility.targeting_entity_types, the modifier is multiplied by mob_visibility.visibility.}
      • The modifier is limited by 10.0.
  • If [Boolean] checkLineOfSight is true, the targeter is a mob, and it is not possible to draw a straight line from the targeter's eye to the target without intersecting a block collision box, return false.
    • If the mob is a ravager with a stunned tick or roar tick greater than 0, return false.
  • Otherwise, it returns true.

The table below shows when the conditions of a living entity (the targeter) can not attack another (the target). At least one condition must be satisfied for it not to attack.

Can not attack
Targeter Can not attack if...
Living entity (except ender dragon and warden)
  • The target is a player and the difficulty is peaceful.
  • The target is invulnerable.
  • The target is not alive.
Mobs (except ender dragon and warden)

Tamable Animal

  • The target owns the animal.
Dolphin
  • The dolphin is baby.

Iron Golem

  • The iron golem was created by a player ([Boolean] PlayerCreated is true) and the target is a player.
  • The target is a creeper.

Ender Dragon

  • The target is invulnerable.
  • The target is not alive.

Breeze

  • The target is not a player or iron golem.

Illager

Warden
  • The warden can not target the target:

An entity A is an ally of an entity B if A = B, if A considers B as an ally, or if B considers A as an ally. The table below shows when one entity considers another as an ally:

  1. ↑ The root owner of an entity, if it exists, is the first non-ownable entity in a chain of owners of owners ... of owners of the entity. For example, if the entity owner is not an ownable entity, it would be the root owner.

Sensor classes

[edit | edit source]

Sensors classes are responsible for detecting a specific type of information and storing the results in one or more memory modules in a mob's brain. In the game's code, these classes are part of the package net.minecraft.world.entity.ai.sensing

Class Memory requires Do tick
DummySensor None Performs no actions
AdultSensor nearest_visible_adult and visible_mobs Searches the visible_mobs memory for the nearest visible living entity of the same entity type as the mob that is not a baby. Stores the result in the nearest_visible_adult memory.

If no matching adult is found, nearest_visible_adult is set to empty.

AdultSensorAnyType
Extends AdultSensor

When setting the nearest visible adult, it tests whether the entity is in the tag #followable_friendly_mobs, rather than whether it's in the same entity type as the mob.

AxolotlAttackablesSensor nearest_attackabled, visible_mobs, and has_hunting_cooldown

Searches the visible_mobs memory for the closest living entity that:

Stores the closest matching entity in the nearest_attackable memory.

BreezeAttackEntitySensor mobs, visible_mobs, and nearest_attackable

Updates the mobs and visible_mobs memories (by the super method). It then searches the mobs memory for the attackable entity[sensor 1] that is not a player in Creative mode or Spectator mode.

Stores the first matching entity in the nearest_attackable memory. If no matching entity is found, it removes the nearest_attackable memory.

FrogAttackablesSensor nearest_attackable, visible_mobs, and unreachable_tongue_targets

Searches the visible_mobs memory for entity that:

Stores the closest matching entity in the nearest_attackable memory.

GolemSensor mobs and golem_detected_recently Searches the mobs memory for an iron golem. If one is found, it sets the golem_detected_recently memory to true with an expiration time of 599 game ticks (29.95 seconds).

scanRate: This sensor runs every 200 game ticks (10 seconds) by default. It only checks whether at least one iron golem is present.

HoglinSpecificSensor visible_mobs, nearest_repellent, nearest_visible_adult_piglin, nearest_visible_adult_hoglins, visible_adult_piglin_count, and visible_adult_hoglin_count Searches the visible_mobs memory for visible adult piglins and hoglins.

Stores the nearest visible adult piglin in the nearest_visible_adult_piglin memory and stores visible adult hoglins in the nearest_visible_adult_hoglins memory. It also stores the number of visible adult piglins and hoglins in the visible_adult_piglin_count and visible_adult_hoglin_count memories.

Searches for the nearest hoglin repellent block within 8 blocks horizontally and 4 blocks vertically, and stores its position in the nearest_repellent memory.

HurtBySensor hurt_by and hurt_by_entity Checks the mob's last damageSource.
  • If the mob has a last damage source, stores it in the hurt_by memory.
  • If the damage source was caused by a living entity, stores that entity in the hurt_by_entity memory.
  • If the mob has no last damage source, removes the hurt_by memory.
  • If the entity stored in hurt_by_entity is no longer alive or is no longer in the same world, removes the hurt_by_entity memory.
IsInWaterSensor is_in_water Checks whether the mob is in water: the hitbox intersects the fluid in the #water fluid tag, if the mob are on the boat, reduce the y-min of the hitbox; disregard heights below the height of the boat, except if the boat is underwater.

If it is, it sets the is_in_water memory. Otherwise, it removes the is_in_water memory.

MobSensor mobs
This sensor uses parameters.

If the sensor's readiness condition (readyTest) is met, it searches the mobs memory for a living entity matching the sensor's predicate (mobTest). If a matching entity is found, it sets the sensor's memory (memoryTimeToLive) to true with an expiration time determined by the sensor (toSet). If the readiness condition (readyTest) is not met, it removes the sensor's memory (memoryTimeToLive).

NearestBedSensor nearest_bed If the mob is a baby:
  • Searches for POIs of type home (bed head) within 48 blocks of the mob. The sensor uses a cache to avoid repeatedly checking the same POIs and attempts to add up to 5 new beds to the cache during each scan.
  • The sensor attempts to create a path to the found beds. If a path is found and can reach its target, and the target is a valid POI, it stores the target's position in the mob's nearest_bed memory.
  • If no reachable bed is found and fewer than 5 POIs were checked, it removes expired entries from the cache.[sensor 2]
NearestItemSensor nearest_visible_wanted_item Find the nearest item that:
  • Is within a bounding box extending 32 blocks horizontally and 16 blocks vertically from the mob.
  • Is within 32 blocks of the mob.
  • The mob wants to pick up.[sensor 3]
  • Is in the mob's line of sight.[sensor 4]

The nearest matching item is stored in the nearest_visible_wanted_item memory. If no matching item is found, the memory is set to empty.

NearestLivingEntitySensor mobs and visible_mobs

Lists all other living entities that are alive and within a cuboid generated by the mob's hitbox expanded by its follow_range in all directions. Sorts the entities by Euclidean distance from the mob and stores the list in the mobs memory.

In visible_mobs, stores[sensor 5] the entities from mobs filtering entities using the mob's targeting conditions[sensor 6]

NearestVisibleLivingEntitySensor visible_mobs and a memory defined by the subclass Searches the visible_mobs memory for the closest living entity that matches the conditions defined by the subclass.

The matching entity is stored in the memory defined by the subclass. If no matching entity is found, the memory is set to empty.

PiglinBruteSpecificSensor visible_mobs, nearest_visible_nemesis, and nearby_adult_piglins Searches the visible_mobs memory for the nearest wither skeleton or wither and stores it in the nearest_visible_nemesis memory.

Stores nearby adult piglins in the nearby_adult_piglins memory.

PiglinSpecificSensor visible_mobs, mobs, nearest_visible_nemesis, nearest_targetable_player_not_wearing_gold, nearest_player_holding_wanted_item, nearest_visible_huntable_hoglin, nearest_visible_baby_hoglin, nearest_visible_adult_piglins, nearby_adult_piglins, visible_adult_piglin_count, visible_adult_hoglin_count, and nearest_repellent Searches the visible_mobs memory and updates memories related to piglin behavior:
  • EntitySprite hoglin.png: Sprite image for hoglin in Minecraft Stores the nearest adult huntable[sensor 7] hoglin as nearest_visible_huntable_hoglin
    • EntitySprite baby-hoglin.png: Sprite image for baby-hoglin in Minecraft Stores the nearest baby hoglin as nearest_visible_baby_hoglin.
  • [Int] Stores the number of adult piglins and adult hoglins in visible_adult_piglin_count and visible_adult_hoglin_count, respectively.

Searches the mobs memory and stores adult piglins and piglin brutes in nearby_adult_piglins.

Searches for the nearest[sensor 8] block in the tag #pigling repellents in a box with 17 × 9 × 17 blocks centered on the piglins' position, and stores its position in nearest_repellent. Not lit soul campfires are not considered repellents.

PlayerSensor nearest_players, nearest_visible_player, nearest_visible_attackable_player and nearest_visible_attackable_players List all non-Spectator players that are within a Euclidean distance of the mob's follow_range. Sorts the players by distance from the mob and stores the list in nearest_players.

From this list, it creates nearest_visible_player by filtering players using the mob's targeting conditions[sensor 6]. If the resulting list is not empty, stores the first player in nearest_visible_player.

Creates nearest_visible_attackable_players by filtering nearest_visible_player's list using the mob's attack targeting conditions[sensor 1]. If the resulting list is not empty, the first player is stored in nearest_visible_attackable_player.

SecondaryPoiSensor secondary_job_site Scans all blocks within a 9 × 5 × 9 area centered on a villager. If a block matches one of the villager profession's secondary job site blocks, it stores its global position in the secondary_job_site memory. It stores all matching blocks.

If no matching blocks are found, it removes the secondary_job_site memory.

scanRate: This sensor runs every 40 game ticks (2 seconds) instead of the default 20.

TemptingSensor tempting_player
This sensor uses parameters.

Searches for the player that:

If a matching player is found, it stores the nearest (by euclidean distance) player in the tempting_player memory. Otherwise, it removes the tempting_player memory.

VillagerBabiesSensor visible_villager_babies Finds all villagers that are babies from the mob's visible_mobs memory and stores them as a list in the visible_villager_babies memory.

If no visible baby villagers are found, stores an empty list.

VillagerHostilesSensor nearest_hostile and visible_mobs

Searches the visible_mobs memory for the nearest living entity matching one of the following hostile entity types and stores it in the nearest_hostile memory:

If no matching hostile entity is found, nearest_hostile is set to empty.

WardenEntitySensor mobs, visible_mobs, and nearest_attackable

Updates the mobs and visible_mobs memories (by the super method). It then searches the mobs memory for the closest targetable player. If none is found, it searches for the closest targetable non-player living entity. In both cases, only entities that the warden can target are considered.

Stores the first matching entity in the nearest_attackable memory. If no matching entity is found, it removes the nearest_attackable memory.

  1. ↑ a b c d Targeting condition with [Boolean] isCombat and [Boolean] checkLineOfSight true, and [Boolean] testInvisible flase iff the entity is not in memory attack_target.
  2. ↑ A POI is considered expired depending on whether the current lastUpdate exceeds the lastUpdate from when the POI was added to the cache by more than 40. The lastUpdate is an auxiliary variable defined as Gametime + random.nextInt(20), at the beginning of the doTick.
  3. ↑ It depends on the mob, defined independently of the sensor.
  4. ↑ It is possible to draw a straight line from the mob's eye to the target without intersecting a block collision box.
  5. ↑ Technically, in memory visible_mobs, a list equal to that of mob is saved, along with a binary list of the same size indicating whether the entity passes the test.
  6. ↑ a b Targeting condition with [Boolean] isCombat false, [Boolean] checkLineOfSight true, and [Boolean] testInvisible flase iff the entity is not in memory attack_target
  7. ↑ A hoglin is huntable if the nbt tag [Boolean] CannotBeHunted is false. By default it is false.
  8. ↑ Used manhattan distance. If two blocks are equidistant, prioritize the one with the smaller X coordinate. If they are on the same X coordinate, prioritize the one with the smaller Y coordinate. If they are on the same Y coordinate, prioritize the one with the larger Z coordinate. In other words, it is the lexicographical order of (d,X,Y,-Z), with d the manhattan distance.
  9. ↑ Targeting condition, with this [Double] range, [Boolean] testInvisible true, and [Boolean] checkLineOfSight and [Boolean] isCombat false.

Activities

[edit | edit source]

An activity is essentially a phase within a mobs lifecycle. For example, some mobs, start with their idle activity, and switch to the fight activity as soon as an attack target is found. Once the attack target is defeated, the brain switches back to the idle activity.

An activity itself does, however, not define a mobs behavior during the activity. For example, just because the fight activity is called fight, it does not make the mob fight other mobs. This behavior is handled by certain behavior controls associated with the activity.

Core and default activities

[edit | edit source]

A brain has two types of special activities: core activities and the default activity.

Core activities are a set of activities that always run in the background. These contain basic behaviors such as trying to swim in water, looking at the current look target, or moving toward the current move target. By default, the set of core activities only includes the core activity. No mob changes this behavior.

The default activity of a brain is used when the mob spawns. This defaults to the idle activity and usually includes behaviors such as randomly looking or walking around. Only the Breeze sets its default activity to the fight activity. Villagers can also temporarily set their default activity to pre_raid> just before a raid or raid during a raid. Their default activity is reset to idle after the raid.

Activity conditions

[edit | edit source]

Within a brain, activities have conditions specifying when they can start. These conditions are specified as a list of memory module types and a memory status they must have. For example, the fight activity often requires that attack_target has a memory status of VALUE_PRESENT in order to start. This will be further discussed in the brain construction and brain updates section.

List of activities

[edit | edit source]

Behaviors

[edit | edit source]
In this section, the terms behavior control and behavior have distinct meanings. See the behavior control hierarchy for more information

Behavior controls define how a mob acts during an activity. For example, the core activity often contains the Swim behavior which instructs a mob to jump if it is in water. Behaviors are often given a priority, like goals in the goal system, allowing them start before lower prioritized behavior controls.

Behavior Controls are not registered via a registry but are standalone classes within the games code. Behavior controls essentially run an action for a certain amount of time. Different types (subclasses) specify different durations. Each Behavior Control also has a status, stating whether it is currently running or not.

Behavior control hierarchy

[edit | edit source]
  • BehaviorControl
    • Behavior
      • Swim
      • MoveToTargetSink
      • LookAtTargetSink
      • RandomLookAround
      • AnimalMakeLove
      • many more...
    • OneShot
    • GateBehavior
      • RunOne
    • DoNothing
Behavior
[edit | edit source]

A behavior is the most common type of behavior control. They are simply actions that run for a random amount of ticks. All behaviors specify so called entry conditions, being memory module types and a memory status they must have. A behavior can only start if these entry conditions and some extra behavior-specific start conditions are fulfilled. The behavior then runs until its specified duration ends or a stop condition is fulfilled.

Example: MoveToTargetSink

Entry Conditions:

  • cant_reach_walk_target_since: REGISTERED
  • path: VALUE_ABSENT
  • walk_target: value_present

Description: The MoveToTargetSink behavior tries to reach the position stored in the walk_target memory by instructing the mobs path navigation. This behavior usually runs for 150 to 250 ticks.

OneShot
[edit | edit source]

A oneshot is a behavior control that runs within a single tick. It is an action that executes instantly.

Example: MeleeAttack

Entry Conditions:

  • look_target: REGISTERED
  • attack_target: VALUE_PRESENT
  • attack_cooling_down: VALUE_ABSENT
  • visible_mobs: VALUE_PRESENT

Description: Fires a melee attack at the current target stored in the attack_target memory and resets the attack_cooldown memory to a per mob-specific value. This all occurs within one tick.

GateBehavior
[edit | edit source]

A gate behavior is like a behavior but selects a subset of behavior controls to run from a given pool of weighted behavior controls. A gate behavior attempts to start as follows:

  1. The entry conditions (required memories) for all behavior controls of the pool must be fulfilled. After passing this check, the gate behavior is already considered running.
  2. The order policy is applied. Either ORDERED, which keeps the order in which the pool elements were specified, or SHUFFLED which randomizes the order.
  3. The running policy is applied. Either RUN_ONE to find the first behavior control that will start, or TRY_ALL which will attempt to start all of them.

The Gate behavior is considered done when all behavior controls within the gate behavior have stopped.

RunOne
[edit | edit source]

A RunOne behavior control is a gated behavior with SHUFFLED order policy and RUN_ONE running policy. In other words, given a list of weighted behavior controls, the RunOne behavior control will randomly select one of them to run. Most mobs use a RunOne behavior control during the idle activity for looking around and randomized movement.

Example: RunOne structure used during the Creakings idle activity:

  • RandomStroll (weight = 2)
  • SetWalkTargetFromLookTarget (weight = 2)
  • DoNothing (weight = 1)
DoNothing
[edit | edit source]

Essentially a behavior that does nothing for a random amount of time. Usually either 20 to 40 ticks long, or 30 to 60 ticks long, but some mobs deviate from these times.

Brain construction

[edit | edit source]

All entities using the brain system define a brain provider. The brain provider is like a blueprint for a brain.

A brain provider specifies:

  • Required memory module types
  • Required sensor types
  • A list of activity data, where each activity data specifies:
    • An activity
    • The activity's memory status conditions
    • A list of behavior controls labeled with priorities, that can run during the activity
    • Memories to erase once the activity has completed
A structural overview depicting the internal components of a goats brain after spawning.
Overview of a goats brain structure after spawning

The brain provider is then used on a per mob basis, to construct the mobs brain. The process is as follows:

  1. The required memory module types specified in the brain provider are registered.
  2. Each specified sensor is created, and the sensors required memory module types are registered. Each sensors is also randomly delayed here.
  3. For all activity datas:
    1. The specified memory module tpyes that are to be erased after the activity completes are stored.
    2. The memory module types specified in the activity conditions are registered and stored.
    3. Each behavior control's required memories are registered, then the behavior controls are stored in a tree-like structure with the ordering of priority -> activity -> behavior control.
  4. Stored memories, from when the mob was saved, are restored.
  5. The core activity set is set to only include the core activity.
  6. The default activity (by default idle) is set as currently active. (core is implicitly also set active)

Brain updates

[edit | edit source]

A brain updates once every tick on the server side of the game. This involves ticking the brain, and a manual per-mob-specific decision, where the next activity is chosen.

Brain tick

[edit | edit source]
Visual overview of the mob AI brain tick process.
Visual overview of the brain tick process.
  1. Forget outdated memories: Memories with a time-to-live decrease their lifetime by one tick. Memories that have already reached their end of life are forgotten.
  2. Tick sensors: All sensors tick. Note that sensors only actually update every scanRate amount of ticks.
  3. Try to start non-running behaviors for active activities: From highest to lowest priority, and for each active activity, each behavior control, that has a status of not running is attempted to start, starting from the highest priority. It is here that the priority comes into play. For example: a highly prioritized behavior control that sets the walk_target memory will cause a low priority behavior control to not start if that behavior control requires the walk_target memory to be absent.
  4. Tick all running behaviors: all behaviors that are running are ticked or stopped if done.

Activity selection

[edit | edit source]

After the brain has ticked, each entity decides on the next possible activity with a self-defined policy. Usually this just involves defining an order of activities, from which the first is chosen that fulfills its memory requirements. The core activity is also implicity added to the set of active activities. Note, that the activity change will also cause the brain to erase all memories that are specified for erasure by a previously active activity. Behavior controls of previous activities will also continue to run until they are done or reach a stop condition.

Example: Order of activities defined by Piglins:

  1. admire_item
  2. fight
  3. avoid
  4. celebrate
  5. ride
  6. idle

The only entities to not use this approach are:

  • Axolotl: only applies the above method if the old activity is not play_dead.
  • Creaking: only applies the above method if it can move, otherwise uses the default activity.
  • Villager: activity updates are performed according to a schedule.

Control

[edit | edit source]

Walking

[edit | edit source]

Mob movement on land varies depending on whether it's hostile or passive. Hostile mobs will try to approach and attack the player when within their detection range, while most passive mobs will attempt to run away when attacked. Some mobs will also try to attack or run away from certain blocks or mobs.

Swimming

[edit | edit source]

Mob swimming works the same way as walking, but in water. While most mobs will just float on water or sink, some can properly swim like fish, drowned, dolphins, turtles, guardians, and elder guardians.

Flying

[edit | edit source]

Mob flying works the same way as walking, but in the air. Most mobs will just fall when suspended in air, with a few exceptions. Mobs with Slow Falling, levitation, and the chicken don't fly normally but can float in mid-air. Category:Flying mobs contains a list of all mobs that can pathfind in air.

Goals

[edit | edit source]

Goals are a simple AI system used primarily by mobs that already existed before the brain AI. However, there are recent mobs that use both AIs simultaneously, for example, the happy ghast.

Goals can range from wandering around, opening doors, attacking another mob, and more. Each type of mob that uses goals has its own defined list of goals, and each goal has a priority. Mobs attempt to perform the lowest priority goal they can, and may switch goals if there is an opportunity to pursue a lower priority goal. For example, if a zombie is targeting and chasing a villager (priority of 3) and a player comes within the detection range of the zombie, the zombie may target and chase the player (priority of 2) instead.

List of goals

[edit | edit source]

List of goals that are used by many different mobs.

Lists of mob goals

[edit | edit source]

Lists of goals and associated priorities for individual mobs.

Zombie
Goal Priority Notes
Revenge 1 Attack entity that damaged the zombie
Active Target - Player 2 Target the player
Zombie Attack 2 Attack current target
Active Target - Iron Golem 3 Target Iron Golem
Active Target - Merchant 3 Target Villager or Wandering Trader
Destroy Egg 4 Break turtle eggs
Active Target - Turtle 5 Target baby turtle
Wander Around Far 7
Look Around 8 Looks away from Entities
Look at Entity 8 Looks at nearest Entities

Pathfinding

[edit | edit source]

Pathfinding is the system used by mobs to navigate through the world. Mobs that use pathfinding calculate routes through the environment and follow these routes using their navigation system. Different mobs use different types of navigation depending on their movement abilities, such as walking, swimming, or flying.

The default navigation type for mobs is ground path navigation, although individual mobs can replace it with a different navigation implementation.

Pathfinding is controlled by a mob's AI. Goals and behaviors can request movement to a location or entity, causing the mob's navigation system to calculate and follow a path. The navigation system is updated every tick while the mob's AI is active.

A mob is considered to be pathfinding when its navigation system has an active path. The path ends when the mob reaches its destination, the path becomes invalid, or the navigation is stopped.

[edit | edit source]

The navigation system controls how mobs follow paths after they have been calculated.

A navigation system stores the mob's current path, movement speed, and destination. During each AI update, the navigation system checks the current path, advances through nodes that have been reached, and sends movement instructions to the mob's movement controls.

Navigation can be stopped manually, which clears the mob's current path. A mob is considered to be navigating when it has an active path that has not been completed.

Different mobs use different navigation systems depending on their movement type. Ground mobs generally use ground navigation, while aquatic and flying mobs use specialized navigation systems.

Navigation systems can also perform checks while moving, such as:

  • When a mob becomes stuck.
  • Recalculating paths when needed.
  • Whether a mob can move directly between two points.
  • Adjusting paths around certain blocks.

Path following

[edit | edit source]

After a path is created, mobs follow the path by moving from node to node. A node represents a position that the mob must reach while traveling.

A mob advances to the next node when it is close enough to its current node. Some paths allow mobs to skip nodes when moving directly toward a later point would be safe.

While following a path, mobs can become stuck if they fail to make sufficient progress. The navigation system checks movement over time and stops the path if the mob cannot continue.

Pathfinding penalties

[edit | edit source]
Zombified piglin starts pathfinding to a turtle egg
Due to pathfinding penalties, the zombified piglin takes an indirect path to the turtle egg, pathing through wither roses and taking damage, instead of pathing through the lava or magma blocks, which do not damage the zombified piglin

When pathfinding to a target, mobs will sometimes avoid certain blocks (usually blocks that cause damage or slow the mob down). These blocks have a penalty associated with them. Generally, mobs try to path through blocks with the smallest penalty. There are some blocks that most mobs cannot path through; these all have a penalty of -1.

The following table is a list of all pathfinding penalties and their default values. Each type of pathfinding (land, water, air) uses its own subset of these penalties. Some mobs override these default values.

Penalty type Penalty Description
blocked -1 can't pathfind through block (most full solid blocks)
powder snow -1 powder snow
fence -1 fences
walls
fence gates (closed)
lava -1 lava
unpassable rail -1 rail
damage - other -1 cactus
sweet berry bush
closed wood door -1 wood door
closed iron door -1 iron door
open 0 air
cave air
void air
walkable 0 TNT with pressure plate on top (under the mob)
walkable door 0 a door the mob can open
trapdoor 0 trapdoors
lily pad
big dripleaf
danger - powder snow 0 neighboring block is powder snow
open door 0 open wood or iron door
cocoa 0 cocoa
damage - cautious 0 wither rose
pointed dripstone
danger - trapdoor 0 neighboring block is trapdoor
breach water 4 there is an air block above a water block
water 8 water
water border 8 neighboring block is water
danger - fire 8 neighboring block is:
fire
lava
magma block
lit campfire
lava cauldron
danger - other 8 neighboring block is:
cactus
sweet berry bush
honey 8 honey block
damage - fire 16 fire
lava
magma block
lit campfire
lava cauldron
Mob pathfinding penalty overrides

The following mobs override the default pathfinding penalty for some blocks:

This section needs expansion.
You can help by editing the section and adding missing information.

Pathfinding on land

[edit | edit source]
  • All entities move based on random targets that are generated every tick with a priority toward their entity-specific goals.
  • These targets can be located anywhere in 3D space within the entity range and are only generated when wandering or when they have no goals.
  • For every target, a path is generated; with the entity preferring the path with the lowest score regarding the Pathfinding penalties.
  • If an entity cannot take any paths with a low enough score, or any paths without a score of -1, the entity will not move until one is found.
  • If an entity's target is located inside a block (including water), the target is moved to the nearest air block above it.

This means every entity, when wandering, will always prefer to pathfind to a block with the most blocks below it within range.

Due to the higher chance that a target will be generated within the blocks below it and moved up to the nearest air block above before generating a path.

Pathfinding in water

[edit | edit source]
  • Pathfinding in water is roughly the same as land; however, most entities, excluding fish and drowned, will bounce on the surface, preferring land due to the Pathfinding penalties of water.

Pathfinding in air

[edit | edit source]
  • Pathfinding in air is roughly the same as land; however, few entities can pathfind to air.

See also

[edit | edit source]
[edit | edit source]