Syntax
Comments
Single-line comments start with //
and continue until the end of the line.
Multiline comments start with /*
and end with */
.
These comments are completely ignored by the compiler and will not show up in the generated data pack. If you want to include a comment in the data pack, you can use the doccomment syntax.
Literal Commands
Literal commands are commands that are directly included in the output.
They start with a /
and are followed by the command.
This will result in say Hello, world!
being included in the .mcfunction
file.
Functions
Functions are blocks of code that can be executed.
They start with fn
followed by the name of the function, parenthesis and a block of code.
Optionally they can be preceeded by annotations. When a function has the pub
keyword in front of it, it will be accessible from other files.
This code defines a function called main
that will be executed every tick.
Annotations
Annotations are special attributes that can be attached to functions.
They start with #
followed by the name of the annotation in square brackets. Some annotations can have arguments assigned to them with the =
operator.
Currently, the following annotations are supported:
#[tick]
: The function will be executed every tick.#[load]
: The function will be executed when the data pack is loaded.#[deobfuscate]
: The function will keep the original name in the output (path of the.shu
-file followed by the function name).#[deobfuscate = "path/to/function"]
: The function will be named as specified in the argument.
Function calls
Functions can be called by using their name followed by parenthesis.
Imports
Functions from other files can be imported by using the from
-import
syntax.
Multiple functions can be imported by separating them with a comma.
Tags
In Minecraft, tags are used to group multiple items, blocks, entities, etc. together. In Shulkerscript, tags can be defined right in the code, where they are needed.
This will result in a tag of type block
with the name foo
containing the blocks minecraft:stone
and minecraft:dirt
.
If you want the tag to replace, instead of append to the existing tag, you can use the replace
keyword.
The type has to be the name of the subfolder in the tags
folder of the data pack. Most often you will use tags with
the types:
function
block
item
entity_type
fluid
game_event
But you can also use custom types, refer to this page for more information.
Conditional Statements
Conditional statements are used to execute code based on a condition.
They start with if
followed by a condition in parenthesis and a block of code.
Optionally they can be followed by an else
block.
To learn more about how to combine or negate conditions, refer to the if-else statement reference.
Execute Blocks
Execute blocks are used to execute a block of code in a specific context.
They consist of the keyword you would pass to the /execute
command followed the argument as a string in parenthesis and a block of code.
Multiple execute blocks can be chained together by separating them with a comma.
Supported Execute Blocks
align
anchored
as
at
asat
facing
if
in
on
positioned
rotated
store
summon
For general information on the execute command, refer to the Minecraft Wiki.
Groupings
Groupings are used to group multiple commands into one mcfunction
file without declaring a new function.
This can be used for commands that need to be executed atomically.
Run
The run
keyword is used to evaluate the following expression and include the resulting command in the output.
Lua Code
The lua
keyword is used to embed Lua code in your Shulkerscript code. It can be combined with the run
keyword to include the result of the Lua code in the output.