Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Minecraft:Commands/function

From SAS Gaming Wiki

Template:Infobox command

Runs commands found in the corresponding function file(s) with command execution context (executor, execution position, angles, etc) of the /function command itself.

Usage

Template:IN, runs a function or all functions in a tag from a Minecraft:data pack.

Template:IN, runs a function from a Minecraft:behavior pack.

Template:IN, the behavior of Template:Cmd (or Template:Cmd) is different with a direct call to the Template:Cmd command. If Template:Cmd runs multiple functions, execution stops after first Template:Cmd in any of the functions. If a direct call to the Template:Cmd runs multiple functions, all of the functions are executed, and the return values are added up as the result value of the Template:Cmd command.

Syntax

  • Java Edition
function <name>
Runs a function or functions in a tag.
function <name> <arguments>
function <name> with (block <sourcePos>|entity <source>|storage <source>) [<path>]
Runs a function or functions in a tag, with arguments for macros.
  • Bedrock Edition
function <name: filepath>
Runs a function.

Arguments

Template:Argument

Specifies the function(s) to execute.
Template:Arg desc

Template:El: Template:Argument

Specifies arguments for macro functions in a compound NBT tag.
Template:Arg desc

Template:El: Template:Argument

The position of the target Minecraft:block entity whose NBT is to be used.
Template:Arg desc

Template:El: Template:Argument (in entity <target> mode)

Specifies an entity whose NBT is to be used.
Template:Arg desc

Template:El: Template:Argument (in storage <target> mode)

Specifies a storage whose NBT is to be used.
Template:Arg desc

Template:El: Template:Argument

Specifies the NBT path. Should be a path of a single compound tag.
Template:Arg desc

Result

Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table

Output

Template:IN, for Template:Cmd: Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table Template:IN, otherwise: Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table Template:IN: Template:Output table Template:Output table Template:Output table Template:Output table

Examples

  • Template:IN:
    • To run a function located at data/custom/function/example/test.mcfunction in a loaded data pack: Template:Cmd
    • To run all functions in a function tag located at data/custom/tags/function/example/test.json: Template:Cmd
    • 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
    • To run a function macro with arguments a=42, b="example": /function custom:example/test {a: 42, b: "example"}
    • To run a function macro with arguments from storage custom:storage: /function custom:example/test with custom:storage

History

Java Edition

Template:HistoryTable

Bedrock Edition

Template:HistoryTable

See also

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

References

Template:Reflist

External links

Navigation

Template:Navbox commands

Minecraft:de:Befehl/function Minecraft:es:Comandos/function Minecraft:ja:コマンド/function Minecraft:ko:명령어/function Minecraft:pt:Comandos/function Minecraft:ru:Команды консоли/function Minecraft:uk:Команди консолі/function Minecraft:zh:命令/function