Blocking Damage with the Damage Sensor
The primary mechanism for making an entity immune to harm is the `minecraft:damage_sensor` component. Whenever an entity is about to take damage from any source—whether it is a player's sword, a TNT explosion, or starvation—the game passes the damage event through this sensor before subtracting health. By setting up a trigger that catches every damage type and tells the game not to deal damage, the entity becomes impervious to health loss.
Inside the component, the `triggers` array accepts objects that filter incoming hits. Setting `deals_damage` to `false` cancels the health reduction, prevents the entity from flashing red, and suppresses the standard hurt sound and knockback associated with the hit. If you omit the `on_damage` filter or set the `cause` to `all`, the rule applies universally to every damage source in the game.
| Field | What it does | Notes |
|---|---|---|
| cause | Specifies which damage source triggers this rule. | Use 'all' to catch every possible damage type, or specific strings like 'fall', 'fire', or 'entity_attack'. |
| deals_damage | Determines if the incoming hit reduces health. | Accepts a boolean. When false, the hit is completely ignored by the health component. |
| on_damage | Defines filters and an event to fire when hit. | Optional. Useful when you want the entity to ignore damage except from a specific player or tool. |
{
"format_version": "1.20.40",
"minecraft:entity": {
"description": {
"identifier": "custom:quest_npc",
"is_spawnable": true,
"is_summonable": true
},
"components": {
"minecraft:health": {
"value": 20,
"max": 20
},
"minecraft:damage_sensor": {
"triggers": [
{
"cause": "all",
"deals_damage": false
}
]
}
}
}
}Handling the Void and the Kill Command
Even with `deals_damage` set to `false` for `all` causes, there are two ways an entity can usually still be destroyed: falling into the void below the world, and being targeted by the `/kill` command. Both of these apply the `void` and `suicide` or ` magic` damage causes under the hood, bypassing normal armor and health calculations to force entity cleanup.
In modern Bedrock versions, a damage sensor with `"cause": "all"` and `"deals_damage": false` will actually prevent `/kill` from working on your entity. While this guarantees absolute invulnerability, it quickly becomes frustrating during development or map maintenance when you cannot remove a test mob. Furthermore, if an invulnerable entity falls into the void, it will fall forever or sit at the bottom of the void taking zero damage, consuming server resources.
To keep your entities manageable, put a specific trigger for `void` and `suicide` above your catch-all trigger. Because Bedrock evaluates the `triggers` array from top to bottom and stops at the first match, placing an exception at the top allows `/kill` and the void to function normally while blocking everything else.
{
"minecraft:damage_sensor": {
"triggers": [
{
"cause": "void",
"deals_damage": true
},
{
"cause": "suicide",
"deals_damage": true
},
{
"cause": "all",
"deals_damage": false
}
]
}
}Allowing Creative Mode or Specific Item Removal
For custom furniture, statues, or vehicles, you generally want the entity to be invulnerable to survival hazards like Creepers or stray arrows, but still removable by a player in Creative mode or someone holding a specific tool (like a wrench). You can achieve this by combining `deals_damage: false` with an `on_damage` filter that triggers an instant despawn event.
Instead of letting the player beat the entity to death over several hits, the sensor blocks all health damage, checks if the attacker meets your criteria via a filter, and then fires an event that activates `minecraft:instant_despawn`. This removes the entity cleanly in a single click without playing death animations or dropping corpse smoke.
{
"format_version": "1.20.40",
"minecraft:entity": {
"description": {
"identifier": "custom:statue",
"is_spawnable": true,
"is_summonable": true
},
"component_groups": {
"custom:despawn_group": {
"minecraft:instant_despawn": {}
}
},
"components": {
"minecraft:health": {
"value": 1,
"max": 1
},
"minecraft:damage_sensor": {
"triggers": [
{
"on_damage": {
"filters": {
"all_of": [
{
"test": "is_family",
"subject": "other",
"value": "player"
},
{
"test": "has_ability",
"subject": "other",
"value": "instabuild"
}
]
},
"event": "custom:remove_entity"
},
"deals_damage": false
},
{
"cause": "all",
"deals_damage": false
}
]
}
},
"events": {
"custom:remove_entity": {
"add": {
"component_groups": [
"custom:despawn_group"
]
}
}
}
}
}Preventing Knockback, Pushing, and Fire Visuals
An entity that takes no damage can still be pushed around by pistons, water currents, or players walking into it. It can also catch fire visually when walking through lava, even if the fire deals no damage. To make an entity feel truly solid and impervious, you need to lock down its physical and environmental properties alongside the damage sensor.
Use `minecraft:pushable` with both boolean flags set to `false` so neither mobs nor pistons can shove the entity out of place. Add `minecraft:fire_immune` so the entity does not display the burning flame overlay when exposed to fire or lava. Finally, adding `minecraft:knockback_resistance` with a value of `1.0` ensures that any edge-case effects, such as explosions or wind charges that apply impulse outside the standard damage pipeline, fail to move the entity.
{
"components": {
"minecraft:fire_immune": {},
"minecraft:knockback_resistance": {
"value": 1.0
},
"minecraft:pushable": {
"is_pushable": false,
"is_pushable_by_piston": false
},
"minecraft:physics": {
"has_gravity": true,
"has_collision": true
}
}
}Untargetable Marker Entities
Sometimes an entity does not need to be hit at all. If you are making an invisible marker, a floating text display, or a visual effect anchor, using a damage sensor is unnecessary overhead if you simply remove the entity's hitbox. When an entity has a collision box with zero width and height, swings and projectiles pass right through it.
Set both `width` and `height` to `0.0` in `minecraft:collision_box`, and disable gravity and collision in `minecraft:physics`. Pair this with a damage sensor anyway so area-of-effect damage like explosions or potions cannot destroy the marker.
{
"components": {
"minecraft:collision_box": {
"width": 0.0,
"height": 0.0
},
"minecraft:physics": {
"has_collision": false,
"has_gravity": false
},
"minecraft:pushable": {
"is_pushable": false,
"is_pushable_by_piston": false
},
"minecraft:damage_sensor": {
"triggers": [
{
"cause": "all",
"deals_damage": false
}
]
}
}
}Which versions this applies to
Applies to all modern Bedrock versions (1.16.0 through 1.21+). All components shown (`minecraft:damage_sensor`, `minecraft:pushable`, `minecraft:fire_immune`, `minecraft:knockback_resistance`, `minecraft:instant_despawn`) are stable and do not require any experimental toggles.
When it does not work
| What you see | Why | The fix |
|---|---|---|
| Running `/kill @e[type=custom:quest_npc]` says 'Killed Quest NPC' in chat, but the entity is still standing there alive. | Your `minecraft:damage_sensor` has a trigger with `"cause": "all"` and `"deals_damage": false`, which blocks the `suicide` and `void` damage causes used by the `/kill` command. | Add a trigger at the very top of your `triggers` array for `"cause": "suicide"` and `"cause": "void"` with `"deals_damage": true`. If the entity is already stuck in your world, use `/event entity @e[type=custom:quest_npc] <your_despawn_event>` or edit the behavior pack and reload the world. |
| The Creative mode removal event never fires when hitting the entity, even though the filters are correct. | In the `triggers` array of `minecraft:damage_sensor`, the catch-all `"cause": "all"` object was placed above the specific `on_damage` trigger. The game stops evaluating the array at the first matching trigger. | Move your specific triggers (like player attack filters or environmental checks) to the top of the `triggers` list, and always leave the generic `"cause": "all"` fallback as the very last item in the array. |
| Content Log Error: `[Json][error] minecraft:entity -> components -> minecraft:damage_sensor: triggers must be an array or object` or the sensor simply does not work. | You placed `cause` and `deals_damage` directly inside `minecraft:damage_sensor` instead of wrapping them inside the `triggers` array. | Ensure `cause`, `deals_damage`, and `on_damage` are nested inside `"triggers": [ { ... } ]` within the `minecraft:damage_sensor` component. |
Reference, straight from the game files
Read out of the game itself, so the ids match the version you are building for.
