minecraft:behavior.nearest_attackable_target

Allows an entity to attack the closest target within a given subset of specific target types.

Properties

PropertyTypeDefaultWhat it does
reselect_targetsBooleanfalseAllows the attacking entity to update the nearest target, otherwise a target is only reselected after each "scan_interval" or "attack_interval".
attack_intervalObject{"max": 0, "min": 0}Time range (in seconds) between searching for an attack target, range is in (0, "attack_interval"]. Only used if "attack_interval" is greater than 0, otherwise "scan_interval" is used.
minDecimal0
maxDecimal0
scan_intervalIntegermin 110If "attack_interval" is 0 or isn't declared, then between attacks: scanning for a new target occurs every amount of ticks equal to "scan_interval", minimum value is 1. Values under 10 can affect performance.
target_search_heightDecimalmin -1-1Maximum vertical target-search distance, if it's greater than the target type's "max_dist". A negative value defaults to "entity_types" greatest "max_dist".
target_invisible_multiplierDecimal0.7Multiplied with the target's armor coverage percentage to modify "max_dist" when detecting an invisible target.
target_sneak_visibility_multiplierDecimal0.8Multiplied with the target type's "max_dist" when trying to detect a sneaking target.
set_persistentBooleanfalseAllows the actor to be set to persist upon targeting a player
target_acquisition_probabilityDecimal1Probability (0.0 to 1.0) that this entity will accept a found target. Checked each time a valid target is found during scanning.
attack_ownerBooleanfalseIf true, this entity can attack its owner.
must_reachBooleanfalseIf true, this entity requires a path to the target.
must_seeBooleanfalseDetermines if target-validity requires this entity to be in range only, or both in range and in sight.
within_radiusDecimalmin 00Maximum distance this entity can be from the target when following it, otherwise the target becomes invalid. This value is only used if the entity doesn't declare "minecraft:follow_range".
must_see_forget_durationDecimalmin 03Time (in seconds) the target must not be seen by this entity to become invalid. Used only if "must_see" is true.
persist_timeDecimalmin 00Time (in seconds) this entity can continue attacking the target after the target is no longer valid.
entity_typesList of object or Object[]Filters which types of targets are valid for this entity.
filtersObject or List of object{"AND": null, "NOT": null, "OR": null, "all": null, "all_…Conditions that make this entry in the list valid
max_distDecimal16Maximum distance this mob can be away to be a valid choice
max_heightDecimal-1Maximum height this mob can be away to be a valid choice
max_fleeDecimal10Maximum distance this mob can be from the target to stop fleeing
walk_speed_multiplierDecimal1Multiplier for the walking speed. A value of 1.0 means the speed is unchanged
sprint_speed_multiplierDecimal1Multiplier for the sprinting speed. A value of 1.0 means the speed is unchanged
priorityInteger0Priority for this mob type
check_if_outnumberedBooleanfalseIf true, the mob will check if its outnumbered
reevaluate_descriptionBooleanfalseIf true, the mob will stop being targeted if it stops meeting any conditions.
cooldownInteger0The amount of time in seconds that the mob has to wait before selecting a target of the same type again
must_seeBoolean—If true, the mob has to be visible to be a valid choice
must_see_forget_durationInteger3Determines the amount of time in seconds that this mob will look for a target before forgetting about it and looking for a new one when the target isn't visible any more
priorityIntegermin 00
control_flagsList of text[]

Example from the game files

This is how vanilla Axolotl uses it in Minecraft Bedrock 1.26.60.5:

{
  "minecraft:behavior.nearest_attackable_target": {
    "priority": 3,
    "must_see": true,
    "reselect_targets": true,
    "within_radius": 20.0,
    "must_see_forget_duration": 17.0,
    "entity_types": [
      {
        "filters": {
          "all_of": [
            {
              "test": "in_water",
              "subject": "other",
              "value": true
            },
            {
              "test": "has_component",
              "subject": "self",
              "operator": "!=",
              "value": "minecraft:attack_cooldown"
            },
            {
              "any_of": [
                {
                  "test": "is_family",
                  "subject": "other",
                  "value": "squid"
                },
                {
                  "test": "is_family",
                  "subject": "other",
                  "value": "fish"
                },
                {
                  "test": "is_family",
                  "subject": "other",
                  "value": "tadpole"
                }
              ]
            }
          ]
        },
        "max_dist": 8
      },
      {
        "filters": {
          "all_of": [
            {
              "test": "in_water",
              "subject": "other",
              "value": true
            },
            {
              "any_of": [
                {
                  "test": "is_family",
                  "subject": "other",
                  "value": "drowned"
                },
                {
                  "test": "is_family",
                  "subject": "other",
                  "value": "guardian"
                },
                {
                  "test": "is_family",
                  "subject": "other",
                  "value": "guardian_elder"
                }
              ]
            }
          ]
        },
        "max_dist": 8
      }
    ]
  }
}

Used by 49

Vanilla entities with minecraft:behavior.nearest_attackable_target in their definition:

Related components