Entity Documentation - minecraft:behavior.nearest_attackable_target

minecraft:behavior.nearest_attackable_target compels an entity to attack the closest target within a given subset of specific target types.

Note

This behavior is a requirement for the following behaviors:

Parameters

Name Default Value Type Description
attack_interval 0 Integer 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.
attack_interval_min 0 Integer Alias for "attack_interval"; provides the same functionality as "attack_interval".
attack_owner false Boolean If true, this entity can attack its owner.
entity_types not set JSON Object Filters which types of targets are valid for this entity. See entity_types' definition page.
must_reach false Boolean If true, this entity requires a path to the target.
must_see false Boolean Determines if target-validity requires this entity to be in range only, or both in range and in sight.
must_see_forget_duration 3.0 Decimal Time (in seconds) the target must not be seen by this entity to become invalid. Used only if "must_see" is true.
persist_time 0.0 Decimal Time (in seconds) this entity can continue attacking the target after the target is no longer valid.
priority not set Integer The higher the priority, the sooner this behavior will be executed as a goal.
reevaluate_description false Boolean If true, the mob will stop being targeted if it stops meeting any conditions.
reselect_targets false Boolean Allows the attacking entity to update the nearest target, otherwise a target is only reselected after each "scan_interval" or "attack_interval".
scan_interval 10 Integer If "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.
set_persistent false Boolean Allows the entity to be set to persist upon targeting a player.
target_invisible_multiplier 0.70 Decimal Multiplied with the target's armor coverage percentage to modify "max_dist" when detecting an invisible target.
target_search_height -1.00 Decimal Maximum 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_sneak_visibility_multiplier 0.80 Decimal Multiplied with the target type's "max_dist" when trying to detect a sneaking target.
within_radius 0.0 Decimal Maximum 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".

Example

"minecraft:behavior.nearest_attackable_target":{
        "priority": 2,
        "must_see":true,
        "reselect_targets": true,
        "within_radius": 25.0,
        "entity_types":[
          {
            "filters":{
              "test": "is_family", "subject": "other", "value": "player"
            },
            "max_dist":32
          }
        ]
      }

Vanilla mob examples

Zombie

"minecraft:behavior.nearest_attackable_target": {
        "priority": 2,
        "must_see": true,
        "reselect_targets": true,
        "within_radius": 25.0,
        "must_see_forget_duration": 17.0,
        "entity_types": [
          {
            "filters": {
              "any_of": [
                { "test": "is_family", "subject": "other", "value": "player" },
                { "test": "is_family", "subject": "other", "value": "snowgolem" },
                { "test": "is_family", "subject": "other", "value": "irongolem" }
              ]
            },
            "max_dist": 35
          },
          {
            "filters": {
              "any_of": [
                { "test": "is_family", "subject": "other", "value": "villager" },
                { "test": "is_family", "subject": "other", "value": "wandering_trader" }
              ]
            },
            "max_dist": 35,
            "must_see": false
          },
          {
            "filters": {
              "all_of": [
                { "test": "is_family", "subject": "other", "value": "baby_turtle" },
                { "test": "in_water", "subject": "other", "operator": "!=", "value": true }
              ]
            },
            "max_dist": 35
          }
        ]
      }

Vanilla mobs using nearest_attackable_target