From Minecraft Wiki
Jump to: navigation, search

Runs a function or all functions in a tag from loaded data packs.‌[Java Edition only]
Runs a function from add-ons.‌[Bedrock Edition only]

function <function>
  • Java Edition
May be of the format namespace:path/to/function/file, or #namespace:path/to/function/tag.
The format without the # prefix, namespace:path/to/function/file, runs a single function located at [data_pack]/data/namespace/functions/path/to/function/file.mcfunction.
The format with the # prefix, #namespace:path/to/function/tag, runs all functions included in the function tag located at [data_pack]/data/namespace/tags/functions/path/to/function/tag.json.
  • Bedrock Edition
May be of the format path/to/function/file
Runs the function located at [behavior_pack]/functions/path/to/function/file.mcfunction
Fails if the argument is not specified correctly.
If successful, runs a function through the command source which ran the /function command.
  • Java Edition
If /function is ran inside of another function, it always fails but still executes its command entries;[1]
Otherwise, returns the number of commands ran (not the number of commands that succeed) plus the number of embedded functions called by this function.[2]
  • Java Edition
To run a function located at data/custom/functions/example/test.mcfunction in a loaded data pack: /function custom:example/test
To run all functions in a function tag located at data/custom/tags/functions/example/test.json: /function #custom:example/test
To run a function if there is a sheep within a radius of 2 blocks: /execute if entity @e[type=sheep,distance=..2] run function custom:example/test
To run a function unless the executor is a player: /execute unless entity @s[type=player] run function custom:example/test


Java Edition
1.12pre1Added /function.
1.1317w49b/function now accept function tags as the argument.
Removed [if/unless] arguments in favor of /execute [if/unless].
Bedrock Edition
1.8.0beta /function.

See also[edit]

  • Tag – To run function in batch, every tick, or on server (re)load.