minecraft:behavior.nearest_attackable_target
Allows an entity to attack the closest target within a given subset of specific target types.
Properties
| Property | Type | Default | What it does |
|---|---|---|---|
reselect_targets | Boolean | false | Allows the attacking entity to update the nearest target, otherwise a target is only reselected after each "scan_interval" or "attack_interval". |
attack_interval | Object | {"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. |
min | Decimal | 0 | |
max | Decimal | 0 | |
scan_interval | Integermin 1 | 10 | 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. |
target_search_height | Decimalmin -1 | -1 | 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_invisible_multiplier | Decimal | 0.7 | Multiplied with the target's armor coverage percentage to modify "max_dist" when detecting an invisible target. |
target_sneak_visibility_multiplier | Decimal | 0.8 | Multiplied with the target type's "max_dist" when trying to detect a sneaking target. |
set_persistent | Boolean | false | Allows the actor to be set to persist upon targeting a player |
target_acquisition_probability | Decimal | 1 | Probability (0.0 to 1.0) that this entity will accept a found target. Checked each time a valid target is found during scanning. |
attack_owner | Boolean | false | If true, this entity can attack its owner. |
must_reach | Boolean | false | If true, this entity requires a path to the target. |
must_see | Boolean | false | Determines if target-validity requires this entity to be in range only, or both in range and in sight. |
within_radius | Decimalmin 0 | 0 | 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". |
must_see_forget_duration | Decimalmin 0 | 3 | Time (in seconds) the target must not be seen by this entity to become invalid. Used only if "must_see" is true. |
persist_time | Decimalmin 0 | 0 | Time (in seconds) this entity can continue attacking the target after the target is no longer valid. |
entity_types | List of object or Object | [] | Filters which types of targets are valid for this entity. |
filters | Object or List of object | {"AND": null, "NOT": null, "OR": null, "all": null, "all_… | Conditions that make this entry in the list valid |
max_dist | Decimal | 16 | Maximum distance this mob can be away to be a valid choice |
max_height | Decimal | -1 | Maximum height this mob can be away to be a valid choice |
max_flee | Decimal | 10 | Maximum distance this mob can be from the target to stop fleeing |
walk_speed_multiplier | Decimal | 1 | Multiplier for the walking speed. A value of 1.0 means the speed is unchanged |
sprint_speed_multiplier | Decimal | 1 | Multiplier for the sprinting speed. A value of 1.0 means the speed is unchanged |
priority | Integer | 0 | Priority for this mob type |
check_if_outnumbered | Boolean | false | If true, the mob will check if its outnumbered |
reevaluate_description | Boolean | false | If true, the mob will stop being targeted if it stops meeting any conditions. |
cooldown | Integer | 0 | The amount of time in seconds that the mob has to wait before selecting a target of the same type again |
must_see | Boolean | — | If true, the mob has to be visible to be a valid choice |
must_see_forget_duration | Integer | 3 | Determines 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 |
priority | Integermin 0 | 0 | |
control_flags | List 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:
AxolotlBeeBlazeBoggedBreezeCatCave SpiderCreeperDrownedElder GuardianEndermanEndermiteEvokerFrogGhastGoatGuardianHoglinHuskIron GolemLlamaMagma CubeNautilusOcelotParchedPhantomPiglinPiglin BrutePillagerPolar BearRavagerShulkerSilverfishSkeletonSlimeSnow GolemSpiderStrayTrader LlamaVexVindicatorWitherWither SkeletonWolfZoglinZombieZombie NautilusZombie VillagerZombie Villager
Related components
behavior.melee_box_attackbehavior.ranged_attackbehavior.stomp_turtle_eggbehavior.leap_at_targetbehavior.nearest_prioritized_attackable_targetbehavior.aquatic_charge_attackbehavior.charge_held_itembehavior.guardian_attackbehavior.ocelotattackbehavior.slime_attackbehavior.charge_attackbehavior.delayed_attackbehavior.dragonchargeplayerbehavior.dragonflamingbehavior.dragonstrafeplayerbehavior.fire_at_targetbehavior.knockback_roarbehavior.melee_attackbehavior.ram_attackbehavior.roarbehavior.send_eventbehavior.sonic_boombehavior.stomp_attackbehavior.summon_entity