Function


Info

Functions allow players to run lists of commands using text files with the extension .mcfunction.

Usage

To utilize functions, the text files must first be placed into the WORLDNAME/data/functions folder within .minecraft .minecraft (or simply minecraft in macOS) is the folder Minecraft creates to run from. This folder includes the .jar files, sound, music, resource packs, personal options, worlds, etc. Locating .minecraft Locating the .minecraft folder is . They can then be run using the several methods detailed below.

Function files must be further divided into subfolders, and are run in-game using the format namespace:path/to/function/file, where namespace is the first-level subfolder name of the functions folder. For instance, running custom:example/test will refer to the function located at WORLDNAME/data/functions/custom/example/test.mcfunction. If the namespace is left out when trying to call a function, it will default to minecraft.

Within the text file, one valid command is placed per line (without the usual forward slash). Players can add comments within the function text file by preceding them with a #. If a function is added or modified, the /reload command will reload the function files from disk, allowing Minecraft to recognise any changes to the function files. Commands run inside a function will obey /gamerule maxCommandChainLength.

Commands in functions can be longer than the 32 500 character limit in command blocks Command Block Type Block Entity Physics No Transparency No Luminance No Blast resistance 18,000,000 Hardness -1 Tool None Renewable No Stackable Yes (64) Flammable No First appearances See history Drops None Block entity id command_block minecraft . Functions will also run all of their commands in a single tick. Functions called from within other functions will run their commands in the same tick as their parent. Position changes that happen within a function will not affect the relative coordinates used in other commands within that function (or other functions called within the function) till the next iteration regardless of the order of commands, the /execute command circumvents this. For example:

 tp @a ~ ~5 ~ setblock ~ ~-1 ~ emerald_block execute @a ~ ~ ~ setblock ~ ~-1 ~ diamond_block 

These 3 commands will teleport all players 5 blocks up, place an emerald_block one block below their original position before the teleport and place a diamond block one block below their new position after the teleport. This behavior does not affect position arguments within selectors, which will always test for the current position at the time of execution.

Since they are simply text files, functions are easily modifiable and less likely to induce lag when used in large quantities, compared to command blocks. Be that as it may, the successful output of a function cannot be measured with a comparator Redstone Comparator Transparency Yes Luminance No (7 when powered, in Pocket Edition) Blast resistance 0 Tool Any tool Renewable No Stackable Yes (64) Flammable No Drops Redstone Comparator (1) Data values See Data values Name minecraft (without the use of complex scoreboard A screenshot of a scoreboard on the right side of the screen. The scoreboard system is a complex gameplay mechanic utilized through commands. Mainly intended for mapmakers and server operators, scoreboards are used to track, minecraft commands).

There are several methods of running a function file in-game:

Videos

Commands

/function
/gamerule gameLoopFunction
  • Runs a function every tick.
  • The commands in the function are run through the server.
  • If multiple functions need to be looped, it is possible to insert function commands into this looped function file, put function commands in those functions, etc.
  • Usage: /gamerule gameLoopFunction namespace:path/to/function/file>

Advancements

Advancements Java Edition Only “ The system as a whole is called "advancements", which is aimed at guiding & tracking players progress through the game (in vanilla survival and any custom additions by mapmakers or mods). minecraft 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.

Reward functions are called within advancement JSON JSON is a format that serves a similar purpose to NBT, but which can always be displayed and edited in programs that treat it as plain text. Minecraft (PC edition) uses it to store several files using the following format:

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

History

Official releaseAnnounce Minecraft 1.0 Starting version 1.0.0 (Nov. 18th, 2011) Latest version 1.12 Paid Yes Website http://www.minecraft.net/ See the official release of Minecraft for the PC. For the version, see 1.0.0. For the first minecraft
1.12 1.12 Official name World of Color Update 1] Release date Jun. 7, 2017 Development versions View all Snapshot 17w06a 17w13a 17w13b 17w14a 17w15a 17w16a 17w16b 17w17a 17w17b 17w18a 17w18b Pre-release 1.12-pre1 1.12-pre2 1.12-pre3 1.12-pre4 1.12-pre5 minecraft pre1 Added functions.
pre3 Commands are no longer allowed to begin with a / (forward slash)
Comments must now be proceeded by a #; using // is no longer allowed
pre4 Added new arguments to the /function command: if|unless selector
pre6 Skipped functions (when a conditional fails) are now considered failures when used in commands.

Issues

Issues relating to ⃢₀ₜFunction⃢₀₝ are maintained on the issue tracker. Report issues there.