/function
Runs a function or function tag from a data pack. Functions are .mcfunction files containing a list of commands.
Syntax
/function <name> [with <storage> [<path>]]Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| name | resource | Required | The function or function tag to execute (e.g., mypack:my_function or #mypack:my_tag). |
| storage | resource | Optional | A data storage to pass as macro arguments (1.20.2+, used with 'with' keyword). |
| path | nbt_path | Optional | The NBT path within the storage for macro arguments. |
Examples
/function my_pack:setupRuns all commands in the my_pack:setup function.
/function #minecraft:loadRuns all functions in the minecraft:load function tag.
/function my_pack:greet with storage my_pack:data playerRuns the greet function with macro arguments from a data storage.
Common Mistakes
- Using # prefix for individual functions, # is for function tags, not individual functions.
- Forgetting to /reload after adding new function files to a data pack.
Notes
Functions run sequentially, one command per line. The function inherits the execution context of the calling command. Since 1.20.2, macros allow parameterized functions using $() syntax.
Related Commands
Need a Minecraft server?
Try these commands on Astroworld or host your own server.
Try Astroworld Hosting