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 a couple advantages. Functions are just text files where as command blocks are tile entities in your world, making functions less lag inducing. Another advantage is that functions are more easily organized, which makes working with large quantities of commands much easier. 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
関数