Skip to content

API reference / @jsprismarine/molang

@jsprismarine/molang ​

Join the Discord Servernpm

Molang parser, compiler and evaluator for Bedrock behavior packs. Parses the full Molang grammar with a Pratt parser, compiles each expression once per (source, version) into a JavaScript closure, and evaluates it over a typed scope (entity, block permutation, item, world, placement, context.*, variable.*, temp.*).

ts
import { Molang } from '@jsprismarine/molang';

const molang = new Molang();
const compiled = molang.compile('query.is_baby ? 0.02 : 0.001', { minEngineVersion: [1, 21, 0] });
const value = compiled.evaluate({ entity: myEntityContext });

Operator precedence is versioned by the containing pack's min_engine_version, matching the engine's rule changes at 1.18.10 (ternary associativity) and 1.18.20 (&& over ||, comparison over equality). Unknown query.* and math.* identifiers are reported through the compile diagnostics and evaluate to 0.0 at run time, as the engine does.

Examples ​

These expressions are exported as MOLANG_EXAMPLES, each with the scopes it is shown under and the value it produces. The test suite compiles every one with no diagnostics and checks the values, and fails if this section drifts from the list, so they are safe to copy.

ts
import { MOLANG_EXAMPLES, Molang } from '@jsprismarine/molang';

const molang = new Molang();
for (const example of MOLANG_EXAMPLES) {
    const compiled = molang.compile(example.source);
    for (const { label, scope, expected } of example.cases) {
        console.log(example.title, label, compiled.evaluate(scope), expected);
    }
}

A chance that depends on age ​

A ternary picks between two numbers, as an ambient sound probability does.

molang
query.is_baby ? 0.02 : 0.001

a baby: 0.02; an adult: 0.001.

A value kept in range ​

The math functions take and return numbers; clamp(value, min, max) bounds a variant index.

molang
math.clamp(query.variant, 0, 3)

variant 2: 2; variant 9: 3.

A spawn condition ​

Booleans are 1 and 0, so conditions combine with &&, || and !.

molang
query.head_is_in_water && !query.is_on_ground

swimming: 1; standing in the shallows: 0.

A string property ​

Strings compare with == and !=, and query.property reads an entity property.

molang
query.property('example:color') == 'red'

red: 1; blue: 0.

Worn-out tools ​

An item expression reads durability; the result is 1 once less than a tenth is left.

molang
query.remaining_durability / query.max_durability < 0.1

almost broken: 1; nearly new: 0.

Interpolating between two numbers ​

math.lerp(start, end, t) blends linearly.

molang
math.lerp(10, 20, 0.25)

no scope needed: 12.5.

A reward that grows with level ​

Arithmetic follows the usual precedence, so the multiplication happens before the cap.

molang
math.min(10 + query.player_level * 5, 100)

level 4: 30; level 40: 100.

A terrain condition ​

Worldgen queries take coordinates and read the placement context.

molang
query.heightmap(0, 0) > 62

above sea level: 1; under water: 0.

A complex expression with a loop ​

Statements end in ;, v. is variable., and a complex expression yields what return gives it.

molang
v.total = 0; loop(5, { v.total = v.total + 2; }); return v.total;

five rounds of two: 10.

Stopping a loop early ​

break leaves the loop; the loop is capped at 1024 rounds either way.

molang
v.n = 0; loop(100, { v.n = v.n + 1; (v.n >= 7) ? break; }); return v.n;

stops at seven: 7.

Classes ​

Interfaces ​

ArrowNode ​

Defined in: ast.ts:63

The arrow operator left->right; evaluates right against the entity left resolves to.

Properties ​

kind ​

kind: "arrow"

Defined in: ast.ts:64

left ​

left: ExpressionNode

Defined in: ast.ts:65

right: ExpressionNode

Defined in: ast.ts:66


AssignNode ​

Defined in: ast.ts:77

An assignment to variable.* or temp.* storage.

Properties ​

kind ​

kind: "assign"

Defined in: ast.ts:78

target ​

target: ReferenceNode

Defined in: ast.ts:79

value ​

value: ExpressionNode

Defined in: ast.ts:80


BinaryNode ​

Defined in: ast.ts:47

A binary operation.

Properties ​

kind ​

kind: "binary"

Defined in: ast.ts:48

left ​

left: ExpressionNode

Defined in: ast.ts:50

operator ​

operator: BinaryOperator

Defined in: ast.ts:49

right ​

right: ExpressionNode

Defined in: ast.ts:51


BlockContext ​

Defined in: scope.ts:54

Block permutation state for query.block_state and tag queries on blocks.

Methods ​

blockState()? ​

optional blockState(name): string | number | boolean | undefined

Defined in: scope.ts:56

The value of the named block state, or undefined when the permutation lacks it.

Parameters ​
name ​

string

Returns ​

string | number | boolean | undefined

tags()? ​

optional tags(): readonly string[]

Defined in: scope.ts:58

The block's tags, for query.any_tag and query.all_tags.

Returns ​

readonly string[]


BlockNode ​

Defined in: ast.ts:98

A braced statement list { a = 1; b = 2; }.

Properties ​

kind ​

kind: "block"

Defined in: ast.ts:99

statements ​

statements: readonly StatementNode[]

Defined in: ast.ts:100


CallNode ​

Defined in: ast.ts:30

A call such as math.clamp(a, b, c) or query.anger_level(this).

Properties ​

args ​

args: readonly ExpressionNode[]

Defined in: ast.ts:33

callee ​

callee: ReferenceNode

Defined in: ast.ts:32

kind ​

kind: "call"

Defined in: ast.ts:31


CompileOptions ​

Defined in: Molang.ts:10

Options for one compilation.

Properties ​

minEngineVersion? ​

optional minEngineVersion?: EngineVersion

Defined in: Molang.ts:15

The min_engine_version of the pack that contains the expression. Selects the versioned precedence and evaluation rules; the latest rules apply when omitted.


CompiledMolang ​

Defined in: compiler.ts:74

A compiled Molang expression: the parse diagnostics and a closure to evaluate it.

Properties ​

ast? ​

optional ast?: ProgramNode

Defined in: compiler.ts:78

The parsed program, or undefined when the source failed to parse.

diagnostics ​

diagnostics: readonly Diagnostic[]

Defined in: compiler.ts:80

Problems found at parse or bind time; the closure still evaluates, erroring parts as 0.

evaluate ​

evaluate: (scope) => MolangValue

Defined in: compiler.ts:82

Evaluates the expression over the scope. Booleans come back as 0 and 1.

Parameters ​
scope ​

MolangScope

Returns ​

MolangValue

source ​

source: string

Defined in: compiler.ts:76

The source text the expression was compiled from.


Diagnostic ​

Defined in: diagnostics.ts:9

A problem found while parsing or binding an expression. The engine raises content errors for these and still evaluates the expression to 0.0; this package mirrors that and reports the problem here instead of throwing.

Properties ​

code ​

code: DiagnosticCode

Defined in: diagnostics.ts:10

message ​

message: string

Defined in: diagnostics.ts:11


EntityContext ​

Defined in: scope.ts:27

Entity state the entity queries read. Implement the members your entities can answer.

Properties ​

variables? ​

optional variables?: Map<string, MolangValue>

Defined in: scope.ts:50

Read-write variable.* storage on the entity; not persisted.

Methods ​

angerLevel()? ​

optional angerLevel(): number

Defined in: scope.ts:29

The warden's anger level, [0, n).

Returns ​

number

equipmentCount()? ​

optional equipmentCount(): number

Defined in: scope.ts:31

Armor pieces equipped, 0 to 5, hands excluded.

Returns ​

number

hadComponentGroup()? ​

optional hadComponentGroup(name): boolean

Defined in: scope.ts:33

Whether the entity was loaded from data saved with the named component group.

Parameters ​
name ​

string

Returns ​

boolean

hasAnyFamily()? ​

optional hasAnyFamily(families): boolean

Defined in: scope.ts:35

Whether the entity belongs to any of the given type families.

Parameters ​
families ​

readonly string[]

Returns ​

boolean

headIsInWater()? ​

optional headIsInWater(): boolean

Defined in: scope.ts:37

Whether the entity's head is in water.

Returns ​

boolean

isBaby()? ​

optional isBaby(): boolean

Defined in: scope.ts:38

Returns ​

boolean

isOnGround()? ​

optional isOnGround(): boolean

Defined in: scope.ts:39

Returns ​

boolean

isUsingItem()? ​

optional isUsingItem(): boolean

Defined in: scope.ts:40

Returns ​

boolean

lastHitByPlayer()? ​

optional lastHitByPlayer(): boolean

Defined in: scope.ts:42

Whether a player dealt the last hit.

Returns ​

boolean

playerLevel()? ​

optional playerLevel(): number

Defined in: scope.ts:44

The player's experience level, or 0 for non-players.

Returns ​

number

property()? ​

optional property(name): string | number | undefined

Defined in: scope.ts:46

The value of the named entity property, or undefined when it does not exist.

Parameters ​
name ​

string

Returns ​

string | number | undefined

variant()? ​

optional variant(): number

Defined in: scope.ts:48

The entity's variant index.

Returns ​

number


ForEachNode ​

Defined in: ast.ts:111

for_each(variable, array, expression).

Properties ​

array ​

array: ExpressionNode

Defined in: ast.ts:114

body ​

body: ExpressionNode

Defined in: ast.ts:115

kind ​

kind: "for_each"

Defined in: ast.ts:112

variable ​

variable: ReferenceNode

Defined in: ast.ts:113


IndexNode ​

Defined in: ast.ts:70

Array access target[index].

Properties ​

index ​

index: ExpressionNode

Defined in: ast.ts:73

kind ​

kind: "index"

Defined in: ast.ts:71

target ​

target: ExpressionNode

Defined in: ast.ts:72


ItemContext ​

Defined in: scope.ts:62

Item stack state for the durability and tag queries.

Methods ​

maxDurability()? ​

optional maxDurability(): number

Defined in: scope.ts:63

Returns ​

number

remainingDurability()? ​

optional remainingDurability(): number

Defined in: scope.ts:64

Returns ​

number

tags()? ​

optional tags(): readonly string[]

Defined in: scope.ts:66

The item's tags, for query.any_tag and query.all_tags.

Returns ​

readonly string[]


LoopControlNode ​

Defined in: ast.ts:93

break and continue inside a loop body. They may appear where an expression is expected, as in (v.x > 5) ? break, and evaluate to 0 outside a loop.

Properties ​

kind ​

kind: "break" | "continue"

Defined in: ast.ts:94


LoopNode ​

Defined in: ast.ts:104

loop(count, expression); the engine caps count at 1024.

Properties ​

body ​

body: ExpressionNode

Defined in: ast.ts:107

count ​

count: ExpressionNode

Defined in: ast.ts:106

kind ​

kind: "loop"

Defined in: ast.ts:105


MathFunction ​

Defined in: math.ts:2

A Molang math function: a pure numeric function over already-evaluated arguments.

Properties ​

evaluate ​

evaluate: (args) => number

Defined in: math.ts:4

Evaluates the function. Missing arguments read as 0, as Molang errors evaluate to 0.

Parameters ​
args ​

readonly number[]

Returns ​

number


MolangArray ​

Defined in: scope.ts:18

An actor array, as produced by queries the arrow and for_each constructs consume.

Properties ​

elements ​

elements: readonly MolangValue[]

Defined in: scope.ts:20

kind ​

kind: "array"

Defined in: scope.ts:19


MolangExample ​

Defined in: examples.ts:12

A Molang expression a pack author could write, with the scopes it is shown to work under.

Properties ​

cases ​

readonly cases: readonly MolangExampleCase[]

Defined in: examples.ts:20

description ​

readonly description: string

Defined in: examples.ts:16

Where an author would put it and what it does.

minEngineVersion? ​

readonly optional minEngineVersion?: readonly [number, number, number]

Defined in: examples.ts:19

The pack's min_engine_version when the expression depends on one.

source ​

readonly source: string

Defined in: examples.ts:17

title ​

readonly title: string

Defined in: examples.ts:14

A short name, used as the heading in the README.


MolangExampleCase ​

Defined in: examples.ts:4

One evaluation of an example: what the scope answers and the value that comes out.

Properties ​

expected ​

readonly expected: MolangValue

Defined in: examples.ts:8

label ​

readonly label: string

Defined in: examples.ts:6

What is different about this scope, in a few words.

scope ​

readonly scope: MolangScope

Defined in: examples.ts:7


MolangOptions ​

Defined in: Molang.ts:19

Options for a Molang engine.

Properties ​

queries? ​

optional queries?: QueryRegistry

Defined in: Molang.ts:21

The query registry to bind query.* names against; a fresh vanilla registry by default.


MolangScope ​

Defined in: scope.ts:95

Everything one evaluation can see. Queries declare which of these members they need; the compiler reports a query bound against a scope that was declared without its context.

Properties ​

block? ​

optional block?: BlockContext

Defined in: scope.ts:97

context? ​

optional context?: ReadonlyMap<string, MolangValue>

Defined in: scope.ts:102

Read-only values the game supplies for the expression, such as context.other.

entity? ​

optional entity?: EntityContext

Defined in: scope.ts:96

item? ​

optional item?: ItemContext

Defined in: scope.ts:98

placement? ​

optional placement?: PlacementContext

Defined in: scope.ts:100

variables? ​

optional variables?: Map<string, MolangValue>

Defined in: scope.ts:104

variable.* storage when no entity carries it, as for feature-rule engine variables.

world? ​

optional world?: WorldContext

Defined in: scope.ts:99


MolangScopeRef ​

Defined in: scope.ts:12

A reference to another evaluation scope, used by the arrow operator and this. The engine's actor references map to this: context.other->query.remaining_durability evaluates its right side against the referenced scope.

Properties ​

kind ​

kind: "scope"

Defined in: scope.ts:13

scope ​

scope: MolangScope

Defined in: scope.ts:14


MolangStruct ​

Defined in: scope.ts:2

A struct value, implicitly defined by usage such as v.location.x = 1;.

Properties ​

kind ​

kind: "struct"

Defined in: scope.ts:3

members ​

members: Map<string, MolangValue>

Defined in: scope.ts:4


MolangVersionRules ​

Defined in: version.ts:13

The language rules that change with a pack's min_engine_version.

The engine versions each Molang expression by the manifest of the pack that contains it. Two changes affect parsing: at 1.18.10 the ternary became right-associative, and at 1.18.20 && started binding tighter than || and comparisons tighter than equality. One change affects evaluation: at 1.19.60 division by a dynamically determined negative value stopped dividing by its absolute value.

Properties ​

andBeforeOr ​

andBeforeOr: boolean

Defined in: version.ts:17

&& binds tighter than || and comparison tighter than equality from 1.18.20.

divideByNegativeValue ​

divideByNegativeValue: boolean

Defined in: version.ts:19

Division by a non-constant negative divisor uses the real divisor from 1.19.60.

ternaryRightAssociative ​

ternaryRightAssociative: boolean

Defined in: version.ts:15

A ? B : C ? D : E groups as A ? B : (C ? D : E) from 1.18.10.


NumberNode ​

Defined in: ast.ts:2

A numeric literal. Molang numbers are floats; true and false lex to 1 and 0.

Properties ​

kind ​

kind: "number"

Defined in: ast.ts:3

value ​

value: number

Defined in: ast.ts:4


PlacementContext ​

Defined in: scope.ts:80

Feature placement state for the worldgen queries.

Methods ​

aboveTopSolid()? ​

optional aboveTopSolid(x, z): number

Defined in: scope.ts:84

The height of the block above the highest solid block at (x, z).

Parameters ​
x ​

number

z ​

number

Returns ​

number

hasBiomeTag()? ​

optional hasBiomeTag(tag, x?, y?, z?): boolean

Defined in: scope.ts:88

Whether the biome at the placement position (or the given one) has the tag.

Parameters ​
tag ​

string

x? ​

number

y? ​

number

z? ​

number

Returns ​

boolean

heightmap()? ​

optional heightmap(x, z): number

Defined in: scope.ts:82

The world-surface height (Y) at (x, z).

Parameters ​
x ​

number

z ​

number

Returns ​

number

noise()? ​

optional noise(x, z): number

Defined in: scope.ts:86

A Perlin noise value near [-1, 1] for (x, z).

Parameters ​
x ​

number

z ​

number

Returns ​

number


ProgramNode ​

Defined in: ast.ts:143

A parsed Molang expression. A simple expression has one statement and no ; and returns its value; a complex expression runs its statements and returns 0 unless a return runs.

Properties ​

complex ​

complex: boolean

Defined in: ast.ts:145

kind ​

kind: "program"

Defined in: ast.ts:144

statements ​

statements: readonly StatementNode[]

Defined in: ast.ts:146


QueryDefinition ​

Defined in: queries.ts:7

A registered query: the context it needs and its implementation.

Properties ​

context ​

context: QueryContextKind

Defined in: queries.ts:9

Which part of the scope the query reads; loaders can validate fields against it.

evaluate ​

evaluate: (scope, args) => MolangValue

Defined in: queries.ts:11

Evaluates the query over already-evaluated arguments.

Parameters ​
scope ​

MolangScope

args ​

readonly MolangValue[]

Returns ​

MolangValue


ReferenceNode ​

Defined in: ast.ts:18

A dotted reference such as query.is_baby, variable.a.b or math.pi. domain is the normalized first segment (aliases q, v, t and c are expanded) and path the remaining segments.

Properties ​

domain ​

domain: "query" | "math" | "variable" | "temp" | "context" | "geometry" | "material" | "texture" | "array"

Defined in: ast.ts:20

kind ​

kind: "reference"

Defined in: ast.ts:19

path ​

path: readonly string[]

Defined in: ast.ts:21


ReturnNode ​

Defined in: ast.ts:84

return <expression>; ends the whole expression with the value.

Properties ​

kind ​

kind: "return"

Defined in: ast.ts:85

value ​

value: ExpressionNode

Defined in: ast.ts:86


StringNode ​

Defined in: ast.ts:8

A single-quoted string literal with its case preserved.

Properties ​

kind ​

kind: "string"

Defined in: ast.ts:9

value ​

value: string

Defined in: ast.ts:10


TernaryNode ​

Defined in: ast.ts:55

A ? B : C, or the binary conditional A ? B when otherwise is undefined.

Properties ​

condition ​

condition: ExpressionNode

Defined in: ast.ts:57

kind ​

kind: "ternary"

Defined in: ast.ts:56

otherwise? ​

optional otherwise?: ExpressionNode

Defined in: ast.ts:59

then ​

then: ExpressionNode

Defined in: ast.ts:58


ThisNode ​

Defined in: ast.ts:25

this, the value the expression ultimately writes to.

Properties ​

kind ​

kind: "this"

Defined in: ast.ts:26


Token ​

Defined in: lexer.ts:11

A lexed token. value is lowercased except for string contents, which keep their case.

Properties ​

kind ​

kind: TokenKind

Defined in: lexer.ts:12

start ​

start: number

Defined in: lexer.ts:15

Offset of the token's first character in the source text.

value ​

value: string

Defined in: lexer.ts:13


UnaryNode ​

Defined in: ast.ts:37

A unary operation, !a or -a.

Properties ​

kind ​

kind: "unary"

Defined in: ast.ts:38

operand ​

operand: ExpressionNode

Defined in: ast.ts:40

operator ​

operator: "!" | "-"

Defined in: ast.ts:39


WorldContext ​

Defined in: scope.ts:70

Level state the world queries read.

Methods ​

day()? ​

optional day(): number

Defined in: scope.ts:73

Returns ​

number

moonBrightness()? ​

optional moonBrightness(): number

Defined in: scope.ts:75

Returns ​

number

moonPhase()? ​

optional moonPhase(): number

Defined in: scope.ts:74

Returns ​

number

timeOfDay()? ​

optional timeOfDay(): number

Defined in: scope.ts:72

Time of day in [0, 1): midnight 0.0, sunrise 0.25, noon 0.5, sunset 0.75.

Returns ​

number

timeStamp()? ​

optional timeStamp(): number

Defined in: scope.ts:76

Returns ​

number

Type Aliases ​

BinaryOperator ​

BinaryOperator = "+" | "-" | "*" | "/" | "<" | "<=" | ">" | ">=" | "==" | "!=" | "&&" | "||" | "??"

Defined in: ast.ts:44

The binary operators of the language, including ??.


DiagnosticCode ​

DiagnosticCode = "syntax-error" | "unknown-query" | "unknown-math-function" | "client-only-resource"

Defined in: diagnostics.ts:2

What a diagnostic reports.


EngineVersion ​

EngineVersion = readonly [number, number, number]

Defined in: version.ts:2

A pack min_engine_version triple, as found in a manifest header.


ExpressionNode ​

ExpressionNode = NumberNode | StringNode | ReferenceNode | ThisNode | CallNode | UnaryNode | BinaryNode | TernaryNode | ArrowNode | IndexNode | AssignNode | BlockNode | LoopNode | ForEachNode | LoopControlNode

Defined in: ast.ts:119

Any expression form.


Keyword ​

Keyword = typeof KEYWORDS[number]

Defined in: lexer.ts:5

One of KEYWORDS.


MathFunctionName ​

MathFunctionName = keyof typeof MATH_FUNCTIONS

Defined in: math.ts:168

The name of a known math.* function.


MolangValue ​

MolangValue = number | string | MolangStruct | MolangScopeRef | MolangArray

Defined in: scope.ts:24

A runtime Molang value. Numbers carry booleans as 0.0 and 1.0.


QueryContextKind ​

QueryContextKind = "entity" | "block" | "item" | "world" | "placement" | "tags" | "pure"

Defined in: queries.ts:4

The scope member a query reads. tags resolves to the item when present, else the block.


StatementNode ​

StatementNode = ExpressionNode | ReturnNode

Defined in: ast.ts:137

A statement in a complex expression.


TokenKind ​

TokenKind = "number" | "string" | "identifier" | "keyword" | "operator"

Defined in: lexer.ts:8

The lexical category of a token.


VanillaQueryName ​

VanillaQueryName = keyof typeof VANILLA_QUERIES

Defined in: queries.ts:134

The name of a registered vanilla server-side query.

Variables ​

KEYWORDS ​

const KEYWORDS: readonly ["return", "loop", "for_each", "break", "continue", "this", "true", "false"]

Defined in: lexer.ts:2

Keywords the parser treats specially. Everything else that looks like a word is an identifier.


LATEST_RULES ​

const LATEST_RULES: MolangVersionRules

Defined in: version.ts:35

The rules the latest engine applies; used when a caller gives no version.


MATH_FUNCTIONS ​

const MATH_FUNCTIONS: object

Defined in: math.ts:95

The 61 documented math.* functions with Bedrock's semantics: trigonometry in degrees, sign(0) is -1, mod keeps the dividend's sign like C fmod, die_roll sums num random floats, and the 30 easing functions map (start, end, t) along the Penner curves.

Type Declaration ​

abs ​

readonly abs: MathFunction

acos ​

readonly acos: MathFunction

asin ​

readonly asin: MathFunction

atan ​

readonly atan: MathFunction

atan2 ​

readonly atan2: MathFunction

ceil ​

readonly ceil: MathFunction

clamp ​

readonly clamp: MathFunction

copy_sign ​

readonly copy_sign: MathFunction

cos ​

readonly cos: MathFunction

die_roll ​

readonly die_roll: MathFunction

die_roll_integer ​

readonly die_roll_integer: MathFunction

ease_in_back ​

readonly ease_in_back: MathFunction

ease_in_bounce ​

readonly ease_in_bounce: MathFunction

ease_in_circ ​

readonly ease_in_circ: MathFunction

ease_in_cubic ​

readonly ease_in_cubic: MathFunction

ease_in_elastic ​

readonly ease_in_elastic: MathFunction

ease_in_expo ​

readonly ease_in_expo: MathFunction

ease_in_out_back ​

readonly ease_in_out_back: MathFunction

ease_in_out_bounce ​

readonly ease_in_out_bounce: MathFunction

ease_in_out_circ ​

readonly ease_in_out_circ: MathFunction

ease_in_out_cubic ​

readonly ease_in_out_cubic: MathFunction

ease_in_out_elastic ​

readonly ease_in_out_elastic: MathFunction

ease_in_out_expo ​

readonly ease_in_out_expo: MathFunction

ease_in_out_quad ​

readonly ease_in_out_quad: MathFunction

ease_in_out_quart ​

readonly ease_in_out_quart: MathFunction

ease_in_out_quint ​

readonly ease_in_out_quint: MathFunction

ease_in_out_sine ​

readonly ease_in_out_sine: MathFunction

ease_in_quad ​

readonly ease_in_quad: MathFunction

ease_in_quart ​

readonly ease_in_quart: MathFunction

ease_in_quint ​

readonly ease_in_quint: MathFunction

ease_in_sine ​

readonly ease_in_sine: MathFunction

ease_out_back ​

readonly ease_out_back: MathFunction

ease_out_bounce ​

readonly ease_out_bounce: MathFunction

ease_out_circ ​

readonly ease_out_circ: MathFunction

ease_out_cubic ​

readonly ease_out_cubic: MathFunction

ease_out_elastic ​

readonly ease_out_elastic: MathFunction

ease_out_expo ​

readonly ease_out_expo: MathFunction

ease_out_quad ​

readonly ease_out_quad: MathFunction

ease_out_quart ​

readonly ease_out_quart: MathFunction

ease_out_quint ​

readonly ease_out_quint: MathFunction

ease_out_sine ​

readonly ease_out_sine: MathFunction

exp ​

readonly exp: MathFunction

floor ​

readonly floor: MathFunction

hermite_blend ​

readonly hermite_blend: MathFunction

inverse_lerp ​

readonly inverse_lerp: MathFunction

lerp ​

readonly lerp: MathFunction

lerprotate ​

readonly lerprotate: MathFunction

ln ​

readonly ln: MathFunction

max ​

readonly max: MathFunction

min ​

readonly min: MathFunction

min_angle ​

readonly min_angle: MathFunction

mod ​

readonly mod: MathFunction

pi ​

readonly pi: MathFunction

pow ​

readonly pow: MathFunction

random ​

readonly random: MathFunction

random_integer ​

readonly random_integer: MathFunction

round ​

readonly round: MathFunction

sign ​

readonly sign: MathFunction

sin ​

readonly sin: MathFunction

sqrt ​

readonly sqrt: MathFunction

trunc ​

readonly trunc: MathFunction


MOLANG_EXAMPLES ​

const MOLANG_EXAMPLES: readonly MolangExample[]

Defined in: examples.ts:32

Expressions that compile and evaluate on this engine, each with the values it produces.

The README shows exactly these sources, and examples.test.ts fails when the two differ or when an example stops producing its values, so none of them can quietly rot. A tool that wants real Molang to try - an editor, a playground, a documentation page - can take them from here.


VANILLA_QUERIES ​

const VANILLA_QUERIES: object

Defined in: queries.ts:26

The 21 queries the vanilla behavior pack uses server-side, keyed without the query. prefix. Each declares the scope context it reads.

Type Declaration ​

above_top_solid ​

readonly above_top_solid: object

above_top_solid.context ​

readonly context: "placement" = 'placement'

above_top_solid.evaluate ​

readonly evaluate: (scope, args) => number

Parameters ​
scope ​

MolangScope

args ​

readonly MolangValue[]

Returns ​

number

all_tags ​

readonly all_tags: object

all_tags.context ​

readonly context: "tags" = 'tags'

all_tags.evaluate ​

readonly evaluate: (scope, args) => 0 | 1

Parameters ​
scope ​

MolangScope

args ​

readonly MolangValue[]

Returns ​

0 | 1

anger_level ​

readonly anger_level: object

anger_level.context ​

readonly context: "entity" = 'entity'

anger_level.evaluate ​

readonly evaluate: (scope) => number

Parameters ​
scope ​

MolangScope

Returns ​

number

any_tag ​

readonly any_tag: object

any_tag.context ​

readonly context: "tags" = 'tags'

any_tag.evaluate ​

readonly evaluate: (scope, args) => 0 | 1

Parameters ​
scope ​

MolangScope

args ​

readonly MolangValue[]

Returns ​

0 | 1

block_state ​

readonly block_state: object

block_state.context ​

readonly context: "block" = 'block'

block_state.evaluate ​

readonly evaluate: (scope, args) => string | number

Parameters ​
scope ​

MolangScope

args ​

readonly MolangValue[]

Returns ​

string | number

equipment_count ​

readonly equipment_count: object

equipment_count.context ​

readonly context: "entity" = 'entity'

equipment_count.evaluate ​

readonly evaluate: (scope) => number

Parameters ​
scope ​

MolangScope

Returns ​

number

had_component_group ​

readonly had_component_group: object

had_component_group.context ​

readonly context: "entity" = 'entity'

had_component_group.evaluate ​

readonly evaluate: (scope, args) => 0 | 1

Parameters ​
scope ​

MolangScope

args ​

readonly MolangValue[]

Returns ​

0 | 1

has_any_family ​

readonly has_any_family: object

has_any_family.context ​

readonly context: "entity" = 'entity'

has_any_family.evaluate ​

readonly evaluate: (scope, args) => 0 | 1

Parameters ​
scope ​

MolangScope

args ​

readonly MolangValue[]

Returns ​

0 | 1

has_biome_tag ​

readonly has_biome_tag: object

has_biome_tag.context ​

readonly context: "placement" = 'placement'

has_biome_tag.evaluate ​

readonly evaluate: (scope, args) => 0 | 1

Parameters ​
scope ​

MolangScope

args ​

readonly MolangValue[]

Returns ​

0 | 1

head_is_in_water ​

readonly head_is_in_water: object

head_is_in_water.context ​

readonly context: "entity" = 'entity'

head_is_in_water.evaluate ​

readonly evaluate: (scope) => 0 | 1

Parameters ​
scope ​

MolangScope

Returns ​

0 | 1

heightmap ​

readonly heightmap: object

heightmap.context ​

readonly context: "placement" = 'placement'

heightmap.evaluate ​

readonly evaluate: (scope, args) => number

Parameters ​
scope ​

MolangScope

args ​

readonly MolangValue[]

Returns ​

number

is_baby ​

readonly is_baby: object

is_baby.context ​

readonly context: "entity" = 'entity'

is_baby.evaluate ​

readonly evaluate: (scope) => 0 | 1

Parameters ​
scope ​

MolangScope

Returns ​

0 | 1

is_on_ground ​

readonly is_on_ground: object

is_on_ground.context ​

readonly context: "entity" = 'entity'

is_on_ground.evaluate ​

readonly evaluate: (scope) => 0 | 1

Parameters ​
scope ​

MolangScope

Returns ​

0 | 1

is_using_item ​

readonly is_using_item: object

is_using_item.context ​

readonly context: "entity" = 'entity'

is_using_item.evaluate ​

readonly evaluate: (scope) => 0 | 1

Parameters ​
scope ​

MolangScope

Returns ​

0 | 1

last_hit_by_player ​

readonly last_hit_by_player: object

last_hit_by_player.context ​

readonly context: "entity" = 'entity'

last_hit_by_player.evaluate ​

readonly evaluate: (scope) => 0 | 1

Parameters ​
scope ​

MolangScope

Returns ​

0 | 1

max_durability ​

readonly max_durability: object

max_durability.context ​

readonly context: "item" = 'item'

max_durability.evaluate ​

readonly evaluate: (scope) => number

Parameters ​
scope ​

MolangScope

Returns ​

number

noise ​

readonly noise: object

noise.context ​

readonly context: "placement" = 'placement'

noise.evaluate ​

readonly evaluate: (scope, args) => number

Parameters ​
scope ​

MolangScope

args ​

readonly MolangValue[]

Returns ​

number

player_level ​

readonly player_level: object

player_level.context ​

readonly context: "entity" = 'entity'

player_level.evaluate ​

readonly evaluate: (scope) => number

Parameters ​
scope ​

MolangScope

Returns ​

number

property ​

readonly property: object

property.context ​

readonly context: "entity" = 'entity'

property.evaluate ​

readonly evaluate: (scope, args) => string | number

Parameters ​
scope ​

MolangScope

args ​

readonly MolangValue[]

Returns ​

string | number

remaining_durability ​

readonly remaining_durability: object

remaining_durability.context ​

readonly context: "item" = 'item'

remaining_durability.evaluate ​

readonly evaluate: (scope) => number

Parameters ​
scope ​

MolangScope

Returns ​

number

variant ​

readonly variant: object

variant.context ​

readonly context: "entity" = 'entity'

variant.evaluate ​

readonly evaluate: (scope) => number

Parameters ​
scope ​

MolangScope

Returns ​

number

Functions ​

compileProgram() ​

compileProgram(source, program, rules, queries): CompiledMolang

Defined in: compiler.ts:86

Compiles a parsed program into a closure over a scope.

Parameters ​

source ​

string

program ​

ProgramNode

rules ​

MolangVersionRules

queries ​

QueryRegistry

Returns ​

CompiledMolang


parse() ​

parse(source, rules): ProgramNode

Defined in: parser.ts:283

Parses Molang source text into an AST under the given versioned rules.

Parameters ​

source ​

string

rules ​

MolangVersionRules

Returns ​

ProgramNode

Throws ​

When the text is not a valid Molang expression.


rulesForEngineVersion() ​

rulesForEngineVersion(version): MolangVersionRules

Defined in: version.ts:26

Derives the versioned language rules from a pack's min_engine_version.

Parameters ​

version ​

EngineVersion

Returns ​

MolangVersionRules


tokenize() ​

tokenize(source): Token[]

Defined in: lexer.ts:43

Splits Molang source text into tokens. Molang is case-insensitive except inside strings, so identifiers and keywords are lowercased here and string contents are preserved.

Parameters ​

source ​

string

Returns ​

Token[]

Throws ​

When the text contains an unexpected character or an unterminated string.