Skip to content

API reference / @jsprismarine/mcfunction

@jsprismarine/mcfunction ​

Join the Discord Servernpm

The Java Edition mcfunction runtime: it loads .mcfunction files and function tags from a pack stack, compiles them once, and runs them against a command runner you supply. It parses the file format, expands macro lines, resolves function tags, and bounds a run with the two gamerules that Java bounds it with. It does not implement a single command.

ts
import { FunctionExecutor, RecordingCommandRunner, loadFunctions } from '@jsprismarine/mcfunction';

const { functions, tags, diagnostics } = loadFunctions([{ name: 'my pack', files }]);
const runner = new RecordingCommandRunner();
const executor = new FunctionExecutor({ functions, tags, runner });

executor.runLoad({ source: console }); // once, after the packs load
executor.runTick({ source: console }); // once per server tick

What this buys, and what it does not ​

Vanilla ships no functions. The Java 26.3 server jar has 9884 files under data/minecraft/ and zero of them are .mcfunction; it has 883 tag files and none of them tags the function registry. Bedrock is the same: Mojang/bedrock-samples at 1.26.50.4 has 22258 files, no .mcfunction and no tick.json. Both editions have a function runtime and neither uses it for vanilla gameplay.

So this package buys no vanilla parity on its own. What it buys is the ability to run a third-party Java datapack, and a place to write server behavior as data rather than as TypeScript. Parity comes from the commands a function calls into, which live elsewhere.

The file format ​

One command per line, written without a leading slash. A line is a comment when its first non-whitespace character is #, and blank lines are skipped. A line whose last non-whitespace character is `` continues into the next line, whose leading and trailing whitespace is stripped before it is appended. A command may be at most 2000000 characters.

Two mistakes are rejected rather than guessed at, because Java rejects them by name: a line that starts with //, which is not a comment marker here, and a line that starts with /. A file with any error does not load at all, which is what the Java server does when CommandFunction.fromLines throws.

A function id comes from its path. data/pack/function/setup/stage.mcfunction loads as pack:setup/stage, using the singular function directory that 26.3 uses.

Macro lines ​

A line whose first non-whitespace character is $ is a macro line. It carries one or more $(variable) substitutions, and the call must pass a compound holding an entry for each of them. Extra entries in the compound are ignored, and a plain function called with a compound ignores it entirely.

mcfunction
say starting
$say hello $(name), you have $(count) items

A $ is literal unless ( follows it, which is the only escape the format has. A string argument goes in raw, with no quoting and no escaping, so a value carrying a quote can produce a command that no longer parses. Numbers go in without the type suffix they would carry in NBT, matching the 1.20.2 fix; a nested compound or list is rendered as SNBT, where suffixes are back because the text is NBT again. A missing entry reports the macro arguments have no entry for '<name>' and the whole call is skipped, the way Java skips a call whose macro cannot be instantiated.

Macro lines are the one part of the format that costs something per call, because the substituted text has to be parsed again. Each macro function keeps the 8 most recent argument sets, matching MAX_CACHE_ENTRIES in Java's MacroFunction, and keys them on the values the macro actually references, so extra compound entries do not split the cache.

Function tags ​

A function #namespace:tag line runs every function the tag names, in order, with nested tags expanded where they appear. A function named twice runs once. A cycle between tags is reported and cut rather than followed.

Two tags are special, and they are the only two the Java server looks up by name: minecraft:load, which runs once after the packs load, and minecraft:tick, which runs on every server tick. FunctionExecutor exposes them as runLoad and runTick.

Tags merge across the stack rather than replacing. Two packs that both add to minecraft:tick both run, unless the later one sets "replace": true. Functions are the opposite: a later pack that declares the same id replaces the earlier file whole. loadFunctions applies both rules, and FunctionTagRegistry is the lookup FunctionExecutor resolves tags through. The lookup is injected, so a server that already holds its tags somewhere else can pass its own.

The limits, and how sure we are of them ​

A run is bounded by the two gamerules Java bounds it with. Both were renamed in 1.21.11, so the camelCase names you may have seen are stale.

RuleCountsDefault here
minecraft:max_command_sequence_length (was maxCommandChainLength)operations65536
minecraft:max_command_forks (was maxCommandForkCount)contexts65536

Mojang has never published either default. The figure 65536 has two independent secondary confirmations, minecraft.wiki's gamerule page and Pumpkin's extraction from the real 26.3 server jar, and 65536 is in the GameRules class constant pool, but no Mojang document attributes the value to either rule. Treat it as a well-corroborated default rather than a confirmed one. Both are configurable per executor:

ts
new FunctionExecutor({ functions, runner, limits: { maxCommandSequenceLength: 10_000 } });

An operation here is one command line run or one function invoked, which is this runtime's reading of the three kinds the 1.20.3 changelog enumerates. A context is whatever a command reports as forks: execute as @e matching five entities reports 5, and the runner is what knows that, so fork counting is only as accurate as the runner's reporting.

Reaching either limit stops the run, records the reason in report.stopped, and adds a diagnostic. Nothing throws. Everything a call reaches shares one budget, so the report covers the whole tree below the entry point.

Bedrock's equivalent is a smaller per-call cap, 10000 commands, exported as BEDROCK_MAX_COMMANDS_PER_FUNCTION. This runtime runs Java functions and does not apply it; pass it as maxCommandSequenceLength if you want Bedrock's ceiling.

The command seam ​

This package implements no commands. Every line it does not handle itself goes to a CommandRunner:

ts
interface CommandRunner<TSource> {
    run(commandLine: string, context: CommandContext<TSource>): { result?: number; forks?: number };
}

The context carries the source you passed to the run, plus the function id and line number the command came from, which is what diagnostics and logs need. The server's Brigadier dispatcher is the real adapter at this seam - packages/prismarine/src/command/function/ holds it, and routes every line into the @jsprismarine/commands tree with the source made silent, as Java does. RecordingCommandRunner is the other one, and it records what a function would run so a test or a pack author can inspect it without a world.

A runner may throw. The executor reports the failure and continues with the next line, because one failing command does not abort a Java function.

/return is split across the seam. The runner implements the command, because it is one, and reports it back as returned; only the executor can act on it, because ending a function means dropping a frame. A line that reports returned ends the function it came from, and the loop carries on with whatever called it. returned.value is what the function returns, and a /return fail or a return run whose command failed ends the function without one. The report collects the values of the functions the entry point invoked directly, in returnValues, so #a:tag whose three members returned 0, nothing and 5 reports [0, 5]. A /return deeper in the call tree ends its own function and contributes nothing, which is Java's rule: /return returns from one function, not from its caller.

The one exception is a function line, which the executor reads itself. A call is control flow rather than a command, and handling it here is what keeps nesting on the queue. The line form is function <id>, function #<tag>, or either of those followed by an argument compound. The compound is read as JSON by default, because SNBT needs a parser this package does not own; pass parseArguments to supply one. Java's function <id> with block|entity|storage forms need a world to read from and are not supported yet.

Why the executor uses a queue ​

Java rewrote function execution in 23w41a, moving the call stack onto the heap: ExecutionContext holds a Deque of queued commands, a commandQuota and a Frame type carrying its own depth. That rewrite is what lets the gamerules bound work and what closed MC-265805, where a tail-recursive function consumed memory linearly with depth.

This executor has the same shape: an array of frames, one loop, and a counter charged per operation. Nesting 20000 functions deep does not touch the JavaScript stack, and a call made from the last line of a function replaces its frame instead of stacking on it, so a tail-recursive function runs at constant depth until the operation limit stops it. Both are covered by tests.

Reporting ​

Loading, compiling and running all report problems instead of throwing. Each diagnostic carries a severity, a stable code, a message, and whichever of functionId, line and pack apply. A broken file is left out of the registry and the rest of the stack still loads.

Further reading ​

The research note on commands, functions and datapack execution is where the facts above come from, including what was measured in Mojang's own files and what could not be confirmed.

Classes ​

Interfaces ​

CommandContext ​

Defined in: runner.ts:9

What a command is told about the line it was reached from.

Type Parameters ​

TSource ​

TSource = unknown

Properties ​

functionId ​

functionId: string

Defined in: runner.ts:13

The namespaced id of the function the line belongs to.

line ​

line: number

Defined in: runner.ts:15

The 1-based line of that function's file.

source ​

source: TSource

Defined in: runner.ts:11

Whatever the server uses as a command source, passed through untouched.


CommandOutcome ​

Defined in: runner.ts:19

What a command reports back.

Properties ​

forks? ​

optional forks?: number

Defined in: runner.ts:27

How many contexts the command created, which is what maxCommandForks counts. execute as @e with five matching entities reports 5. A command that runs in one context reports nothing.

result? ​

optional result?: number

Defined in: runner.ts:21

The command's integer result, as Brigadier defines it. Defaults to 0.

returned? ​

optional returned?: object

Defined in: runner.ts:37

Set when the line ended the function it belongs to, which is what /return does. The executor drops that function's remaining lines and carries on with whatever called it.

value is what the function returns. /return fail, and a /return run whose command failed, end the function without one, which is the case execute if function does not match.

value? ​

readonly optional value?: number


CommandRunner ​

Defined in: runner.ts:41

Runs one command line. The server's dispatcher is the real adapter at this seam.

Type Parameters ​

TSource ​

TSource = unknown

Methods ​

run() ​

run(commandLine, context): CommandOutcome

Defined in: runner.ts:50

Runs one command, written without a leading slash.

The runtime never calls this with a command the line format already handles, so a function line never reaches it. Throwing is allowed: the executor catches it, reports it, and carries on with the next line, the way one failing command does not abort a Java function.

Parameters ​
commandLine ​

string

context ​

CommandContext<TSource>

Returns ​

CommandOutcome


CompileResult ​

Defined in: compile.ts:140

What compileFunction produces.

Properties ​

diagnostics ​

diagnostics: readonly Diagnostic[]

Defined in: compile.ts:143

function? ​

optional function?: CompiledFunction

Defined in: compile.ts:142

The compiled function, or undefined when the file did not compile.


Diagnostic ​

Defined in: diagnostics.ts:45

One reported problem, carrying enough location to find it in a pack.

Properties ​

code ​

code: DiagnosticCode

Defined in: diagnostics.ts:47

functionId? ​

optional functionId?: string

Defined in: diagnostics.ts:50

The namespaced id of the function the problem is in, when there is one.

line? ​

optional line?: number

Defined in: diagnostics.ts:52

The 1-based line number inside that function, when the problem has one.

message ​

message: string

Defined in: diagnostics.ts:48

pack? ​

optional pack?: string

Defined in: diagnostics.ts:54

The name of the pack the file came from, for problems found while loading.

severity ​

severity: DiagnosticSeverity

Defined in: diagnostics.ts:46


ExecutionLimits ​

Defined in: executor.ts:23

The two gamerules that bound a run. They were renamed in 1.21.11 from maxCommandChainLength and maxCommandForkCount; anything written against the camelCase names is stale.

Properties ​

maxCommandForks ​

maxCommandForks: number

Defined in: executor.ts:27

minecraft:max_command_forks: how many contexts one entry point may create.

maxCommandSequenceLength ​

maxCommandSequenceLength: number

Defined in: executor.ts:25

minecraft:max_command_sequence_length: how many operations one entry point may run.


ExecutionOptions ​

Defined in: executor.ts:76

What one call needs beyond the function to run.

Type Parameters ​

TSource ​

TSource = unknown

Properties ​

arguments? ​

optional arguments?: Readonly<Record<string, unknown>>

Defined in: executor.ts:80

The compound a macro function substitutes from. Ignored by a plain function.

source ​

source: TSource

Defined in: executor.ts:78

The command source every command in the run is given.


ExecutionReport ​

Defined in: executor.ts:87

What one run did.

Properties ​

commands ​

commands: number

Defined in: executor.ts:93

How many command lines reached the runner.

diagnostics ​

diagnostics: readonly Diagnostic[]

Defined in: executor.ts:112

forks ​

forks: number

Defined in: executor.ts:91

Contexts charged against maxCommandForks.

invocations ​

invocations: number

Defined in: executor.ts:95

How many functions the run invoked, including the entry point.

maxDepth ​

maxDepth: number

Defined in: executor.ts:97

The deepest the frame stack got. A tail call does not deepen it.

operations ​

operations: number

Defined in: executor.ts:89

Operations charged against maxCommandSequenceLength.

returnValues ​

returnValues: readonly number[]

Defined in: executor.ts:109

The values /return produced, one per function the entry point invoked directly that reached one.

Empty when every function ran to its last line, which is the case Java calls "returned no value". A tag contributes one entry per member that returned, because execute if function #tag matches when any member did. A /return deeper in the call tree ends its own function and leaves nothing here, the way Java returns from one function rather than from its caller.

stopped? ​

optional stopped?: ExecutionStop

Defined in: executor.ts:111

Set when a limit stopped the run; the matching diagnostic carries the detail.


FunctionExecutorOptions ​

Defined in: executor.ts:60

How to build a FunctionExecutor.

Type Parameters ​

TSource ​

TSource = unknown

Properties ​

functions ​

functions: FunctionLookup

Defined in: executor.ts:61

limits? ​

optional limits?: Partial<ExecutionLimits>

Defined in: executor.ts:66

Overrides either limit; anything left out keeps its DEFAULT_EXECUTION_LIMITS value.

parseArguments? ​

optional parseArguments?: (text) => Readonly<Record<string, unknown>> | undefined

Defined in: executor.ts:72

Reads the argument compound of a function <id> <arguments> line. The default accepts JSON, because SNBT needs a parser this package does not own; a server with one passes it here.

Parameters ​
text ​

string

Returns ​

Readonly<Record<string, unknown>> | undefined

runner ​

runner: CommandRunner<TSource>

Defined in: executor.ts:62

tags? ​

optional tags?: FunctionTagLookup

Defined in: executor.ts:64

Resolves #namespace:tag references. Without it, a tag reference is reported as unknown.


FunctionLine ​

Defined in: parse.ts:18

One command the file declares, after comments, blank lines and continuations are resolved.

Properties ​

command ​

command: string

Defined in: parse.ts:22

The command text, without the leading $ of a macro line.

line ​

line: number

Defined in: parse.ts:20

The 1-based number of the line the command starts on.

macro ​

macro: boolean

Defined in: parse.ts:24

Whether the line is a macro line, so its $(name) substitutions run per call.


FunctionLoadResult ​

Defined in: registry.ts:65

What loadFunctions produces.

Properties ​

diagnostics ​

diagnostics: readonly Diagnostic[]

Defined in: registry.ts:68

functions ​

functions: FunctionRegistry

Defined in: registry.ts:66

tags ​

tags: FunctionTagRegistry

Defined in: registry.ts:67


FunctionLookup ​

Defined in: executor.ts:54

Where the executor reads compiled functions from.

Methods ​

get() ​

get(id): CompiledFunction | undefined

Defined in: executor.ts:56

Returns the function registered under a namespaced id.

Parameters ​
id ​

string

Returns ​

CompiledFunction | undefined


FunctionPack ​

Defined in: registry.ts:23

One pack's files, keyed by pack-relative path. Any pack reader can supply this: @jsprismarine/packs routes the JSON half of a datapack, and the .mcfunction files it does not consume come through here unchanged.

Properties ​

files ​

files: ReadonlyMap<string, string | Uint8Array<ArrayBufferLike>>

Defined in: registry.ts:26

name ​

name: string

Defined in: registry.ts:25

The pack's name, used to attribute diagnostics and to say which pack won.


FunctionReference ​

Defined in: identifiers.ts:15

A parsed reference to either one function or a function tag.

Properties ​

id ​

id: string

Defined in: identifiers.ts:19

The namespaced id, always with an explicit namespace and without the #.

kind ​

kind: "function" | "tag"

Defined in: identifiers.ts:17

Whether the reference named a tag (#namespace:path) or a single function.


FunctionTag ​

Defined in: tags.ts:29

One tag file's contents after the packs that declare it are merged.

Properties ​

replace? ​

optional replace?: boolean

Defined in: tags.ts:32

Whether the tag discards what earlier packs contributed.

values ​

values: readonly FunctionTagEntry[]

Defined in: tags.ts:30


FunctionTagLookup ​

Defined in: tags.ts:36

Where resolveFunctionTag reads tags from.

Methods ​

get() ​

get(tagId): FunctionTag | undefined

Defined in: tags.ts:38

Returns the tag registered under a namespaced id, without the #.

Parameters ​
tagId ​

string

Returns ​

FunctionTag | undefined


InstantiatedCommand ​

Defined in: compile.ts:23

One command a call is about to run.

Properties ​

command ​

command: string

Defined in: compile.ts:25

The command text, with every macro substitution already filled in.

line ​

line: number

Defined in: compile.ts:27

The 1-based line of the function file the command came from.


MacroTemplate ​

Defined in: macro.ts:15

A macro line compiled into the pieces a call concatenates.

Properties ​

segments ​

segments: readonly MacroSegment[]

Defined in: macro.ts:16

variables ​

variables: readonly string[]

Defined in: macro.ts:18

Every variable the line substitutes, once each, in first-use order.


ParsedFunction ​

Defined in: parse.ts:28

What parseFunctionSource produces.

Properties ​

diagnostics ​

diagnostics: readonly Diagnostic[]

Defined in: parse.ts:30

lines ​

lines: readonly FunctionLine[]

Defined in: parse.ts:29


RecordedCommand ​

Defined in: runner.ts:54

One command a RecordingCommandRunner was asked to run.

Type Parameters ​

TSource ​

TSource = unknown

Properties ​

commandLine ​

commandLine: string

Defined in: runner.ts:55

context ​

context: CommandContext<TSource>

Defined in: runner.ts:56


TagResolution ​

Defined in: tags.ts:42

The functions a tag names, in the order they run, plus anything that did not resolve.

Properties ​

diagnostics ​

diagnostics: readonly Diagnostic[]

Defined in: tags.ts:47

exists ​

exists: boolean

Defined in: tags.ts:46

Whether the tag itself exists. An empty tag that exists resolves to no functions.

functions ​

functions: readonly string[]

Defined in: tags.ts:44

The function ids, each once, in tag order with nested tags expanded in place.

Type Aliases ​

DiagnosticCode ​

DiagnosticCode = "line.double-slash-comment" | "line.leading-slash" | "line.too-long" | "line.dangling-continuation" | "macro.invalid" | "macro.missing-arguments" | "call.unknown-function" | "call.unknown-tag" | "call.invalid-arguments" | "command.failed" | "tag.cycle" | "tag.missing-entry" | "limit.command-sequence-length" | "limit.command-forks" | "load.invalid-file"

Defined in: diagnostics.ts:12

The problems this package reports.


DiagnosticSeverity ​

DiagnosticSeverity = "error" | "warning"

Defined in: diagnostics.ts:9

How serious a diagnostic is. An error means the affected function did not load or did not run.


ExecutionStop ​

ExecutionStop = "max-command-sequence-length" | "max-command-forks"

Defined in: executor.ts:84

Why a run stopped before it finished.


FunctionTagEntry ​

FunctionTagEntry = string | { id: string; required?: boolean; }

Defined in: tags.ts:26

One entry of a tag file: a function id, a #tag reference, or the object form, whose required: false lets a pack reference something that may not be installed.


InstantiationResult ​

InstantiationResult = { commands: readonly InstantiatedCommand[]; ok: true; } | { line?: number; message: string; ok: false; }

Defined in: compile.ts:31

The outcome of instantiating a function for one call.


MacroArguments ​

MacroArguments = Readonly<Record<string, unknown>>

Defined in: macro.ts:9

The compound a macro call substitutes from. Extra entries are ignored.


MacroSegment ​

MacroSegment = { text: string; } | { variable: string; }

Defined in: macro.ts:12

One piece of a compiled macro line: literal text, or a hole naming a variable.


MacroSubstitutionResult ​

MacroSubstitutionResult = { command: string; ok: true; } | { message: string; ok: false; }

Defined in: macro.ts:25

The outcome of filling a template from an argument compound.


MacroTemplateResult ​

MacroTemplateResult = { ok: true; template: MacroTemplate; } | { message: string; ok: false; }

Defined in: macro.ts:22

The outcome of compiling a macro line.

Variables ​

BEDROCK_MAX_COMMANDS_PER_FUNCTION ​

const BEDROCK_MAX_COMMANDS_PER_FUNCTION: 10000 = 10_000

Defined in: executor.ts:51

What Bedrock caps a single /function call at, from Mojang's creator documentation. This runtime runs Java functions and does not apply it; a server that wants Bedrock's ceiling passes it as maxCommandSequenceLength.


DEFAULT_EXECUTION_LIMITS ​

const DEFAULT_EXECUTION_LIMITS: ExecutionLimits

Defined in: executor.ts:41

The limits a run uses when the caller sets none.

Both default to 65536. Mojang has never published either default: the figure has two independent secondary confirmations (minecraft.wiki's gamerule page and Pumpkin's extraction from the 26.3 server jar) and the GameRules class holds 65536 in its constant pool, but no Mojang document attributes the value to either rule. Treat it as a well-corroborated default rather than a confirmed one, and configure it when a world says otherwise.


DEFAULT_NAMESPACE ​

const DEFAULT_NAMESPACE: "minecraft" = 'minecraft'

Defined in: identifiers.ts:12

The namespace an id without a colon belongs to.


FUNCTION_EXTENSION ​

const FUNCTION_EXTENSION: ".mcfunction" = '.mcfunction'

Defined in: identifiers.ts:48

The file extension of a function file.


LOAD_FUNCTION_TAG ​

const LOAD_FUNCTION_TAG: "minecraft:load" = 'minecraft:load'

Defined in: tags.ts:16

The tag whose functions run once after the packs load.


MACRO_CACHE_ENTRIES ​

const MACRO_CACHE_ENTRIES: 8 = 8

Defined in: compile.ts:20

How many argument sets one macro function remembers. Java's MacroFunction carries 8 as its only integer constant, and caches only the values the macro actually references, so extra entries in the compound do not split the cache.


MAX_COMMAND_LENGTH ​

const MAX_COMMAND_LENGTH: 2000000 = 2_000_000

Defined in: parse.ts:15

The longest a single command may be, in characters. Java's CommandFunction carries 2000000 as its only integer constant and rejects a longer line with "Command too long".


TICK_FUNCTION_TAG ​

const TICK_FUNCTION_TAG: "minecraft:tick" = 'minecraft:tick'

Defined in: tags.ts:19

The tag whose functions run on every server tick.

Functions ​

compileFunction() ​

compileFunction(id, source): CompileResult

Defined in: compile.ts:156

Compiles one function file.

A file with any error does not produce a function, matching the Java server, where a file that fails CommandFunction.fromLines is logged and left out of the function library rather than partly loaded.

Parameters ​

id ​

string

The namespaced id the file loads under.

source ​

string

The text of the .mcfunction file.

Returns ​

CompileResult


compileMacroLine() ​

compileMacroLine(command): MacroTemplateResult

Defined in: macro.ts:44

Compiles one macro line into a reusable template.

$ is literal unless it is followed by (, which is the only escape the format has. A line marked as a macro but carrying no substitution is an error, as is an unterminated $( or a name outside letters, digits and _.

Parameters ​

command ​

string

Returns ​

MacroTemplateResult


functionIdForPath() ​

functionIdForPath(path): string | undefined

Defined in: identifiers.ts:56

Derives a function id from a pack-relative path, following the 26.3 layout data/<namespace>/function/<path>.mcfunction.

Parameters ​

path ​

string

Returns ​

string | undefined

The namespaced id, or undefined when the path is not a function file.


functionTagIdForPath() ​

functionTagIdForPath(path): string | undefined

Defined in: identifiers.ts:75

Derives a function tag id from a pack-relative path, following data/<namespace>/tags/function/<path>.json.

Parameters ​

path ​

string

Returns ​

string | undefined

The namespaced tag id without a #, or undefined when the path is not a function tag.


loadFunctions() ​

loadFunctions(packs): FunctionLoadResult

Defined in: registry.ts:145

Loads every function and function tag a pack stack declares.

Packs apply in order. A function id a later pack also declares is replaced whole; a tag a later pack also declares is merged, unless that pack sets replace. A file that does not compile is reported and left out, so one broken function does not stop the rest of the stack from loading.

Parameters ​

packs ​

readonly FunctionPack[]

Returns ​

FunctionLoadResult


normalizeIdentifier() ​

normalizeIdentifier(text): string | undefined

Defined in: identifiers.ts:27

Normalizes a namespaced id, filling in the default namespace.

Parameters ​

text ​

string

Returns ​

string | undefined

The namespace:path form, or undefined when either half is not a legal id.


parseFunctionReference() ​

parseFunctionReference(text): FunctionReference | undefined

Defined in: identifiers.ts:40

Parses the argument of a /function call or a function tag entry.

Parameters ​

text ​

string

Returns ​

FunctionReference | undefined

The reference, or undefined when the text is not a legal id.


parseFunctionSource() ​

parseFunctionSource(source): ParsedFunction

Defined in: parse.ts:47

Parses the text of one .mcfunction file into its command lines.

A line is dropped when it is blank or starts with #. A line whose last non-whitespace character is \ continues into the next line, which is trimmed before being appended. A line whose first non-whitespace character is $ is a macro line and keeps its substitutions unevaluated.

Problems are reported rather than thrown; the caller decides whether a function with errors is registered.

Parameters ​

source ​

string

Returns ​

ParsedFunction


renderMacroValue() ​

renderMacroValue(value): string

Defined in: macro.ts:109

Renders one argument the way a substitution inserts it: a string goes in raw, with no quoting and no escaping, so a value carrying quotes can produce a command that no longer parses. Numbers lose the type suffix they would carry in NBT, matching the 1.20.2 fix. A compound or list becomes SNBT, where suffixes are back because the text is NBT again.

Parameters ​

value ​

unknown

Returns ​

string


resolveFunctionTag() ​

resolveFunctionTag(lookup, tagId): TagResolution

Defined in: tags.ts:60

Expands a function tag into the functions it names.

Entries apply in order and a nested #tag expands where it appears. A function already named earlier is not repeated. A cycle between tags is reported and cut rather than followed, and a missing entry is reported only when the entry does not say required: false.

Parameters ​

lookup ​

FunctionTagLookup

tagId ​

string

The tag id, with or without the leading #.

Returns ​

TagResolution


substituteMacro() ​

substituteMacro(template, args): MacroSubstitutionResult

Defined in: macro.ts:83

Fills a compiled macro line from an argument compound.

Parameters ​

template ​

MacroTemplate

args ​

MacroArguments

Returns ​

MacroSubstitutionResult

The command to parse, or the reason the call cannot be instantiated.