For example:Įxecute at run setblock ~ ~-1 ~ diamond_block This command context is preserved for all the commands in the function, so a / setblock command will use the saved position context even when a previous command in the same function teleported the original executor to a different position. This includes command sender, position, rotation, etc. Functions will use the command environment of whatever called the function. Individual commands in functions can be longer than the 32,500 character limit in command blocks but the total number of commands run inside a function will still obey / gamerule maxCommandChainLength, which is 65,536 commands by default any commands beyond this limit will be ignored.įunctions will run all of their commands in a single tick and functions called from within other functions will also run their commands in the same tick as their parent. Players can add comments within the function text file by beginning a line with #. mcfunction file, one valid command is placed per line, without the usual forward slash ( /). Three / tellraw messages and one / give command were used in this simple function. On the default multiplayer software, a function can run any command that is no more restrictive than the permission level prescribed in function-permission-level setting in server.properties. In a singleplayer or a LAN world, like a command block, a function can run any command that is no more restrictive than permission level 2. The successful output of the commands inside a function cannot be measured with a comparator (although the same effect could be accomplished with the use of / execute store command). Embedded functions won't display this chat messsage. Upon successfully running / function, a message will display in the chat: Executed command(s) from function ''.
This allows Minecraft to recognize any changes to the function files, without the need to quit and re-enter the world. If a function is modified or added, using the / reload command will reload the function files from disk. For example, running the function custom:example/test will refer to the file located at data/custom/functions/example/test.mcfunction.įunctions, being text files, are easily modifiable and less likely than command blocks to induce lag when used in large quantities. It is also necessary to have a pack.mcmeta file in the folder. įunctions can also be placed into subfolders within the functions folder. Using a custom namespace is recommended in order to prevent unintended behavior in the case of future additions to the default namespace. If the namespace is left out when trying to call a function, it will default to the minecraft: namespace. If there's no ambiguity with other datapacks or with an existing minecraft command, you can just use. To execute the function, use the fully qualified function name, which is. mcfunction may be placed in the folder /datapacks//data//functions.