namespace:path points at data/namespace/function/path.mcfunction inside your datapack (the folder is named functions before 1.21). Lowercase only.
A tag runs every function registered under it, the same mechanism the game uses for #minecraft:tick and #minecraft:load.
Just run the function. Works in every version that has /function.
Runs every line of the function as the command's executor. Needs permission level 2: an operator, a command block, or another function.
A macro line in a .mcfunction file starts with $ and marks value slots with $(variable). When the function runs, every $(variable) is replaced by the matching key from the compound you pass, inline or via with, before the line executes. A macro line fails if any of its variables is missing; plain lines never need arguments.
The /function command runs every command inside a datapack function file, top to bottom, as if you typed them all at once. One command can trigger hundreds, which is why functions power nearly every datapack, adventure map and command-block contraption in the game.
A function is a plain text file with the .mcfunction extension, one command per line, no leading slashes. Its id is the datapack namespace plus its path inside the function folder: mypack:greet lives at data/mypack/function/greet.mcfunction (the folder is named functions in versions before 1.21). Prefixing the id with # runs a function tag instead, which fires every function registered under that tag.
Every command in the function executes as the executor of /function, at the executor's position, unless a line changes context with /execute. The command needs permission level 2: cheats enabled in singleplayer, operator status on a server, a command block, or another function.
The command has five forms, all covered by the generator above:
The optional <path> at the end of each with form is an NBT path that narrows the source to a single compound inside it, for example Items[0].components on a chest or front_text on a sign. Without a path, the whole root compound becomes the macro input.
Five commands you can copy and adapt. Replace the mypack ids with your own datapack's namespace and paths:
/function mypack:setupRuns one function once. The most common use: re-running a datapack's setup after editing it and typing /reload.
/function #mypack:arena_resetThe # runs a function tag: every function registered in data/mypack/tags/function/arena_reset.json fires in order.
/function mypack:give_kit {player:"Steve",count:3}Inline macro arguments. Inside the function, $(player) and $(count) are replaced before each macro line runs.
/function mypack:read_chest with block ~ ~-1 ~Feeds the NBT of the block entity directly under the executor, here a chest, into the function's macro lines.
/function mypack:spawn_wave with storage mypack:waves currentReads the compound at path current inside command storage mypack:waves. Write it first with /data modify storage.
Macros, added in 1.20.2, let one function behave differently per run instead of hardcoding values. They work in three steps:
1. In the .mcfunction file, start a line with $ and put $(name) wherever a value should be substituted, for example $give @s diamond $(count).
2. Run the function with a compound: inline as /function id {count:5}, or from live data with one of the with forms so the values come from a block entity, an entity, or command storage.
3. Minecraft replaces every $(name) with the matching key's value before the line runs. If any macro line is missing one of its variables, the whole command fails with an error.
Lines without the $ prefix are untouched, so a function can mix plain and macro lines freely. Values substitute as raw text: strings keep their quotes only if the source had them, so numbers slot into counts and coordinates while quoted strings suit names and JSON text.
Put your datapack in the world's datapacks folder, run /reload, then run /function namespace:path. The id is the datapack's namespace plus the file path inside its function folder, without the .mcfunction extension. You need permission level 2: cheats enabled in singleplayer, operator status on a server, or a command block.
The usual causes are a typo in the namespace, an uppercase letter somewhere in the id, a missing /reload after editing, or the wrong folder layout. The file must sit at data/<namespace>/function/<path>.mcfunction (the folder is named functions in versions before 1.21) inside an enabled datapack. Run /datapack list to confirm the pack is enabled, /reload, then tab-complete /function to see what the game actually loaded.
with feeds macro arguments into the function from existing NBT instead of an inline compound. with block reads a block entity at a position, with entity reads from exactly one entity, and with storage reads from a command storage id; an optional NBT path after the source narrows it to one compound inside. It requires Minecraft 1.20.2 or newer.
Use function macros, added in 1.20.2. Inside the .mcfunction file, start a line with $ and write $(name) where a value should go, then run /function id {name:value} or one of the with forms to supply the compound. Every macro line must receive all of its variables or the command fails.
Yes. Add the function's id to the minecraft:tick function tag (data/minecraft/tags/function/tick.json in your datapack) and it runs 20 times per second. For a one-off delay use /schedule function <id> <time> instead. The /function command itself runs a function exactly once per execution.
Permission level 2, the gamemasters level. That covers a singleplayer world with cheats on, an operator on a server, command blocks, and other functions. Functions started by the tick and load tags run with full permissions automatically, which is why datapacks work on servers without anyone typing commands.
Building the datapack itself? Or browse more Minecraft tools: