Bedrock Wiki
  • Discord
  • Contribute
  • bedrock.dev
  • MS Learn
Beginner's Guide
  • Guide
    • 1. Introduction
      guide
    • 2. Add-Ons Explained
    • 3. Software & Preparation
    • 4. Project Setup
    • 5. Create a Custom Item
    • 6. Create a Custom Entity
    • 7. Blockbench: Modeling, Texturing & Animating
    • 8. Adding a Loot Table, Spawn Rule & Crafting Recipe
  • Extra
    • a. Understanding JSON
    • b. Download Example Packs
    • c. Troubleshooting
      help
    • d. Advanced Manifest
    • e. Format Versions
    • f. Project Setup Android
Animation Controllers
  • Intro to Animation Controllers
    guide
  • Entity Commands
  • AFK Detector
  • Death Commands
  • Molang into Scoreboard
  • Respawn Commands
Blocks
  • General
    • Intro to Blocks
      guide
    • Block Components
    • Block Tags
    • Block States
    • Block Traits
    • Block Permutations
    • Block Events
      Scripts
    • Block Event Migration
      help
    • Blocks as Items
    • Troubleshooting Blocks
      help
  • Visuals
    • Block Culling
    • Block Models
      guide
    • Block Texture Animation
    • Block Texture Variation
    • Block Tinting
  • Tutorials
    • Applying Constant Effects
      Scripts
    • Avoiding State Limit
    • Fake Blocks
      Scripts
    • Ore Loot Tables
      Scripts
    • Precise Interaction
      Scripts
    • Precise Rotation
      Scripts
    • Rotatable Blocks
  • Vanilla Re-Creations
    • Custom Crops
      Scripts
    • Custom Glass
    • Custom Glazed Terracotta
    • Custom Trapdoors
      Scripts
  • Documentation
    • Block Format History
    • Block Shapes
    • Block Sounds
    • Vanilla Block Models
Commands
  • General
    • Intro to Command Blocks
    • Functions
    • Block States
    • Coordinate System
    • NBT Commands
    • Scoreboard Operations
    • Understanding Selectors
  • Commands
    • Damage
    • Execute
    • Playanimation
    • Playsound
  • On Event Systems
    • On Player First Join
    • On Player Join
    • On Player Leave
    • On Player Death
    • On Player Respawn
    • On First World Load
  • Scoreboard Systems
    • Entity Counter
    • Scoreboard Timers
    • Comparing And Retrieving Scores
  • Techniques
    • Execute Logic Gates
    • MBE - Max's Block Entity
    • FMBE - A New Way to Create Display Entities
    • Look Detection
    • Movement Detections
    • Orbital Camera
  • Useful Creations
    • Custom Crafter
    • Multiplayer Position Rearrangement
      function
Concepts
  • contents.json
  • Emojis & Symbols
  • Molang
  • Namespaces
  • Overwriting Assets
  • Raw Text
  • Shaders
  • Sounds
  • Subpacks
  • Text and Localization
  • Texture Atlases
  • textures_list.json
Documentation
  • Shared Constructs
  • Advanced Molang
  • File Types
  • Fog IDs
  • Material Configuration Description
  • Menu Categories
  • Molang Queries
  • Pack Folder Structure
  • Sound Definitions
  • Vanilla Materials
Entities
  • General
    • Intro to Entities BP
      guide
    • Intro to Entities RP
      guide
    • Troubleshooting Entities
      help
    • Entity Events
    • Entity Properties
    • NPC Dialogues
    • Render Controllers
    • Spawn Rules
  • Tutorials
    • Convert Points Between Any Space (World, Entity, Bones)
    • Creating Boats
    • Detecting Other Entities
    • Disabling Team Damage
    • Dummy Entities
    • Entity Attacks
    • Entity Holds Item
    • Entity Movement
    • Entity Timers
    • Flying Entities
    • Introduction to AOE Clouds
    • Invulnerable Entities
    • Look at Entity
    • Sleeping Entities
    • Solid Entities
    • Spawning Tamed Entities
      Scripts
    • Village Mechanic
  • Documentation
    • Dummy Components
    • Non-Mob Runtime Identifiers
    • Projectiles
    • Runtime Identifiers
    • Vanilla Usage Components
    • Vanilla Usage Spawn Rules
Items
  • General
    • Intro to Items
      guide
    • Item Components
    • Item Tags
    • Item Events
      Scripts
    • Item Event Migration
      help
    • Troubleshooting Items
      help
  • Tutorials
    • Custom Armor
    • Custom Food
      Scripts
    • Custom Pottery Sherds
    • Custom Weapons
    • Equipment-Based Commands
    • High Resolution Items
    • Spawning Items
    • Throwable Items
  • Documentation
    • Enchantments
    • Attachables
    • Item Format History
    • Numerical Item IDs
    • Vanilla Item Identifiers
    • Vanilla Usage Components
JSON UI
  • General
    • Intro to JSON UI
      guide
    • Best Practices
      guide
  • Tutorials
    • Adding HUD Elements
    • Aseprite Animations
    • Buttons and Toggles
    • Modifying Server Forms
    • Preserve Title Texts
    • String to Number
  • Documentation
    • JSON UI Documentation
Loot, Recipes & Trading
  • General
    • Trading Behavior
  • Documentation
    • Loot Tables
    • Trade Tables
    • Recipes
    • Item Functions
  • Tutorials
    • Randomized Structure Loot
Meta
  • Add-On Performance
  • Style Guide
  • Useful Links
  • Using Schemas
  • Version Control
  • Q&A
    • Blocks and Items Q&A 2024/08/30
    • Deferred Technical Preview Q&A 2024/02/23
    • GameTest Q&A 2021/08/06
    • Scripting and Editor Q&A 2023/09/22
    • World Generation Q&A 2024/11/15
NBT
  • General
    • .mcstructure
  • Tutorials
    • Experiments in Minecraft Education
    • Extending Structure Limits
  • NBT in Depth
    • About NBT (Named Binary Tag)
    • NBT Libraries
    • Reading NBT Example
Particles
  • General
    • Intro to Particles
      guide
  • Tutorials
    • Disabling Particles
  • Documentation
    • Vanilla Particles
Scripting
  • General
    • Intro to Scripting
    • What is Script API?
    • API Modules
  • Tutorials
    • Block Placement Prevention
    • GameTests
    • Script Core Features
    • Script Forms
    • Script Requests API
    • Simple Chat Commands
  • Documentation
    • Engine Environment
    • Script Resources
    • Script Watchdog
    • Troubleshooting JavaScript
    • TypeScript
Servers
  • Software
    • Bedrock Server Software
  • Protocols
    • Bedrock Protocol
    • NetherNet Protocol
    • RakNet Protocol
Visuals
  • General
    • Introduction to Entity Visuals
      guide
    • Bedrock Modeling
    • Custom Death Animations
    • Effects in Animations
    • Material Creations
    • Materials
    • Math-Based Animations
    • Skin Packs
  • Tutorials
    • Entity Texture Animation
    • Glowing Entity Texture
    • Hurt Animations
    • Leash Position
    • Player Geometry
    • Remove Entity Shadows
    • Retexturing Spawn Eggs
  • Ideas
    • Structure Presentation
World Generation
  • General
    • Intro to World Generation
      guide
    • Biomes
      guide
    • Feature Types
    • Jigsaw Structures
  • Tutorials
    • Block Conditions for Features
    • Generating Custom Ores
    • Generating Custom Structures
    • Generating Patches
    • Heightmap Noise
  • Documentation
    • Biome Tags

Entity Attacks

intermediate
Entity Attacks
  • Selecting Targets
    • Movement
    • Triggering Hostility
    • Target selecting
  • Types of Attack
    • Melee
    • Ranged
    • Area
    • Knockback Roar
  • More on Attacks
    • Difficulty Dependant Attacks
    • Switching Modes
  • Visual Animations
    • Animations
    • Animation Controllers

Entity attacks are a complex subject that require many different things to work correctly:

  • Navigation and movement abilities to move towards its target
  • Targeting abilities to pick which entity to attack
  • Attack type, such as melee or ranged
  • Attack damage and effects

Selecting Targets ​

Movement ​

Before a mob can attack, it will need various movement components.

Before starting to create your entity attacks, you should ensure that your entity can walk around, and navigate its surroundings.

WARNING

Even if you are making an unmoving entity (like turret), you still need to add navigation component, so your entity can find the entity to shoot.

Triggering Hostility ​

There are many ways to trigger hostility. The most common type nearest_attackable_target, is shown here. It generally allows you to define which entities this entity is interested in attacking:

json
"minecraft:behavior.nearest_attackable_target": {
  "must_see": true, //If true, potential target must be in mob's line of sight
  "reselect_targets": true, //Allows mob to select new target, if one is closer than current
  "within_radius": 25.0, //Radius that potential target must be withing
  "must_see_forget_duration": 17.0, //If "must_see" = true, time before forgetting target
  "entity_types": [
    {
      "filters": { //Entities to attack
        "test": "is_family",
        "subject": "other",
        "value": "player"
      },
      "max_dist": 48.0
    }
  ]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

For more fine control, you may also consider using one of the following components:

ComponentNote
minecraft:behavior.nearest_attackable_targetTargets entity meeting the given requirements
minecraft:behavior.nearest_prioritized_attackable_targetAllows for "priority": [integer] to be set after each filter
minecraft:behavior.defend_trusted_targetTargets entity that hurts any entities specified in filters

But there is also one more - minecraft:lookat

This last component is slightly different to the other three, as it is for detecting and targeting entities that attempt eye contact. It is structured like so:

BP/entities/enderman.json
json
"minecraft:lookat": {
  "search_radius": 64.0,
  "set_target": true, //Becomes a valid target if true
  "look_cooldown": 5.0,
  "filters": {
    "all_of": [
      {
        "subject": "other",
        "test": "is_family",
        "value": "player"
      },
      {
        "test": "has_equipment",
        "domain": "head",
        "subject": "other",
        "operator": "not",
        "value": "carved_pumpkin"  //All players not with carved_pumpkin equipped on head
      }
    ]
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

Target selecting ​

TIP

This section shows you how to configure the "Targeting" components, explained above.

Mobs find targets by using filters can be used to determine which entities are a valid target, through test, subject, operator, and value.

json
"entity_types":[
    {
        "filters":{
            "any_of":[
                {
                    "test":"is_family",
                    "subject":"other",
                    "operator":"==",
                    "value":"snow_golem"
                },
                {
                    "test":"is_family",
                    "subject":"other",
                    "operator":"==",
                    "value":"iron_golem"
                }
                //anything that is equal to either" snow_golem" or "iron_golem"
            ]
        },
        "max_dist":24
    },
    {
        "filters":{
            "all_of":[
                {
                    "test":"is_family",
                    "subject":"other",
                    "operator":"==",
                    "value":"player"
                },
                {
                    "test":"has_equipment",
                    "subject":"other",
                    "domain":"head",
                    "operator":"=!",
                    "value":"turtle_helmet"
                }
                //anything equal to player AND not wearing "turtle_helmet" on head
            ]
        },
        "max_dist":24
    }
]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

This would only target snow_golems, iron_golems, and players that are not wearing turtle_helmets.

Types of Attack ​

Here are the available attacks:

ComponentNote
minecraft:behavior.melee_attackDeals damage to a single target
minecraft:behavior.ranged_attackFires a projectile towards a target
minecraft:area_attackEffectively melee attacks on anything withing range
minecraft:behavior.knockback_roarSimilar to minecraft:area_attack, but much more flexible

Melee ​

Melee attacks are the most common type of attack, they cause knockback, and have a 100% success rate at accuracy.

json
"wiki:melee_attack": {
  "minecraft:attack": {
    "damage": 3,
    "effect_name": "slowness",
    "effect_duration": 20
  },
  "minecraft:behavior.melee_attack": {
    "priority": 3,
    "melee_fov": 90.0, //The allowable FOV the actor will use to determine if it can make a valid melee attack
    "speed_multiplier": 1,
    "track_target": false,
    "require_complete_path": true
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

Set the damage, choose a mob effect, and change some additional properties.

The value defined in components stating integers of damage can simply be a constant, or a string containing 2 numbers, for a range of possible values.

"damage": 3 would result in 3 each time

"damage": [ 2, 6 ] would result in any integer between 2 and 6

Both the mob effect and duration timer are optional, but when they are used, the available effects are as following:

Effect Name
speed
slowness
haste
mining_fatigue
strength
instant_health
instant_damage
jump_boost
nausea
regeneration
resistance
fire_resistance
water_breathing
invisibility
blindness
night_vision
hunger
weakness
poison
wither
health_boost
absorption
saturation
levitation
fatal_poison
slow_falling
conduit_power
bad_omen
village_hero
darkness

Ranged ​

Fires specified projectiles towards target at set intervals.

json
"wiki:ranged_attack": {
  "minecraft:behavior.ranged_attack": {
    "priority": 2,
    "ranged_fov": 90.0, //The allowable FOV the actor will use to determine if it can make a valid ranged attack
    "attack_interval_min": 1.0,
    "attack_interval_max": 3.0,
    "attack_radius": 15.0
  },
  "minecraft:shooter": {
    "def": "wiki:projectile"
  }
}
1
2
3
4
5
6
7
8
9
10
11
12

List of vanilla projectiles:

Vanilla Projectiles
minecraft:arrow
minecraft:dragon_fireball
minecraft:egg
minecraft:ender_pearl
minecraft:fireball
minecraft:fishing_hook
minecraft:lingering_potion
minecraft:llama_spit
minecraft:skulker_bullet
minecraft:small_fireball
minecraft:snowball
minecraft:splash_potion
minecraft:thrown_trident
minecraft:wither_skull
minecraft:wither_skull_dangerous
minecraft:xp_bottle

Only one item has an effect on an entity's ranged attacks. Crossbows. If one is equipped, it is first required for it to be "charged" before the entity can fire anything. Regardless of the projectile stated in minecraft:shooter, the item to charge the crossbow with should always be minecraft:arrow.

json
"minecraft:behavior.charge_held_item": {
  "priority": 2,
  "items": [
    "minecraft:arrow"
  ]
}
1
2
3
4
5
6

Once minecraft:behavior.charge_held_item has been achieved, the entity will be able to execute the process of minecraft:behavior.ranged_attack, and will then need to charge again.

Area ​

These attacks damage all entities within a set radius. It is different to both ranged and melee in that this component doesn’t actually require a target. Regardless of the entities behaviour, all entities will be affected by this. It appears to be similar to melee attacks, as it deals knockback in a similar manner, though dealing damage at a constant rate.

json
"minecraft:area_attack" : {
  "damage_range": 1, //distance in blocks
  "damage_per_tick": 2,
  "cause": "contact",
  "entity_filter": {
     "any_of": [
      {
        "test": "is_family",
        "subject": "other",
        "value": "player"
      },
      {
        "test": "is_family",
        "subject": "other",
        "value": "monster"
      }
    ]
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

Entity damage sources. It is important to take these into consideration, as certain items in vanilla can protect from some, like armour enchantments, and you can also make mobs immune to specific sources using minecraft:damage_sensor.

Knockback Roar ​

Many similarities between this and minecraft:area_attack, this component though having much more flexibility.

json
"wiki:roar_attack": {
  "minecraft:behavior.knockback_roar":{
    "priority":2,
    "duration":0.7,
    "attack_time":0.2,
    "knockback_damage":1,
    "knockback_horizontal_strength":1,
    "knockback_vertical_strength":1,
    "knockback_range":5,
    "knockback_filters":{
      "test":"is_family",
      "subject":"other",
      "operator":"==",
      "value":"player"
    },
    "damage_filters":{
      "test":"is_family",
      "subject":"other",
      "operator":"==",
      "value":"player"
    },
    "on_roar_end":{
      "event":"wiki:other_event"
    },
    "cooldown_time":10
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

This is more like a shockwave of damage. Extremely versatile in uses. Produces a particle effect, which can be disabled by adding a modified version of knockback_roar.json to a resource pack's particles folder.

More on Attacks ​

Entity Attacks don't have to be as simple as Mob being hostile towards X target, doing X attack, dealing X damage.

Difficulty Dependant Attacks ​

Express components and values to use for each difficulty.

BP/entities/bee.json
json
"easy_attack": {
    "minecraft:attack": {
        "damage": 2
    }
},
"normal_attack": {
    "minecraft:attack": {
        "damage": 2,
        "effect_name": "poison",
        "effect_duration": 10
    }
},
"hard_attack": {
    "minecraft:attack": {
        "damage": 2,
        "effect_name": "poison",
        "effect_duration": 18
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

Switching Modes ​

You can use events to make your mob only attack under specific circumstances, or swap between the different types of attack. This can be achieved through simple usage of events and component groups. Two prime examples being minecraft:environment_sensor and minecraft:target_nearby_sensor. The two are pretty similar in regards of structure, difference being that one is for sensing environments and the other for testing for target distance.

Attacks ​

Component groups are required to define the different modes of attack, such as:

json
"wiki:ranged_components": {
  "minecraft:shooter": {
    "def": "wiki:projectile"
  },
  "minecraft:behavior.ranged_attack": {
    "priority": 3,
    "ranged_fov": 90.0,
    "attack_interval_min": 1.0,
    "attack_interval_max": 3.0,
    "attack_radius": 15.0
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
json
"wiki:melee_components": {
  "minecraft:attack": {
    "damage": 6
  },
  "minecraft:behavior.melee_attack": {
    "priority": 3
  }
}
1
2
3
4
5
6
7
8

Those are examples of your attack modes, but they are not the only ones you can use. wiki:ranged_components and wiki:melee_components are generic names for the components within them, they can have any name, but it's what's nested inside them that counts.

Events ​

These component groups won't actually do anything by themselves. Another component group is required, and some events to add/remove the attack modes.

json
"wiki:melee_swap": {    //When triggered, adds component group for ranged and removes melee component group
  "remove": {
    "component_groups": [
      "wiki:ranged_components"
    ]
  },
  "add": {
    "component_groups": [
      "wiki:melee_components"
    ]
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
json
"wiki:ranged_swap": {   //When triggered, adds component group for melee and removes ranged component group
  "remove": {
    "component_groups": [
      "wiki:melee_components"
    ]
  },
  "add": {
    "component_groups": [
      "wiki:ranged_components"
    ]
  }
}
1
2
3
4
5
6
7
8
9
10
11
12

The events are effectively for just turning attack modes on and off, by adding and removing different component groups.

Sensors ​

To trigger the events, another component group is used. Sensors are components that can trigger events when certain conditions are fulfilled. Here are 2 examples of different sensors:

  • For sensing the distance between the mob and target
json
"wiki:switcher_range": {
  "minecraft:target_nearby_sensor": {
    "inside_range": 4.0,
    "outside_range": 5.0,
    "must_see":  true,
    "on_inside_range": { //When target is within 4 blocks range, trigger "wiki:melee_swap" event
      "event": "wiki:melee_swap",
      "target": "self"
    },
    "on_outside_range": { //When target is beyond 5 blocks range, trigger "wiki:ranged_swap" event
      "event": "wiki:ranged_swap",
      "target": "self"
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  • For sensing certain features of the environment of which the mob is exposed to
json
"wiki:switcher_environment": {
  "minecraft:environment_sensor": {
    "triggers": [
      {
        "filters": { //When underwater, trigger "wiki:melee_swap" event
          "test": "is_underwater",
          "subject": "self",
          "operator": "==",
          "value": true
        },
        "event": "wiki:melee_swap"
      },
      {
        "filters": { //When not underwater, trigger "wiki:ranged_swap" event
          "test": "is_underwater",
          "subject": "self",
          "operator": "==",
          "value": false
        },
        "event": "wiki:ranged_swap"
      }
    ]
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

This uses Filters, similar to how the target is initially selected.

TIP

You aren't limited to just 2 attack types, you can have as many as you want! Just make sure to have the event's and sensors to compensate for them.

Visual Animations ​

Attacks and animations go hand in hand. Within resource packs, the following 3 directories are required:

  • animations (entityname.animation.json)
  • animation_controllers (entityname.animation_controller.json)
  • entity (entityname.json)

Or as long as you know the names of vanilla animations and animation controllers, you can define them in the latter directory and folder.

Animations ​

Animations are self explanatory. The files themselves contain all specific animations for the given entity. The recommended way to make animations is by using blockbench.

Though it is possible to create them in a simple text editor.

Vanilla Attack Animations
"animation.zombie.attack_bare_hand"
"animation.skeleton.attack.v1.0"
"animation.humanoid.bow_and_arrow.v1.0"
"animation.humanoid.damage_nearby_mobs.v1.0"

A few examples of Animations. Locate /vanilla_resource_pack/animations for all of them.

Animation Controllers ​

List of states that trigger animations.

Vanilla Attack Animation Controllers
"controller.animation.zombie.attack_bare_hand"
"controller.animation.skeleton.attack"
"controller.animation.humanoid.bow_and_arrow"
"controller.animation.humanoid.attack"

A few examples of Animation Controllers. Locate /vanilla_resource_pack/animation_controllers for all of them

More information on animations can be found here.

Contributors

Edit Entity Attacks on GitHub

Bedrock Wiki by Bedrock OSS

"Minecraft" is a trademark of Mojang AB.

Bedrock OSS, Bedrock Wiki and bedrock.dev are not affiliated in any way with Microsoft or Mojang AB.

  • Privacy Policy
  • Join our Discord
  • Learn how to Contribute
  • Visit our Repository