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
    • 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 Education Edition
    • 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

Molang Queries

Molang Queries
  • query.armor_texture_slot
  • query.armor_material_slot
  • query.armor_color_slot
  • query.get_equipped_item_name
  • query.get_name
  • query.is_name_any
  • query.is_item_name_any
  • query.is_enchanted
  • query.is_eating
  • query.is_ghost
  • query.is_grazing
  • query.is_jumping
  • query.modified_move_speed
  • query.log
  • query.on_fire_time
  • query.scoreboard
  • query.structural_integrity
  • variable.attack_time
  • query.is_roaring
  • query.head_x_rotation
  • query.head_y_rotation
  • query.target_x_rotation and query.target_y_rotation
  • query.time_of_day
  • query.eye_target_x_rotation and query.eye_target_y_rotation
  • variable.short_arm_offset_right
  • variable.short_arm_offset_left
  • query.movement_direction
  • query.block_neighbor_has_any_tag and query.relative_block_has_any_tag

The bedrock documentation for Molang is notoriously bad. This page will attempt to remedy this by providing additional details for individual queries, where possible. This page is intended to be searched, not read in full. Use the side-bar, or use ctrl-f to navigate.

TIP

This page is not an exhaustive list list! It only contains queries we've written extra information for. The full list of queries can be found here!

query.armor_texture_slot ​

Formatted like: query.armor_texture_slot(x) = y.

Where x and y are both integer arguments, from the following table:

X ​

ArgumentSlot
0Helmet
1Chestplace
2Leggings
3Boots

Y ​

ArgumentType
-1none
0Leather armor piece
1Chain armor piece
2Iron armor piece
3Diamond armor piece
4Gold armor piece
5Elytra
6Turtle helmet
7Netherite armor piece

Y for horses ​

ArgumentType
1Leather armor piece
2Iron armor piece
3Gold armor piece
4Diamond armor piece

Example ​

query.armor_texture_slot(3) == 1: queries for Iron Boots.

query.armor_material_slot ​

Formatted like: query.armor_material_slot(x) = y.

Where x and y are both integer arguments, from the following table:

X ​

ArgumentSlot
0Helmet
1Chestplace
2Leggings
3Boots

Y ​

Unknown, possibly:

ArgumentSlot
0Default armor material
1Enchanted armor material
2Leather armor material
3Leather enchanted material

query.armor_color_slot ​

Notice: As of version 1.16.100.51, this query is crashing minecraft. It might be fixed in later versions.

Formatted like: color = query.armor_color_slot(slot, channel).

Where slot and channel are both integer arguments, from the following tables:

Slot ​

ArgumentSlot
0Helmet
1Chestplace
2Leggings
3Boots

Channel ​

ArgumentSlot
0Red channel
1Green channel
2Blue channel
3Alpha channel

Color ​

Query returns color value in specified channel.

query.get_equipped_item_name ​

WARNING

DEPRECATED QUERY: It is recommended to use the new query (query.is_item_name_any) if possible as it is more of an updated version of this query. However, this query will still continue to work in the future for backwards compatibility.

Formatted like: query.get_equipped_item_name('main_hand') = 'item_name'

Takes one optional hand slot as a parameter (0 or 'main_hand' for main hand, 1 or 'off_hand' for off hand), and a second parameter (0=default) if you would like the equipped item or any non-zero number for the currently rendered item, and returns the name of the item in the requested slot (defaulting to the main hand if no parameter is supplied) if there is one, otherwise returns ''.

Where item_name is the item you want to test for. No namespace, and please notice the quotes.

Example: "query.get_equipped_item_name == 'diamond'"

Can you test for items in the inventory? Yes! Using the new query query.is_item_name_any.

query.get_name ​

WARNING

DEPRECATED QUERY: It is recommended to use the new query (query.is_name_any) if possible as it is more of an updated version of this query. However, this query will still continue to work in the future for backwards compatibility.

Formatted like: query.get_name == 'Name'

Turns true if actual in-game displayed name matches name (use OnixClient to see names in third view). Needs to be used in special conditions.

Show
animation_controllers/ac.json
json
{
    "format_version": "1.10.0",
    "animation_controllers": {
        "controller.animation.ac": {
            "initial_state": "default",
            "states": {
                "default": {
                    "transitions": [
                        {
                            "active": "query.is_alive"
                        }
                    ]
                },
                "active": {
                    "transitions": [
                        {
                            "default": "(1.0)"
                        }
                    ],
                    "animations": [
                        {
                            "anim": "query.get_name == '...'" // You can use it only here!
                        }
                    ]
                }
            }
        }
    }
}
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

query.is_name_any ​

Formatted like: query.get_name('Name1', 'Name2'). Takes one or more arguments. Turns true if actual in-game displayed name matches one of the given names. Needs to be used in special conditions.

Show
animation_controllers/ac.json
json
{
    "format_version": "1.10.0",
    "animation_controllers": {
        "controller.animation.ac": {
            "initial_state": "default",
            "states": {
                "default": {
                    "transitions": [
                        {
                            "active": "query.is_alive"
                        }
                    ]
                },
                "active": {
                    "transitions": [
                        {
                            "default": "(1.0)"
                        }
                    ],
                    "animations": [
                        {
                            "anim": "query.is_name_any(...)" // You can use it only here!
                        }
                    ]
                }
            }
        }
    }
}
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

query.is_item_name_any ​

Formatted like: query.is_item_name_any('slot.weapon.mainhand', 0, 'namespace:item_name')

Takes the equipment slot name first, followed by the slot index value, and then the list of item names with namespaces after it.

Possible equipment slot are as follows:

Slot NameSlot CountsDescription
slot.weapon.mainhand0Usually any held items are in here
slot.weapon.offhand0Offhand slot for things like Shield, Totem of Undying or a Map
slot.armor.head0Head armor piece
slot.armor.chest0Chestplate armor piece
slot.armor.legs0Leggings armor piece
slot.armor.feet0Boots armor piece
slot.armor0Horse armor
slot.saddle0Saddle slot
slot.hotbar0 to 8Player hotbar slots
slot.inventory0+ (varies)Entities that has an inventory, like the player, minecart with chests, donkey, etc.
slot.enderchest0 to 26Ender chest inventory for players only

Test for items within the player's inventory ​

Formatted like: t.val = 0; t.i = 0; loop(27, {t.val = q.is_item_name_any('slot.inventory', t.i, 'namespace:item_name'); t.val ? break; t.i = t.i+1;});

Replace namespace:item_name with any item you wish to check for. This simply loops through all 27 slots of the inventory and returns 1.0 if it has found any slot that has the specified item provided. Note that the hotbar is in a different slot from the main inventory slot so you will have to check that separately.

query.is_enchanted ​

Formatted like: is_enchanted = query.is_enchanted.

Return 1.0 or 0.0 based on whether the entity is enchanted.

Currently, can be only used in materials.

query.is_eating ​

This query tracks when certain entities are 'eating'. It's not used for the player. To trigger, use one of the following components: - minecraft:behavior.eat_carried_item - minecraft:behavior.snacking

query.is_ghost ​

Formatted like: is_ghost = query.is_ghost.

Return 1.0 or 0.0 based on whether the entity is a ghost.

Currently, only returns 1.0 for a guardian ghost and is used by its renderer.

query.is_grazing ​

Formatted like: is_grazing = query.is_grazing.

Return 1.0 or 0.0 based on whether the entity is eating a block.

Currently, only returns 1.0 for a sheep and entities using runtime identifier of a sheep.

query.is_jumping ​

Formatted like: is_jumping = query.is_jumping.

Return 1.0 or 0.0 based on whether the entity is jumping.

For the player, conditions for its activation are:

  • the jump button is pressed (includes being in water and climbing a scaffolding)
  • OR auto-jump is triggered
  • OR swimming with auto-jump
  • OR charging the jump of a ridable entity

query.modified_move_speed ​

Formatted like: modified_move_speed = query.modified_move_speed.

Returns the current walk speed of the entity modified by status flags such as is_baby or on_fire

Value example:

  • Player is walking: around 0.86
  • Player is sprinting: 1.0
  • Player is sprinting and jumping: 0.35
  • Player is walking on fire: 1.0
  • Player is sprinting on fire: 1.0
  • Player is sprinting and jumping on fire: 0.525

query.log ​

Content log is NOT debug log, they're different files. query.log outputs to the debug log only.

query.on_fire_time ​

Formatted like: on_fire_time = query.on_fire_time.

Returns the time in ticks since the entity started or stopped being on fire, else it returns 0.0

Value example:

  • Entity is summoned: value is 0
  • Entity is ignited: value is 0 and starts counting up 1 every tick
  • Entity is on fire for 2 seconds already: value is 40 and still counts up 1 every tick
  • Entity stops being on fire: value resets to 0 and continues to count up 1 every tick despite not being on fire
  • Entity is ignited second time: value resets to 0 and continues counting up 1 every tick
  • Entity stops being on fire the second time: value resets to 0 and continues to count up 1 every tick despite not being on fire

Basically it's tick timer that starts after entity is first ignited and resets every time it changes from/to being on fire.

query.scoreboard ​

Formatted like: query.scoreboard('objective_name') > 0

Returns 1.0 or 0.0 if the queried value is within the specified range provided. Or based on score count, molang operator and number.

Note that sometimes it might not work because of unknown reasons. One of which is that this cannot query scoreboard objective names with uppercase letters. In this case, for example, objective testfoo will work but not testFoo.

query.structural_integrity ​

Formatted like: structural_integrity = query.structural_integrity.

Used by boats and minecarts for destroying it. It will decrease when attacking the entity and will recover with time. Probably unusable by anything other than boats and minecarts.

variable.attack_time ​

Explanation ​

This variable is setup as IF it was a query. In other words, it can be used on any entity, both on the client and server, regardless of whether you setup/define the variable correctly.

For entities ​

The variable tracks when the entity is swinging to attack. When not attacking, it will return 0.0, when attacking it will range from 0.0 to the total attack time, which may be around 0.3 or something similar. For players, this value ranges from 0.0 to 1.0. The variable returns a percentage, in the form of a decimal, for how far into the attack the entity is. For example, if an entity is halfway into its attack swing, then the variable will return 0.5. It increments linearly.

For the Player ​

For the player, the variable will track whenever the arm bones are swinging, this includes:

  • placing blocks
  • placing entities
  • interacting (when swing is enabled)
  • melee attack

query.is_roaring ​

Evaluates to true when a knockback_roar attack is happening.

query.head_x_rotation ​

Formatted like: query.head_x_rotation(x)

Where x specifies the head of the entity. It is not really relevant for any entity but the wither.

Returns head pitch. looking up returns -89.9, looking all the way down returns 89.9.

query.head_y_rotation ​

Formatted like: query.head_y_rotation(x)

Where x specifies the head of the entity. It is not really relevant for any entity but the wither.

Returns yaw of the head from -179.9 to 179.9. the values wrap around so like if you are at -179.9 and you turn just a little bit, it instantly goes to 179.9.

query.target_x_rotation and query.target_y_rotation ​

Identical to the respective query.head_*_rotation, however has no optional argument for selecting head.

query.time_of_day ​

Returns the time of day (midnight=0.0, sunrise=0.25, noon=0.5, sunset=0.75) of the dimension the entity is in. Day time is calculated via this formula:

f(x) = (x*0.25/2400)mod 1

query.time_of_day - day time table

Show
query.time_of_dayDay Time
0.0018000
0.0118240
0.0218480
0.0318720
0.0418960
0.0519200
0.0619440
0.0719680
0.0819920
0.0920162
0.1020400
0.1120640
0.1220880
0.1321120
0.1421360
0.1521602
0.1621840
0.1722080
0.1822322
0.1922560
0.2022800
0.2123040
0.2223280
0.2323520
0.2423760
0.250
0.26240
0.27480
0.28720
0.29960
0.301202
0.311440
0.321680
0.331922
0.342160
0.352400
0.362642
0.372880
0.383120
0.393360
0.403600
0.413840
0.424080
0.434320
0.444560
0.454800
0.465040
0.475280
0.485520
0.495760
0.506000
0.516240
0.526480
0.536720
0.546960
0.557200
0.567440
0.577680
0.587920
0.598160
0.608402
0.618640
0.628880
0.639120
0.649360
0.659600
0.669842
0.6710080
0.6810320
0.6910560
0.7010800
0.7111040
0.7211282
0.7311520
0.7411760
0.7512000
0.7612240
0.7712480
0.7812720
0.7912962
0.8013200
0.8113440
0.8213680
0.8313920
0.8414160
0.8514402
0.8614640
0.8714880
0.8815120
0.8915360
0.9015600
0.9115842
0.9216080
0.9316320
0.9416560
0.9516800
0.9617040
0.9717282
0.9817520
0.9917760
1.0018000

Credit: Analysis of query.time_of_day

query.eye_target_x_rotation and query.eye_target_y_rotation ​

Not valid for player. not really sure what its good for.

variable.short_arm_offset_right ​

Returns the offset factor for the player's rightarm bone compared to the default skin geometry. Slim-armed (3 pixel wide) skins will return 0.5 when equipped on the player. Normal (4 pixel wide) skins will return 0.0 when equipped on the player. Note: the player must go into 1st person perspective at least once for this variable to be initialized and usable elsewhere on the entity.

variable.short_arm_offset_left ​

Identical behavior to variable.short_arm_offset_right except it references the player leftarm bone.

query.movement_direction ​

Returns one of the 3 components from the normalized vector of the entity movement meaning the magnitude/modulus/length of the vector is between 0 and 1.

Note: As of writing the documentation, the value returned from any of the axis will change depending on the speed of the entity (If the entity is on the ground the value will be less than the value of the entity if it were in the air even if it is moving in the same direction).

To get the actual normalized velocity vector of the entity movement you will have to normalize the values. Here is the Molang setup:

molang
variable.mag = math.sqrt( math.pow( query.movement_direction(0), 2 ) + math.pow( query.movement_direction(1), 2) + math.pow( query.movement_direction(2), 2));
variable.xNorm = query.movement_direction(0) / variable.mag;
variable.yNorm = query.movement_direction(1) / variable.mag;
variable.zNorm = query.movement_direction(2) / variable.mag;
1
2
3
4

For more information on normalized vectors you can play around with this Desmos graph

ArgumentAxis
0X
1Y
2Z

query.block_neighbor_has_any_tag and query.relative_block_has_any_tag ​

Requires Experimental Molang Features to use. From the docs Takes a relative position and one or more tag names, and returns either 0 or 1 based on if the block at that position has any of the tags provided. This is useful for using connecting blocks or detecting entities.

query.block_neighbor_has_any_tag - Takes block position query.relative_block_has_any_tag - Takes entity position

The syntax for it is q.block_neighbor_has_any_tag(x,y,z,'tag_name') and q.relative_block_has_any_tag(x,y,z,'tag_name').

Example:

  • q.relative_block_has_any_tag(0,-1,0,'grass') would try to detect a block with the grass tag one block under the entity.
  • q.block_neighbor_has_any_tag(0,-1,0,'grass') would try to detect a block with the grass tag one block under the block.

To do multiple tags you would use q.correct_query(0,-1,0,'grass', 'plant') with correct_query being replaced by the right query.

Note that this can also detect custom tags and vanilla tags

Contributors

Edit Molang Queries 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