A filter is a yes-or-no question the game asks about a mob. "Is the attacker a player?" "Is it daytime?" "Is this mob in water?" If the answer is yes, the filter passes and whatever it guards is allowed to happen.
Filters show up all over a mob's files: in events, in components like damage sensors and targeting, and in spawn rules. Learn them once and you can use them everywhere.
The files
Filters are not a file of their own. They sit inside other files, under keys called filters (or biome_filter in spawn rules).
BP/
entities/
ruby_golem.json <- in events and many components
spawn_rules/
ruby_golem.json <- minecraft:biome_filterOne test
The smallest filter is a single test:
{ "test": "is_family", "subject": "other", "operator": "==", "value": "player" }Read it as a sentence: "Is the other entity's family equal to player?"
| Field | What it means | If you leave it out |
|---|---|---|
test | Which question to ask. See the tables below. | Required |
subject | Who to ask about | self |
operator | How to compare with value | equals |
value | What to compare against | For yes/no tests: true |
domain | Extra detail for a few tests, like an equipment slot or a property name | Depends on the test |
Thanks to the defaults, short filters are common:
{ "test": "is_daytime" }
{ "test": "in_water", "value": false }
{ "test": "has_tag", "value": "wiki:tamed" }The first one asks "is it daytime?". The second asks "is this mob not in water?".
Subjects: who is being tested
| Subject | Who it is |
|---|---|
self | The mob that owns the filter |
other | The other entity in an interaction: the one being targeted, touched or interacted with |
player | The player involved in the interaction |
target | The mob's current target |
damager | Whoever caused the damage, in a damage sensor |
parent | The mob's parent |
block | The block involved, for block tests like is_block |
Which subjects make sense depends on where the filter is. In a damage sensor, other and damager are the attacker. In a targeting behavior, other is the mob being considered as a target.
Operators: how to compare
| Operator | Means |
|---|---|
==, =, equals | Equal to (the default) |
!=, <>, not | Not equal to |
< | Less than |
<= | Less than or equal to |
> | Greater than |
>= | Greater than or equal to |
The greater/less operators only make sense for number tests like actor_health or distance_to_nearest_player.
Combining tests
Put several tests together with a group:
| Group | Passes when |
|---|---|
all_of | Every test inside passes (AND) |
any_of | At least one test inside passes (OR) |
none_of | No test inside passes (NOT) |
Groups can hold other groups, so you can build any rule you need. This one passes for a player who is not sneaking, at night or in a thunderstorm:
"filters": {
"all_of": [
{ "test": "is_family", "subject": "other", "value": "player" },
{ "test": "is_sneaking", "subject": "other", "value": false },
{
"any_of": [
{ "test": "is_daytime", "value": false },
{ "test": "weather_at_position", "value": "thunderstorm" }
]
}
]
}A bare list means all_of
If you write a plain list of tests without a group name, every test must pass, just like all_of. Vanilla spawn rules often do this.
Where filters are used
Damage sensor: react to who hit you
"minecraft:damage_sensor": {
"triggers": [
{
"on_damage": {
"filters": { "test": "is_family", "subject": "other", "value": "player" },
"event": "wiki:become_angry"
}
}
]
}Only players make the golem angry. Damage from mobs, falls or fire does nothing special. See minecraft:damage_sensor.
Targeting: who to attack
"minecraft:behavior.nearest_attackable_target": {
"priority": 2,
"entity_types": [
{
"filters": {
"all_of": [
{ "test": "is_family", "subject": "other", "value": "monster" },
{ "test": "is_family", "subject": "other", "operator": "not", "value": "creeper" }
]
},
"max_dist": 16
}
]
}The golem hunts monsters, but leaves creepers alone. See behavior.nearest_attackable_target.
Environment sensor: react to the world
"minecraft:environment_sensor": {
"triggers": [
{
"filters": { "test": "in_water" },
"event": "wiki:start_rusting"
}
]
}The environment sensor checks its filters all the time and fires the event while they pass.
Events and spawn rules
Inside events, filters decide whether an entry runs (see Entity events). In spawn rules, minecraft:biome_filter uses the same tests to pick biomes (see Spawn rules).
The most useful tests
There are over a hundred tests. These are the ones you will reach for most often, grouped by what they check.
Who is it?
| Test | Value | Passes when the subject... |
|---|---|---|
is_family | Family name, like "player" | has that family in minecraft:type_family |
has_component | Component ID, like "minecraft:is_baby" | has that component right now |
has_tag | Tag name | has that tag from /tag |
is_baby | true / false | is a baby |
is_tamed | true / false | is tamed |
is_owner | true / false | is the owner of the mob that owns the filter |
has_nametag | true / false | has a custom name |
is_variant | Number | has that number in minecraft:variant |
is_mark_variant | Number | has that number in minecraft:mark_variant |
is_color | Color name, like "red" | has that color |
Health and state
| Test | Value | Passes when the subject... |
|---|---|---|
actor_health | Number | has health compared with the value (use <, > etc.) |
is_missing_health | true / false | is not at full health |
has_mob_effect | Effect ID, like "poison" | has that effect. See Vanilla effects. |
on_fire | true / false | is burning |
on_ground | true / false | is standing on the ground |
is_sneaking | true / false | is sneaking |
is_sprinting | true / false | is sprinting |
is_moving | true / false | is moving |
is_riding | true / false | is riding another entity |
rider_count | Number | has this many riders |
has_target | true / false | has something to attack |
has_damage | Damage type, like "fall" or "fire" | is taking that kind of damage (damage sensors) |
Items
| Test | Value | Passes when the subject... |
|---|---|---|
has_equipment | Item ID | has that item in the slot named in domain, like "hand", "head" or "any" |
has_equipment_tag | Item tag | has an item with that tag in the domain slot |
has_ranged_weapon | true / false | holds a bow or crossbow |
Where it is
| Test | Value | Passes when the subject... |
|---|---|---|
in_water | true / false | is in water |
is_underwater | true / false | is fully under water |
in_water_or_rain | true / false | is in water or rain |
in_lava | true / false | is in lava |
is_underground | true / false | has blocks above it |
in_nether / in_overworld | true / false | is in that dimension |
has_biome_tag | Biome tag, like "desert" | is in a biome with that tag. See Vanilla biomes. |
is_biome | Biome type, like "ocean" or "jungle" | is in that broad kind of biome |
is_altitude | Number | is at a height compared with the value |
is_block | Block ID | (with "subject": "block") the block involved is that block |
is_in_village | true / false | is inside a village |
has_biome_tag or is_biome?
Prefer has_biome_tag. Tags are more precise, and custom biomes from other add-ons can carry the same tags.
Distance
| Test | Value | Passes when... |
|---|---|---|
distance_to_nearest_player | Number of blocks | the nearest player is that far away (use < or >) |
target_distance | Number of blocks | the mob's target is that far away |
owner_distance | Number of blocks | the mob's owner is that far away |
home_distance | Number of blocks | the mob's home is that far away |
Time, weather and the world
| Test | Value | Passes when... |
|---|---|---|
is_daytime | true / false | it is day |
hourly_clock_time | Number from 0 to 24000 | the time of day compared with the value |
moon_phase | Number from 0 to 7 | the moon is in that phase |
weather_at_position | Weather, like "thunderstorm" | the weather where the subject stands matches |
is_difficulty | "peaceful", "easy", "normal" or "hard" | the game is on that difficulty |
is_game_rule | true / false | the game rule named in domain is on |
random_chance | Number | a random roll hits: a value of 10 passes about 1 time in 10 |
Entity properties
These read the properties declared in the mob's description. The property name goes in domain:
| Test | Value |
|---|---|
bool_property | true / false |
int_property | Whole number |
float_property | Decimal number |
enum_property | One of the words in values |
has_property | The property name (in value, no domain) |
{ "test": "enum_property", "domain": "wiki:mood", "value": "angry" }When something goes wrong
| What you see | Most likely cause |
|---|---|
| The filter never passes | Wrong subject. In a damage sensor or targeting, you usually want other, not self. |
| The filter passes when it should not | A yes/no test is missing "value": false where you meant "not", or a key is misspelled (like allof). Check the Content Log. |
| A family test fails | The family is not in the target's minecraft:type_family list |
| A property test fails | The property name in domain does not match the one in description.properties |
| A number test acts oddly | The operator is missing, so it checks for an exact match |
More help is in Troubleshooting.