Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Minecraft:Molang: Difference between revisions

From SAS Gaming Wiki
imported>Another10101
small tweaks; removed Template:Navbox add-ons
 
SyncBot (talk | contribs)
Fix template calls: add MC/ prefix
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{distinguish|Mojang Studios}}
{{MC/Distinguish|Mojang Studios}}
{{Work in progress}}
{{MC/Work in progress}}
{{exclusive|bedrock}}
{{MC/Exclusive|bedrock}}
'''Molang''' is an expression-based language designed for fast, data-driven calculation of values at run-time, and with a direct connection to in-game values and systems. It is used {{in|BE}} in their [[Minecraft:Add-on|Add-on system]] with its purpose being to enable low-level systems like animation to support flexible data-driven behavior for both internal and external creators, while staying highly performant. Molang's syntax is based off the {{w|C (programming language)|C}} language.<ref>[https://docs.microsoft.com/en-us/minecraft/creator/reference/content/molangreference/examples/molangconcepts/molangintroduction "Molang Documentation - Introduction to Molang"]</ref>
'''Molang''' is an expression-based language designed for fast, data-driven calculation of values at run-time, and with a direct connection to in-game values and systems. It is used {{MC/In|BE}} in their [[Minecraft:Add-on|Add-on system]] with its purpose being to enable low-level systems like animation to support flexible data-driven behavior for both internal and external creators, while staying highly performant. Molang's syntax is based off the {{MC/W|C (programming language)|C}} language.<ref>[https://docs.microsoft.com/en-us/minecraft/creator/reference/content/molangreference/examples/molangconcepts/molangintroduction "Molang Documentation - Introduction to Molang"]</ref>


[[Minecraft:Mojang Studios]] provides [https://docs.microsoft.com/en-us/minecraft/creator/reference/content/molangreference/ official documentation] which goes into details of how the language works and where it is used. The [https://wiki.bedrock.dev/ Bedrock Wiki] provides more areas of Molang where the official documentation may not cover.
Mojang Studios provides [https://docs.microsoft.com/en-us/minecraft/creator/reference/content/molangreference/ official documentation] which goes into details of how the language works and where it is used. The [https://wiki.bedrock.dev/ Bedrock Wiki] provides more areas of Molang where the official documentation may not cover.


== Usage ==
== Usage ==
Molang expressions are used to output values, usually numbers, that can dynamically change. This allows for more complex behavior to be coded for within the restrictions of [[Minecraft:JSON]]. Molang can be used in various places within the JSON files of both [[Minecraft:resource pack]]s (the client) and [[Minecraft:behavior pack]]s (the server):
Molang expressions are used to output values, usually numbers, that can dynamically change. This allows for more complex behavior to be coded for within the restrictions of [[Minecraft:JSON]]. Molang can be used in various places within the JSON files of both resource packs (the client) and [[Minecraft:behavior pack]]s (the server):
*Values in [[Minecraft:Particles (Bedrock Edition)|particle]] components
*Values in [[Minecraft:Particles (Bedrock Edition)|particle]] components
*Values in the <code>scripts</code> and <code>part_visibility</code> fields of entity definitions
*Values in the <code>scripts</code> and <code>part_visibility</code> fields of entity definitions
Line 16: Line 16:
*Arrays and resource allocations in render controllers
*Arrays and resource allocations in render controllers
*Values within certain entity components
*Values within certain entity components
*Data fields in [[Minecraft:recipe]] objects
*Data fields in recipe objects


== Guide ==
== Guide ==
Line 22: Line 22:


For expressions with only a single statement, the terminating symbol <code>;</code> can be removed. Expressions with multiple statements need <code>;</code> in order to separate individual statements.
For expressions with only a single statement, the terminating symbol <code>;</code> can be removed. Expressions with multiple statements need <code>;</code> in order to separate individual statements.
<!-- save info for another article: While developing with Molang, it is recommended to enable content logs (in {{UI|Settings|Creator|link=Settings#Creator}}) to show errors and warnings. However, if you enable file content logs, be careful as if there is a Molang error in an expression that is calculated per frame, while the content log GUI only shows the error once, the content log file will include every instance of that error from every frame, meaning you will likely accumulate potentially Gigabytes of error logs within a relatively short period. -->
<!-- save info for another article: While developing with Molang, it is recommended to enable content logs (in {{MC/UI|Settings|Creator|link=Settings#Creator}}) to show errors and warnings. However, if you enable file content logs, be careful as if there is a Molang error in an expression that is calculated per frame, while the content log GUI only shows the error once, the content log file will include every instance of that error from every frame, meaning you will likely accumulate potentially Gigabytes of error logs within a relatively short period. -->


=== Operators ===
=== Operators ===
{{Empty section}}
{{MC/Empty Section}}


=== Variables ===
=== Variables ===
Line 40: Line 40:
For example, <code>query.health</code> returns the current entity's health, or 0 is not used within an entity.
For example, <code>query.health</code> returns the current entity's health, or 0 is not used within an entity.


Certain queries can also take arguments, which are placed within enclosed brackets after the query name and separated by commas if there are multiple inputs. Arguments can be read as numbers or as strings, where they can be further used as identifiers for objects such as [[Minecraft:Tag (Bedrock Edition)|tag]]s, [[Minecraft:slot]]s, and [[Minecraft:entity|entities]].
Certain queries can also take arguments, which are placed within enclosed brackets after the query name and separated by commas if there are multiple inputs. Arguments can be read as numbers or as strings, where they can be further used as identifiers for objects such as [[Minecraft:Tag (Bedrock Edition)|tag]]s, [[Minecraft:slot]]s, and entities.
For example, <code>q.is_item_name_any('slot.weapon.mainhand', 0, 'minecraft:iron_ingot')</code> evaluates to either <code>1</code> (true) or <code>0</code> (false) based off whether or not the item name (or rather type ID) of the current entity's first slot of their mainhand (the mainhand only has one slot, unlike the inventory or hotbar. Slot indexes start at 0) matches any of the arguments put after the 2nd one.
For example, <code>q.is_item_name_any('slot.weapon.mainhand', 0, 'minecraft:iron_ingot')</code> evaluates to either <code>1</code> (true) or <code>0</code> (false) based off whether or not the item name (or rather type ID) of the current entity's first slot of their mainhand (the mainhand only has one slot, unlike the inventory or hotbar. Slot indexes start at 0) matches any of the arguments put after the 2nd one.


Line 52: Line 52:
== History ==
== History ==
{{HistoryTable
{{HistoryTable
|{{HistoryLine|Bedrock}}
|{{MC/HistoryLine|Bedrock}}
|{{HistoryLine||?|Added Molang, originally capitalized as "MoLang".}}
|{{MC/HistoryLine||?|Added Molang, originally capitalized as "MoLang".}}
|{{HistoryLine||1.17.20|dev=beta 1.17.20.23|Molang now uses the <code>min_engine_version</code> of its resource or behavior pack to allow for versioned changes.}}
|{{MC/HistoryLine||1.17.20|dev=beta 1.17.20.23|Molang now uses the <code>min_engine_version</code> of its resource or behavior pack to allow for versioned changes.}}
}}
}}


Line 61: Line 61:


== Navigation ==
== Navigation ==
{{Navbox Bedrock Edition}}
{{MC/Navbox Bedrock Edition}}




[[Minecraft:es:Molang]]
es:Molang
[[Minecraft:fr:Molang]]
fr:Molang
[[Minecraft:ja:Molang]]
ja:Molang
[[Minecraft:lzh:魔琅]]
lzh:魔琅
[[Minecraft:pt:Molang]]
pt:Molang
[[Minecraft:ru:Molang]]
ru:Molang
[[Minecraft:uk:Molang]]
uk:Molang
[[Minecraft:zh:Molang]]
zh:Molang

Latest revision as of 20:39, 9 April 2026

Template:Hatnote Template:Message box Script error: No such module "Exclusive". Molang is an expression-based language designed for fast, data-driven calculation of values at run-time, and with a direct connection to in-game values and systems. It is used in Template:Editions in their Add-on system with its purpose being to enable low-level systems like animation to support flexible data-driven behavior for both internal and external creators, while staying highly performant. Molang's syntax is based off the

  1. REDIRECT Template:Wikipedia

Template:Redr language.<ref>"Molang Documentation - Introduction to Molang"</ref>

Mojang Studios provides official documentation which goes into details of how the language works and where it is used. The Bedrock Wiki provides more areas of Molang where the official documentation may not cover.

Usage

Molang expressions are used to output values, usually numbers, that can dynamically change. This allows for more complex behavior to be coded for within the restrictions of Minecraft:JSON. Molang can be used in various places within the JSON files of both resource packs (the client) and Minecraft:behavior packs (the server):

  • Values in particle components
  • Values in the scripts and part_visibility fields of entity definitions
  • Values in the scripts field of attachables
  • Values in animations
  • Conditions in the transitions fields of animation controllers
  • Conditions in the permutations field of block behaviors
  • Arrays and resource allocations in render controllers
  • Values within certain entity components
  • Data fields in recipe objects

Guide

Molang expressions are stored as plain text strings in Minecraft:JSON files, enclosed with ". As such, ' must be used instead for any string definitions within the expression. Unlike Minecraft:commands, expressions are case-insensitive, meaning capitalization will not affect how they are interpreted.

For expressions with only a single statement, the terminating symbol ; can be removed. Expressions with multiple statements need ; in order to separate individual statements.

Operators

  1. Redirect Template:Empty section

Variables

Variables, prefixed with variable. or v., are values that can be stored for later use within an expression. Most variables can be declared and reassigned using the = operator, for example in v.<name> = <value>;. Variables declared this way can be read and written for the lifetime of their entity or particle and are not maintained when a world is saved and reloaded.

Temporary variables, prefixed with either temp. or t., only exist while the expression they are declared under is executed.

Context variables, prefixed with context. or c., are read-only variables that are only available under the context of where the expression reading the variable is defined. For example, context.owning_entity can only be read from molang expressions added to an attachable file, since the variable returns the entity which has the attachable equipped.

Functions

Queries

Queries, prefixed with q. or query., return information about the world, entity, etc. as either a boolean or numeric value. They are read-only and cannot be modified. For example, query.health returns the current entity's health, or 0 is not used within an entity.

Certain queries can also take arguments, which are placed within enclosed brackets after the query name and separated by commas if there are multiple inputs. Arguments can be read as numbers or as strings, where they can be further used as identifiers for objects such as tags, Minecraft:slots, and entities. For example, q.is_item_name_any('slot.weapon.mainhand', 0, 'minecraft:iron_ingot') evaluates to either 1 (true) or 0 (false) based off whether or not the item name (or rather type ID) of the current entity's first slot of their mainhand (the mainhand only has one slot, unlike the inventory or hotbar. Slot indexes start at 0) matches any of the arguments put after the 2nd one.

While some queries are consistent over both behavior and resource packs, some are exclusive to only one or the other, an example being query.remaining_durability, which can only be used server-side for the item component minecraft:repairable.

Math functions

Math functions, prefixed with math. without a single-letter alias, perform specific mathematic operations, taking data in the same way as certain queries.

For example, math.floor(3.8) evaluates the input value rounded down as 3.0.

History

Template:HistoryTable

References

<references />

Navigation

Editions
Merged
Ports to consoles
Discontinued
Development
Version history
Technical
Creator
Add-ons
Multiplayer
Exclusive features
Blocks
Mobs
Effects
Unused
Removed


es:Molang fr:Molang ja:Molang lzh:魔琅 pt:Molang ru:Molang uk:Molang zh:Molang