1. Wiki
  2. /Entities
  3. /Filters

Filters

How entity filters work in Minecraft Bedrock add-ons: test, subject, operator, value, all_of, any_of and none_of, plus a table of the most useful tests.

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).

Where filters appear
BP/
  entities/
    ruby_golem.json      <- in events and many components
  spawn_rules/
    ruby_golem.json      <- minecraft:biome_filter

One test

The smallest filter is a single test:

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?"

FieldWhat it meansIf you leave it out
testWhich question to ask. See the tables below.Required
subjectWho to ask aboutself
operatorHow to compare with valueequals
valueWhat to compare againstFor yes/no tests: true
domainExtra detail for a few tests, like an equipment slot or a property nameDepends on the test

Thanks to the defaults, short filters are common:

Short forms
{ "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

SubjectWho it is
selfThe mob that owns the filter
otherThe other entity in an interaction: the one being targeted, touched or interacted with
playerThe player involved in the interaction
targetThe mob's current target
damagerWhoever caused the damage, in a damage sensor
parentThe mob's parent
blockThe 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

OperatorMeans
==, =, equalsEqual to (the default)
!=, <>, notNot 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:

GroupPasses when
all_ofEvery test inside passes (AND)
any_ofAt least one test inside passes (OR)
none_ofNo 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:

A nested filter
"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

BP/entities/ruby_golem.json (components)
"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

BP/entities/ruby_golem.json (component_groups)
"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

BP/entities/ruby_golem.json (components)
"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?

TestValuePasses when the subject...
is_familyFamily name, like "player"has that family in minecraft:type_family
has_componentComponent ID, like "minecraft:is_baby"has that component right now
has_tagTag namehas that tag from /tag
is_babytrue / falseis a baby
is_tamedtrue / falseis tamed
is_ownertrue / falseis the owner of the mob that owns the filter
has_nametagtrue / falsehas a custom name
is_variantNumberhas that number in minecraft:variant
is_mark_variantNumberhas that number in minecraft:mark_variant
is_colorColor name, like "red"has that color

Health and state

TestValuePasses when the subject...
actor_healthNumberhas health compared with the value (use <, > etc.)
is_missing_healthtrue / falseis not at full health
has_mob_effectEffect ID, like "poison"has that effect. See Vanilla effects.
on_firetrue / falseis burning
on_groundtrue / falseis standing on the ground
is_sneakingtrue / falseis sneaking
is_sprintingtrue / falseis sprinting
is_movingtrue / falseis moving
is_ridingtrue / falseis riding another entity
rider_countNumberhas this many riders
has_targettrue / falsehas something to attack
has_damageDamage type, like "fall" or "fire"is taking that kind of damage (damage sensors)

Items

TestValuePasses when the subject...
has_equipmentItem IDhas that item in the slot named in domain, like "hand", "head" or "any"
has_equipment_tagItem taghas an item with that tag in the domain slot
has_ranged_weapontrue / falseholds a bow or crossbow

Where it is

TestValuePasses when the subject...
in_watertrue / falseis in water
is_underwatertrue / falseis fully under water
in_water_or_raintrue / falseis in water or rain
in_lavatrue / falseis in lava
is_undergroundtrue / falsehas blocks above it
in_nether / in_overworldtrue / falseis in that dimension
has_biome_tagBiome tag, like "desert"is in a biome with that tag. See Vanilla biomes.
is_biomeBiome type, like "ocean" or "jungle"is in that broad kind of biome
is_altitudeNumberis at a height compared with the value
is_blockBlock ID(with "subject": "block") the block involved is that block
is_in_villagetrue / falseis 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

TestValuePasses when...
distance_to_nearest_playerNumber of blocksthe nearest player is that far away (use < or >)
target_distanceNumber of blocksthe mob's target is that far away
owner_distanceNumber of blocksthe mob's owner is that far away
home_distanceNumber of blocksthe mob's home is that far away

Time, weather and the world

TestValuePasses when...
is_daytimetrue / falseit is day
hourly_clock_timeNumber from 0 to 24000the time of day compared with the value
moon_phaseNumber from 0 to 7the moon is in that phase
weather_at_positionWeather, like "thunderstorm"the weather where the subject stands matches
is_difficulty"peaceful", "easy", "normal" or "hard"the game is on that difficulty
is_game_ruletrue / falsethe game rule named in domain is on
random_chanceNumbera 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:

TestValue
bool_propertytrue / false
int_propertyWhole number
float_propertyDecimal number
enum_propertyOne of the words in values
has_propertyThe property name (in value, no domain)
Testing a property
{ "test": "enum_property", "domain": "wiki:mood", "value": "angry" }

When something goes wrong

What you seeMost likely cause
The filter never passesWrong subject. In a damage sensor or targeting, you usually want other, not self.
The filter passes when it should notA 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 failsThe family is not in the target's minecraft:type_family list
A property test failsThe property name in domain does not match the one in description.properties
A number test acts oddlyThe operator is missing, so it checks for an exact match

More help is in Troubleshooting.

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