1. Wiki
  2. /Entities
  3. /minecraft:behavior.nearest_attackable_target

minecraft:behavior.nearest_attackable_target

Don't want to write this by hand? GodCraft sets minecraft:behavior.nearest_attackable_target for you with a switch.Get GodCraft

Overview

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

FieldTypeDefaultDescription
reselect_targetsbooleanfalseIf true, the mob switches to a closer target when one appears instead of waiting for the next scan.
attack_intervalFloatRange{"max":0,"min":0}Random time range, in seconds, between target searches. Leave it at 0 to use scan_interval instead.
scan_intervalinteger10Ticks between target searches when attack_interval is not used. Very small values can slow the game down.Range: 1 to …
target_search_heightnumber-1How far up and down to look for targets. A negative value uses the biggest max_dist from entity_types.Range: -1 to …
target_invisible_multipliernumber0.7Shrinks the detection range for invisible targets, based on how much armor they wear.
target_sneak_visibility_multipliernumber0.8Multiplies the detection range when the target is sneaking. Use a value below 1 so sneaking players are harder to spot.
set_persistentbooleanfalseIf true, the mob will not despawn after it targets a player.
target_acquisition_probabilitynumber1Chance (0 to 1) that the mob actually picks a target it found. Lower it to make the mob less aggressive.
attack_ownerbooleanfalseIf true, a tamed mob can attack its own owner.
must_reachbooleanfalseIf true, the mob only picks targets it can walk to.
must_seebooleanfalseIf true, the mob must be able to see the target, not just be in range.
within_radiusnumber0How 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_durationnumber3Seconds the target can stay out of sight before the mob forgets it. Only used when must_see is true.Range: 0 to …
persist_timenumber0Seconds the mob keeps attacking after the target stops being valid.Range: 0 to …
entity_typesEntityTypesnoneWhich entities the mob may target, each with filters and an optional max distance.
priorityinteger0Decides which goal wins when several want to run: lower numbers run first.Range: 0 to …
control_flagsGoal's control flags[]noneLists 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
  }
}

We use cookies to improve your experience and analyse site traffic. Learn more