- Folder context refers to where functions and directories can be defined.
- Function context refers to syntax inside of functions where commands can be written.
- Macro context refers to the folder context inside of
You can create functions using the
Functions can only be defined within Folder context
You can create sub directories using the
Directories can only be defined within Folder context
Function blocks are used to define groups of commands that will be wrapped up into a function on compile-time.
block keyword will define a block and inline the generated function call:
Function blocks can also be defined at the end of execute commands:
Keep in mind that if you do not omit the
block keyword after an
execute command it will always define a function, even if the block only contains a single command. If omitted and only 1 command is inside the block instead of making a function it will just append that command to the end of the
execute command. For example:
Would compile to
execute if score @s value matches 1 run tellraw @s "Value was 1"
Function blocks can also be named using the
This allows for manual naming to remove the
__generated__ folders from your datapack if you so choose.
Function blocks can only be defined and used within Function context
Clocks are an easy way of running a function every x amount of time. For instance you could create a clock that runs every 5 seconds like this:
The time argument takes a
schedule command time input (
Clocks can only be defined and used within Folder context
while loop can be used to run a set of commands while a condition (defined as an
execute subcommand chain) is true. It will halt the execution of the function until the loop exits:
This will loop until the value of
#i is greater than
10, and then it will exit the loop and continue running the function
The async while loop will run a set of commands every x amount of time until it's condition is true without halting the execution of the function.
async while loop can also have a
finally function block defined that will execute it's contents once the loop exits:
until loop will run a set of commands every x amount of time until the condition is met. It will not halt function execution:
blocking until and the
finally block are planned but not implemented as of yet.
while, async while, and until can only be defined and used within Function context
WARNING This feature is experimental. It may not always work the way you expect
You can use
() curved brackets to surround a command to allow newlines in that command:
Multiline commands can only be defined and used within Function context
Inline JS blocks are JS code wrapped in
%>. Whatever the JS inside of those brackets returns will be what is inserted into the command/line:
Inline JS blocks cannot span multiple lines.
Multiline JS blocks are JS code wrapped in
The opening and closing brackets must be the only thing on their line. Only whitespace is allowed before them
Inline and Multiline JS blocks can only be defined and used within Function context
The compile time if statement can be used to omit code and/or functions if a certain condition is not met. For example if you didn't want a dev function to export unless a flag was true in the config you could do something like this:
This would only generate that function IF config.dev is set to
Same as !IF, but less to type:
Compile time LOOP allows you to generate code based off of a JS iterable value. The second argument is the loop variable that will be passed to the context inside the loop.
Compile time logic (!IF shorthand compile time if, and LOOP) can be defined and used within Function and Folder context
Execute if else blocks allow you to write run-time if else logic with ease:
Execute if else blocks can be defined and used within Function context