minecraft:behavior.nearest_attackable_target for you with a switch.Get GodCraftOverview
minecraft:behavior.nearest_attackable_target is an entity component: it goes in the components object of a custom mob, or in one of its component groups. Picks the closest valid target from the entity types you list and makes the mob go after it. This is the usual goal for hostile mobs that hunt players or other mobs.
Fields
| Field | Type | Default | Description |
|---|---|---|---|
reselect_targets | boolean | false | If true, the mob switches to a closer target when one appears instead of waiting for the next scan. |
attack_interval | FloatRange | {"max":0,"min":0} | Random time range, in seconds, between target searches. Leave it at 0 to use scan_interval instead. |
scan_interval | integer | 10 | Ticks between target searches when attack_interval is not used. Very small values can slow the game down.Range: 1 to … |
target_search_height | number | -1 | How far up and down to look for targets. A negative value uses the biggest max_dist from entity_types.Range: -1 to … |
target_invisible_multiplier | number | 0.7 | Shrinks the detection range for invisible targets, based on how much armor they wear. |
target_sneak_visibility_multiplier | number | 0.8 | Multiplies the detection range when the target is sneaking. Use a value below 1 so sneaking players are harder to spot. |
set_persistent | boolean | false | If true, the mob will not despawn after it targets a player. |
target_acquisition_probability | number | 1 | Chance (0 to 1) that the mob actually picks a target it found. Lower it to make the mob less aggressive. |
attack_owner | boolean | false | If true, a tamed mob can attack its own owner. |
must_reach | boolean | false | If true, the mob only picks targets it can walk to. |
must_see | boolean | false | If true, the mob must be able to see the target, not just be in range. |
within_radius | number | 0 | How far the target can get before the mob gives up. Only used if the mob has no minecraft:follow_range.Range: 0 to … |
must_see_forget_duration | number | 3 | Seconds the target can stay out of sight before the mob forgets it. Only used when must_see is true.Range: 0 to … |
persist_time | number | 0 | Seconds the mob keeps attacking after the target stops being valid.Range: 0 to … |
entity_types | EntityTypes | none | Which entities the mob may target, each with filters and an optional max distance. |
priority | integer | 0 | Decides which goal wins when several want to run: lower numbers run first.Range: 0 to … |
control_flags | Goal's control flags[] | none | Lists the body parts this goal takes control of (such as move, look or jump), so goals that need the same part don't run together. |
Example
Inside the components object of BP/entities/<name>.json (values are the defaults or placeholders):
BP/entities/<name>.json
{
"minecraft:behavior.nearest_attackable_target": {
"reselect_targets": false,
"attack_interval": {
"max": 0,
"min": 0
},
"scan_interval": 10,
"target_search_height": -1,
"target_invisible_multiplier": 0.7,
"target_sneak_visibility_multiplier": 0.8,
"set_persistent": false,
"target_acquisition_probability": 1
}
}