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
  • Tutorials
    • Block Conditions for Features
    • Generating Custom Ores
    • Generating Custom Structures
    • Generating Patches
    • Heightmap Noise
  • Documentation
    • Biome Tags

Molang

intermediate
Molang
  • What Is Molang?
  • Expressions
  • Accessing Game Data
    • 1. Queries (query. or q.)
    • 2. Variables (variable. or v.)
    • 3. Temporary Variables (temp. or t.)
    • 4. Context Variables (context. or c.)
  • Logic and Conditions
    • Comparison Operators
    • Boolean Logic
    • Conditional Operators
  • Math Functions
  • Structs
  • Loops and Flow Control
    • break and continue
  • Simple vs Complex Expressions
  • Versioning and min_engine_version

What Is Molang? ​

Molang is a math-based expression language used throughout Minecraft Bedrock Edition. It is used in animations, particles, render controllers, and behavior logic.

Expressions ​

Molang expressions are like little math problems the game solves constantly.

molang
q.health < 5 ? 1 : 0
1

This returns 1.0 if health is less than 5, otherwise 0.0.

Accessing Game Data ​

1. Queries (query. or q.) ​

Read-only values provided by the game. ​

Queries can either return a value directly, or accept arguments to return context-specific results.

Examples without arguments:

  • query.is_sneaking
  • query.time_of_day
  • query.health

Examples with arguments:

  • query.position(0)
  • query.is_item_name_any('slot.weapon.offhand', 'minecraft:dirt')
  • query.in_range(5, 0, 10)

2. Variables (variable. or v.) ​

Read-write values stored per-entity. ​

Examples:

  • variable.buff_timer
  • variable.has_effect
molang
v.buff_timer = (v.buff_timer ?? 0) + q.delta_time;
1

Default Variables ​

VariableDescription
variable.animation_frames_128x128Controls animation frame index for 128x128 textures (persona)
variable.animation_frames_32x32Controls animation frame index for 32x32 textures
variable.animation_frames_faceControls face animation frames (used in facial expressions)
variable.attack_timeProgress of an attack animation (0.0 to 0.7)
variable.bob_animationOscillation used for idle/movement bobbing
variable.charge_amountAmount of charge built up (used in attachables)
variable.damage_nearby_mobsTrue if nearby mobs are being damaged
variable.gliding_speed_valueSpeed value while gliding
variable.has_targetWhether the entity currently has a target
variable.is_brandishing_spearWhether the entity is holding up a trident
variable.is_holding_leftWhether the left hand is holding something
variable.is_holding_rightWhether the right hand is holding something
variable.is_holding_spyglassWhether the player is holding a spyglass
variable.is_horizontal_splitscreenTrue if horizontal splitscreen is active
variable.is_paperdollWhether the paperdoll is currently visible
variable.is_sneakingWhether the player is sneaking
variable.is_tooting_goat_hornWhether the player is tooting a goat horn
variable.is_using_brushWhether the player is using a brush
variable.is_using_vrWhether the player is using a VR headset
variable.is_vertical_splitscreenTrue if vertical splitscreen is active
variable.last_blink_timeTime since last blink event (persona)
variable.left_arm_swim_amountAmount of swimming animation applied to left arm
variable.map_face_iconTrue if there is a map face icon display
variable.player_arm_heightHeight offset of arms (usually adjusted in first-person view)
variable.player_x_rotationX-axis rotation of the player’s view
variable.right_arm_swim_amountAmount of swimming animation applied to right arm
variable.short_arm_offset_leftAdjusts arm length for left arm (used in VR/paperdoll)
variable.short_arm_offset_rightAdjusts arm length for right arm
variable.swim_amountGeneral swimming animation progress
variable.use_blinking_animationEnables/disables blinking animation logic
variable.use_item_interval_progressTracks middle portion of item use timeline
variable.use_item_startup_progressTracks startup phase of item use animation
variable.is_first_personWhether the player is in first-person

3. Temporary Variables (temp. or t.) ​

Read-write values stored per-pack. ​

molang
t.temp_speed = q.ground_speed * 1.2;
1

Temporary variables are pack-scoped and ephemeral. They only exist for the duration of the current Molang expression or loop. They are shared globally across a pack and are cleared automatically after each expression completes. They do not support structs (no .x, .y, .z).

TIP

They are also incredibly useful for passing intermediate results between expressions, especially in contexts that do not support passing in variables or queries directly, such as particles.

4. Context Variables (context. or c.) ​

Read-only values from the base game in specific situations. ​

Common Context Variables ​

Context VariableContextsDescription
context.block_faceBlocksBlock face being interacted with (0–5)
context.cardinal_block_face_placed_onBlocksLegacy placement direction (use block_face)
context.countRecipesCount of something in the current context
context.is_first_personAnimations, Entities, Render ControllersTrue if the entity is rendered in first person
context.item_slotModelsSlot index of the current item
context.otherItemsThe "other" item (for repair targets)
context.owning_entityAttachablesEntity that owns this context (used for getting queries)
context.player_offhand_arm_heightModelsArm offset used when rendering offhand

Example:

molang
context.other->query.remaining_durability
1

Logic and Conditions ​

Comparison Operators ​

OperatorDescription
==Equal
!=Not equal
<, >Less than / greater
<=, >=Less/greater or equal
molang
q.health <= 10
1

Boolean Logic ​

OperatorMeaning
&&AND
||OR
molang
q.is_sneaking && q.is_using_item
1

Conditional Operators ​

Use ? and : like if-else:

  • Binary: condition ? result
  • Ternary: condition ? true : false
molang
q.is_jumping ? 3 : 0
1

You can also use the null coalescing operator (??) to provide a fallback when a variable might not be initialized:

  • fallback = value ?? default
molang
v.timer = (v.timer ?? 0) + q.delta_time
1

This avoids content log errors if v.timer has not been defined yet.

Math Functions ​

Molang supports a wide range of math functions, using degrees (not radians) for trigonometry. These are useful for animation timing, oscillation, directional math, clamping, and more.

FunctionDescription
math.abs(x)Absolute value of x
math.acos(x)Arccosine (inverse cosine) of x
math.asin(x)Arcsine (inverse sine) of x
math.atan(x)Arctangent (inverse tangent) of x
math.atan2(y, x)Arctangent of y / x — returns angle in degrees
math.ceil(x)Round x up to the nearest integer
math.clamp(x, min, max)Constrain x between min and max
math.cos(x)Cosine of x degrees
math.die_roll(n, low, high)Roll n floats between low and high and sum them
math.die_roll_integer(n, low, high)Same as above but rolls integers
math.exp(x)Exponential (e^x)
math.floor(x)Round x down to the nearest integer
math.hermite_blend(t)Smooth curve: 3t^2 - 2t^3, good for eased interpolation
math.lerp(a, b, t)Linearly interpolate between a and b by t
math.lerprotate(a, b, t)Rotational interpolation, shortest path around a circle
math.ln(x)Natural logarithm of x
math.max(a, b)Larger of a or b
math.min(a, b)Smaller of a or b
math.min_angle(x)Clamp angle x to the range -180° to 180°
math.mod(a, b)Remainder of a / b
math.piConstant for π (approximately 3.14159)
math.pow(base, exponent)Raise base to the exponent power
math.random(low, high)Random float between low and high
math.random_integer(low, high)Random integer between low and high
math.round(x)Round x to the nearest integer
math.sin(x)Sine of x degrees
math.sqrt(x)Square root of x
math.trunc(x)Remove fractional part of x (round toward zero)

Structs ​

Structs in Molang are values that contain multiple related fields, like .x, .y, .z.

You can create your own structs using variable. and assign values to their fields directly:

molang
v.location.x = 1;
v.location.y = 2;
v.location.z = 3;
1
2
3

These values can then be reused or passed to other expressions:

molang
v.target = v.other_mob->v.location;
1

WARNING

temp. variables do not support structs. Use variable. for anything involving .x, .y, .z, etc.

Loops and Flow Control ​

You can run expressions multiple times using loop.

molang
v.a = 1;
v.b = 1;

loop(10, {
    t.next = v.a + v.b;
    v.a = v.b;
    v.b = t.next;
});
1
2
3
4
5
6
7
8

break and continue ​

  • break; exits the current loop early
  • continue; skips to the next iteration
molang
loop(10, {
    (v.a > 5) ? break;
    v.a += 1;
});
1
2
3
4

Simple vs Complex Expressions ​

  • Simple: a single expression that returns a value
molang
math.sin(q.anim_time * 10)
1
  • Complex: multiple statements with ; and an explicit return
molang
t.a = math.sin(q.anim_time * 10);
t.b = t.a * t.a;
return t.b + 1;
1
2
3

Versioning and min_engine_version ​

Molang behavior can change depending on the min_engine_version defined in your pack’s manifest.json. These changes improve how expressions behave, fix bugs, and deprecate older behavior.

Make sure your pack's engine version is set correctly to take advantage of the latest fixes and syntax improvements.

Pack min_engine_versionDescription
1.17.0Initial support for Versioned Changes added. (Not actually a Versioned Change)
1.17.30Fixed query.item_remaining_use_duration conversion from ticks to seconds (was multiplied by 20 instead of divided). Also reversed its normalization logic.
1.17.40Added new error messages for invalid expressions (e.g., 'text' + 1 now causes a content error).
1.17.40Added error detection for mismatched parentheses/brackets and unknown tokens.
1.18.10Fixed ternary operator associativity. A ? B : C ? D : E now evaluates correctly as A ? B : (C ? D : E).
1.18.20Changed operator precedence: logical AND now evaluates before OR, and comparison before equality.
1.19.60Fixed issue where dividing by a dynamically negative value used the absolute value instead.
1.20.0Fixed query.cape_flap_amount using incorrect head rotation instead of body rotation.
1.20.10Renamed block_property and has_block_property to block_state and has_block_state.
1.20.40Deprecated block_property and has_block_property.
1.20.50Fully removed block_property logic. Also removed queries: is_scenting, is_rising, and is_feeling_happy. Replaced by timer_flag_1–3.
1.20.70Step particle texture queries now treat leaf blocks as valid sources.

Contributors

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