/function Command in Minecraft Java Edition

Run Data Pack Functions with /function

Java EditionLogic & ScoreboardPermission: Level 2Bedrock version →

The /function command lets you run custom scripts and function tags stored inside a data pack. You can execute a function directly or pass extra NBT data into it from the command line, a block, an entity, or command storage.

Players and mapmakers use this command to trigger groups of commands all at once without building long chains of command blocks. Note that you need Operator permissions (Level 2) or cheats enabled in single-player to run it.

Syntax (Java 26.3, 4 forms)

  1. /function <name> [<arguments>]
  2. /function <name> with block <source> [<path>]
  3. /function <name> with entity <source> [<path>]
  4. /function <name> with storage <source> [<path>]

The forms you will use most

/function <name> [<arguments>]
Runs a data pack function or function tag, with optional NBT compound arguments written directly in the command.
/function <name> with block <source> [<path>]
Runs a function using NBT data taken from a block at the chosen coordinates.
/function <name> with entity <source> [<path>]
Runs a function using NBT data read from a single targeted entity or player.
/function <name> with storage <source> [<path>]
Runs a function using NBT data pulled from a specific command storage ID.

Arguments

ArgumentTypeWhat it means
<name>functionSpecifies the function or #function tag from a data pack that you want to run.
<arguments>NBT compoundAn optional NBT compound in curly braces, such as {NoAI:1b}, passed directly into the function.
<source>block positionThree coordinates x y z. Use ~ for relative or ^ for local coordinates.
<path>NBT pathAn optional NBT path, like Inventory[0].id, that narrows down which part of the source data to send to the function.
<source>target selector
one target
A player name, a UUID or a target selector such as @p, @a, @e or @s.
<source>resource IDA namespaced ID such as minecraft:stone.

Examples

Version history

Measured from the game files of every Java release from 1.13 to 26.3.

  1. 26.3 Only argument names changed (same forms).
    + /function <name> with block <source> [<path>]− /function <name> with block <sourcePos> [<path>]
  2. 1.20.2 Syntax changed.
    + /function <name> [<arguments>]+ /function <name> with block <sourcePos> [<path>]+ /function <name> with entity <source> [<path>]+ /function <name> with storage <source> [<path>]− /function <name>
  3. 1.13 Already in the game in 1.13, the oldest Java version we track.

Tips

Common mistakes

Java vs Bedrock

Bedrock Edition also includes the /function command, but it only supports the basic syntax /function <name: filepath> and does not have the Java Edition options for passing NBT arguments from blocks, entities, or storage.

See /function in Bedrock Edition →

FAQ

What permission level do I need to use /function?

You need permission level 2, which means you must be an Operator on a multiplayer server or have cheats turned on in your single-player world.

When were function arguments added to Java Edition?

The ability to pass inline NBT arguments or pull data using with block, with entity, and with storage was added in Java Edition 1.20.2.

Can I use @a as the entity source in /function?

No, the entity <source> argument only accepts one target at a time, so you must use a player name, a UUID, or a single-target selector like @p or @s.

Related commands

/bossbar/data/execute/random/return/schedule/scoreboard/tag/team/trigger

More on 9Minecraft