This page is validated and up to date with Minecraft Java: 1.21.11
/function command
This command runs any .mcfunction file when called. You can also pass in a NBT
compound or NBT source path if the function is a macro function. All functions
are run independently and one after another - for example, if you run function1 and then function2, then function2 will only run once function1 has finished.
Syntax
function <namespace>:<function>: Runs the.mcfunctionfile atdata/<namespace>/function/<function>function <namespace>:<function> {key:value}: Runs the.mcfunctionfile atdata/<namespace>/function/<function>, and uses the{key:value}if the function is a macro function.function <namespace>:<function> with (block <targetPos>|entity <target>|storage <id>) <path>: Runs the.mcfunctionfile atdata/<namespace>/function/<function>, and uses the NBT source if the function is a macro function.
tip
You can stop a function running in real-time using the return command.