Skip to main content

/function

Runs a function or function tag from a data pack. Functions are .mcfunction files containing a list of commands.

Category
Logic
Permission Level
Game Master
Version Added
1.12

Overview

Runs a function or function tag from a data pack. Functions are .mcfunction files containing a list of commands. In vanilla Minecraft Java Edition it is one of the logic commands and has been available since version 1.12.

It is invoked as /function [with []] and accepts one required argument () and 2 optional arguments ([storage] and [path]).

Functions run sequentially, one command per line. The function inherits the execution context of the calling command. Since 1.20.2, macros allow parameterized functions using $() syntax.

A leading # targets a function tag (runs every function in it); a plain id runs one .mcfunction. Since 1.20.2 macros let a function read $() arguments from a passed data storage.

Syntax & Arguments

/function <name> [with <storage> [<path>]]

The full syntax is /function [with []]. Angle brackets < > mark required arguments and square brackets [ ] mark optional ones; a vertical bar | between words means you pick exactly one of those literals. You must always supply . The arguments [storage] and [path] may be omitted, in which case the documented default applies.

name
Required, of type a resource. The function or function tag to execute (e.g., mypack:my_function or #mypack:my_tag).
storage
Optional, of type a resource. A data storage to pass as macro arguments (1.20.2+, used with 'with' keyword).
path
Optional, of type a nbt_path. The NBT path within the storage for macro arguments.

Parameters

NameTypeRequiredDescription
nameresourceRequiredThe function or function tag to execute (e.g., mypack:my_function or #mypack:my_tag).
storageresourceOptionalA data storage to pass as macro arguments (1.20.2+, used with 'with' keyword).
pathnbt_pathOptionalThe NBT path within the storage for macro arguments.

Examples

The 3 examples below are ready to copy and adapt. For instance, /function my_pack:setup runs all commands in the my_pack:setup function. Each example varies the arguments to show a different real use of /function; read the note under every snippet to see exactly what changes.

/function my_pack:setup

Runs all commands in the my_pack:setup function.

/function #minecraft:load

Runs all functions in the minecraft:load function tag.

/function my_pack:greet with storage my_pack:data player

Runs the greet function with macro arguments from a data storage.

Permission Level & Requirements

/function sits at permission Level 2 - Game Master / Cheats, which means it needs permission level 2, the level cheats grant to single-player worlds and that operators hold by default.

In a single-player world you must have "Allow Cheats" turned on (or open the world to LAN with cheats) before it will run; on a multiplayer server the player needs to be an operator at the matching level.

This reference describes the Java Edition 1.21 form of the command; Bedrock Edition may use slightly different argument formats.

Common Mistakes

Notes

Functions run sequentially, one command per line. The function inherits the execution context of the calling command. Since 1.20.2, macros allow parameterized functions using $() syntax.

Related Commands

If /function is part of your toolkit, the commands below are the ones you will most often reach for alongside it: /schedule, /execute, and /reload. They cover closely related tasks, so the links above jump straight to each one.

Frequently Asked Questions about /function

What does the /function command do in Minecraft?

Runs a function or function tag from a data pack. Functions are .mcfunction files containing a list of commands. It belongs to the logic command group and was added in Java Edition 1.12.

What is the correct syntax for /function?

/function [with []]. The required argument is name, and the optional ones are storage and path.

What permission level does /function need?

It requires permission Level 2 - Game Master / Cheats. On a server the player must be an operator at that level, or have cheats enabled in single-player.

What is a common mistake when using /function?

Using # prefix for individual functions, # is for function tags, not individual functions.

Can you give an example of /function in use?

Yes. /function #minecraft:load — runs all functions in the minecraft:load function tag.

Need a Minecraft server?

Try these commands on Astroworld or host your own server.

Try Astroworld Hosting