Function (Java Edition)

Functions are an upcoming feature allowing players to easily script commands.

Usage
Functions are player-made text files containing commands. To enable a function in a Minecraft world, it must be placed in the 'data/functions' folder of the world. There are currently three ways of running a function file. For all of them the function to run can be specified using. For example  will refer to the function located at 'data/functions/custom/example/test.txt'.

Using functions over command blocks has multiple advantages:
 * Functions are just text files where as command blocks are tile entities in your world, which makes functions more optimized and less lag inducing.
 * Functions are more easily organized, which makes working with large quantities of commands much easier. Removing or adding commands is easier to do in a file compared to doing so using a command block system. Functions also allow players to place comments using  or.
 * You can use the  command in a function file, which allows players to write a piece of 'code' one time and call the function whenever it's needed in their main function file.

On the other hand. Functions lack certain abilities command blocks have, like a conditional option or being able to output its success value using a comparator. These can be replicated using scoreboard commands of course, but it will be more complex.

/function
The command allows players to run a function once. The commands in the function are run through the entity or command block which ran the function command.

/gamerule gameLoopFunction
The will run a function every tick. The commands in the function are run through the server.

Advancement rewards
Advancements can run a function once as a reward for completing them. The commands in the function are run through the player who completed the advancement.

{    "rewards": { "function": "namespace:path/to/function/file" } }

History
関数 Fonctions