/function
Run a list of commands stored in a datapack function file.
Overview
What is the /function command?
The /function command runs a function โ a saved list of commands stored in a datapack โ in one call. Functions are how you package and reuse complex command logic, call routines from other functions, and build large systems that would be impossible to type line by line.
They're the foundation of every datapack: tick loops, libraries and reusable behaviours all live in functions.
When to use it: Use /function to run a saved batch of commands from a datapack โ reusable routines, tick loops and libraries.
At a glance
Syntax
/function <namespace:path>See it
What it does
Anatomy
Every part, explained
- 1
CommandRequired/functionRuns a datapack function.
- 2
Function IDRequired<namespace:path>The pack and path, like mypack:setup.
Your turn
Try it yourself
Copy & paste
Examples
/function mypack:setupRun the setup function.
/function mypack:loopTrigger a loop function.
/function minecraft:tickCall the built-in tick function.
Avoid these
Common mistakes
/function setup/function mypack:setupAlways include the namespace before the colon.
/function mypack/setup/function mypack:setupUse a colon between pack and path.
Good to know
Frequently asked questions
- How do you run a function in Minecraft?
- Run /function <namespace>:<path>, e.g. /function mypack:setup, where the function file lives in a loaded datapack.
- Where do function files go?
- Inside a datapack under data/<namespace>/function/ (or .../functions/ in older versions), as .mcfunction files with one command per line.
- How do you run a function every tick?
- Add it to the #minecraft:tick function tag so it runs automatically 20 times per second.
Keep going