Wiki 9Minecraft Wiki 9Minecraft

Molang Queries Reference Table

Read-only game state functions for entity animations, controllers, blocks, and particles.

6Sections
3Code examples
4Known errors

Molang queries are built-in functions that read live values from an entity, block, item, or the world and return a number (or occasionally a string or bone transform) to your JSON files. You reach for them whenever an animation needs to scale with movement speed, a render controller needs to swap textures by variant, or a behavior filter needs to check an actor's state without writing Script API code.

Syntax, Aliasing, and Return Values

Every query begins with the prefix query. or its shorthand q. followed by the query name in snake_case. Both forms are completely interchangeable across resource packs and behavior packs, though q. is generally favored in complex expressions to keep character counts down and improve readability inside JSON strings.

Most Molang queries return a floating-point number. When a query represents a true or false condition, it returns 1.0 for true and 0.0 for false. Because Molang treats any non-zero value as truthy and 0.0 as falsy, you can drop boolean queries directly into animation controller transition arrays or ternary operators without comparing them to 1.0 first.

Some queries accept arguments inside parentheses, such as a slot name, an equipment hand, a block face index, or a custom property identifier. Queries that take no arguments can be written with or without empty parentheses in older format versions, though modern schemas and complex math expressions are safest when you omit empty parentheses on argument-free queries or follow the exact signature.

RP/animations/custom_mob.animation.json (expression examples)
// Boolean check using shorthand alias
q.is_on_ground && !q.is_in_water

// Numeric query driving a sine wave for leg swing
math.cos(q.modified_distance_moved * 38.17) * q.modified_move_speed * 45.0

// Parameterized query reading an entity property
q.property('custom:charge_state') == 2

Entity State and Movement Queries

The most frequently used queries inspect an entity's physical movement, health, and immediate action flags. Animation files rely heavily on modified movement queries so that walk cycles speed up or slow down naturally when the entity is affected by Speed or Slowness effects, or walks across soul sand.

State flags like is_baby, is_tamed, and is_sheared mirror the components active in the behavior pack. When a behavior pack adds or removes a component group containing minecraft:is_baby or minecraft:is_tamed, the corresponding query flips on the next client tick, allowing render controllers and animations to react immediately.

QueryReturnsNotes
q.is_on_ground0.0 or 1.01.0 when the entity rests on a solid collision box.
q.ground_speedFloatCurrent horizontal speed of the entity in blocks per second.
q.vertical_speedFloatCurrent vertical velocity; positive when rising, negative when falling.
q.modified_distance_movedFloatTotal distance moved, scaled by movement speed modifiers. Ideal as the phase input for walk cycle trig functions.
q.modified_move_speedFloatNormalized movement speed (typically 0.0 to 1.0) used as an amplitude multiplier for limb rotations.
q.is_moving0.0 or 1.01.0 when the entity has non-zero movement input or velocity along the ground.
q.is_in_water0.0 or 1.01.0 when the entity's hitbox overlaps water, excluding rain.
q.is_in_water_or_rain0.0 or 1.01.0 when in water or exposed to active rainfall.
q.is_alive0.0 or 1.01.0 while living; drops to 0.0 during the death animation.
q.healthFloatCurrent health points. Note that on non-local players or certain server setups, exact health may not sync to all clients unless needed.
q.max_healthFloatThe maximum health defined by the entity's health component.
q.is_baby0.0 or 1.01.0 if the entity currently has the minecraft:is_baby component.
q.is_tamed0.0 or 1.01.0 if the entity currently has the minecraft:is_tamed component.
q.is_saddled0.0 or 1.01.0 if the entity currently has the minecraft:is_saddled component.
q.is_riding0.0 or 1.01.0 when the entity is mounted as a passenger on another entity.
q.is_sneaking0.0 or 1.01.0 when the actor is crouching.
q.is_sprinting0.0 or 1.01.0 when the actor is sprinting.
q.is_swimming0.0 or 1.01.0 when the actor is in the horizontal swimming state.
q.is_sleeping0.0 or 1.01.0 when the entity is sleeping in a bed or nap state.
q.hurt_timeIntegerTicks remaining in the entity's damage flash timer; 0 when not recently hurt.

Data Sync, Variants, and Entity Properties

To drive client-side visuals from server-side behavior logic, you need queries that cross the network boundary. Historically, creators relied on integer components like minecraft:variant, minecraft:mark_variant, and minecraft:skin_id. These remain completely functional and are still the quickest way to select an index from a texture array in a render controller.

For modern packs, Entity Properties (defined inside the behavior pack entity description) are much cleaner and do not collide with vanilla component usage. You read them on both server and client using q.property('namespace:property_name'), provided you set client_sync to true in the property definition. If an entity returned by a query holds an enum string property, you compare it against a single-quoted string literal.

QueryReturnsNotes
q.property('namespace:name')Float, Bool, or StringReads the value of a registered entity property. Requires client_sync: true in the BP if evaluated in RP files.
q.has_property('namespace:name')0.0 or 1.01.0 if the entity has the specified property registered in its definition.
q.variantIntegerReads the value of the minecraft:variant component (defaults to 0).
q.mark_variantIntegerReads the value of the minecraft:mark_variant component (defaults to 0).
q.skin_idIntegerReads the value of the minecraft:skin_id component (defaults to 0).
q.has_target0.0 or 1.01.0 when the entity currently has an active attack target assigned by an AI goal.
q.target_x_rotationFloatPitch angle in degrees needed for the entity's head to look at its current target or look position.
q.target_y_rotationFloatYaw angle in degrees relative to the body needed for the head to face its look target.
q.head_x_rotation(0)FloatCurrent pitch of the entity's head.
q.head_y_rotation(0)FloatCurrent yaw of the entity's head.
q.body_y_rotationFloatWorld yaw rotation of the entity's body in degrees.

Equipment, Timing, and Block State Queries

Timing queries keep procedural animations and particle curves smooth across different frame rates. Inside animations and animation controllers, q.anim_time tracks how many seconds have elapsed since the current animation or controller state began playing. Outside of animations, q.life_time gives the total age in seconds of the entity or particle emitter since it spawned on the client.

When building custom blocks or behavior pack filters that inspect the world, q.block_state('namespace:state_name') reads the current value of a custom or vanilla block state. In entity equipment checks, q.is_item_name_any lets you test whether a specific item identifier is held in a hand or worn in an armor slot.

QueryReturnsNotes
q.anim_timeFloatTime in seconds since the current animation or controller state started. Evaluates to 0.0 outside animation contexts.
q.life_timeFloatTime in seconds since the entity or particle effect was created on the client.
q.time_of_dayFloatNormalized time of day from 0.0 to 1.0 (0.0 is sunrise, 0.25 is noon, 0.5 is sunset, 0.75 is midnight).
q.moon_phaseIntegerCurrent phase of the moon from 0 (full moon) to 7.
q.is_item_name_any('slot', idx, 'id')0.0 or 1.0Checks if the slot (e.g. 'slot.weapon.mainhand', 0) holds one of the listed item identifiers.
q.item_is_charged0.0 or 1.01.0 when a chargeable item like a crossbow is loaded.
q.main_hand_item_use_durationFloatDuration the main-hand item has been continuously used.
q.block_state('namespace:state')Float, Bool, or StringEvaluates the value of a block state on the block currently being evaluated (e.g. inside block permutations or bone_visibility).
q.has_block_state('namespace:state')0.0 or 1.01.0 if the evaluated block possesses the named state.
q.cardinal_facing_2dIntegerReturns the horizontal cardinal direction of the actor.

Using Queries in Animation Controllers and Blocks

The two examples below show where Molang queries sit in real pack files. The first is a client animation controller that switches between idle, walk, and attack states using movement and property queries. The second is a custom block definition that uses q.block_state inside a permutation condition to change light emission when toggled.

RP/animation_controllers/golem_guard.animation_controllers.json
{
  "format_version": "1.10.0",
  "animation_controllers": {
    "controller.animation.golem_guard.move": {
      "initial_state": "idle",
      "states": {
        "idle": {
          "animations": [ "idle_pose" ],
          "transitions": [
            { "walk": "q.ground_speed > 0.15 && q.is_on_ground" },
            { "enraged": "q.property('my_pack:stance') == 'aggressive'" }
          ]
        },
        "walk": {
          "animations": [ "walk_cycle" ],
          "transitions": [
            { "idle": "q.ground_speed <= 0.15 || !q.is_on_ground" },
            { "enraged": "q.property('my_pack:stance') == 'aggressive'" }
          ]
        },
        "enraged": {
          "animations": [ "enraged_roar" ],
          "transitions": [
            { "idle": "q.property('my_pack:stance') != 'aggressive' && q.anim_time >= 1.5" }
          ]
        }
      }
    }
  }
}

Evaluating Queries in Custom Block Permutations

When writing a behavior pack block file, the condition field inside each entry of the permutations array is a Molang string. Here, entity queries are out of scope because there is no actor context; instead, you are restricted to block queries like q.block_state.

BP/blocks/lamp_post.json
{
  "format_version": "1.20.80",
  "minecraft:block": {
    "description": {
      "identifier": "my_pack:lamp_post",
      "states": {
        "my_pack:lit": [ false, true ]
      }
    },
    "components": {
      "minecraft:destructible_by_mining": {
        "seconds_to_destroy": 2.0
      },
      "minecraft:light_emission": 0
    },
    "permutations": [
      {
        "condition": "q.block_state('my_pack:lit') == true",
        "components": {
          "minecraft:light_emission": 15
        }
      }
    ]
  }
}

Which versions this applies to

Applies to Minecraft Bedrock 1.19.0 through 1.21+. Core movement, state, block_state, and entity property queries are completely stable and require no experimental toggles.

When it does not work

What you seeWhyThe fix
[Molang][error]-Error: unhandled request for unknown variable 'q.is_on_the_ground'You misspelled a built-in query name. Molang treats any unrecognized query identifier as an undefined variable and returns 0.0 while flooding the Content Log.Check the exact snake_case spelling in the reference table (for example, change q.is_on_the_ground to q.is_on_ground).
q.property('pack:state') always evaluates to 0 or default on the client even after the server changes itThe entity property definition in your behavior pack entity file is missing "client_sync": true, so the server never sends updates to the resource pack.Add "client_sync": true inside the property's definition block under description.properties in your BP/entities/*.json file.
Animation controller gets stuck in a state when using q.anim_time in a transitionq.anim_time only ticks upward if the current controller state actually plays at least one animation in its "animations" array, or within an animation file itself.Assign an animation to the controller state, or track elapsed time using a Molang variable incremented each frame if the state has no animations.
JSON parse error or Molang syntax error when comparing string queries like q.property or q.block_stateUsing double quotes around the string argument inside a JSON string breaks the JSON parser unless escaped, or using bare unquoted words makes Molang look for a variable.Always wrap string literals inside Molang queries in single quotes, such as q.block_state('my_pack:facing') == 'north'.

Reference, straight from the game files

Read out of the game itself, so the ids match the version you are building for.