Configuring a Function Tag for Tick Events — A Quick Guide
Configuring a function tag for tick events in Minecraft is a fundamental skill for any data pack creator looking to implement persistent, dynamic systems within their worlds. This powerful mechanism allows for the execution of custom logic and commands at a consistent, rapid pace, forming the backbone of many advanced data pack functionalities. Understanding its mechanics and proper setup is crucial for efficient and reliable game design.
![]()
Understanding Tick Event Mechanics
At its core, the minecraft:tick function tag serves as an automated scheduler for your data pack’s commands. Functions listed within this tag are executed precisely at the beginning of each game tick. In Minecraft: Java Edition, a game tick occurs 20 times every second. This means that any commands contained within these functions, or any functions called by them, will run every 0.05 seconds, providing a continuous loop for your game logic.
The primary advantage of using function tags for tick events is the ability to achieve repetitive command execution without relying on an extensive network of repeating command blocks. This not only streamlines the development process but also significantly improves performance by consolidating logic into data pack functions, which are generally more optimized than individual command blocks for complex operations. All commands within a function listed in the minecraft:tick tag, along with any other functions that are called from within it, are processed and executed entirely within a single game tick. This “atomic” execution ensures that your game logic is processed coherently and completely without being split across multiple ticks, preventing potential inconsistencies or race conditions.
It is also important to understand the execution order in relation to another critical function tag: minecraft:load. While functions in the minecraft:load tag run only once when a world is loaded or a data pack is reloaded, there’s a specific interaction with the tick tag. Upon the initial loading of a world or reloading of data packs, the very first instance of a function from the minecraft:tick tag will execute *before* any functions from the minecraft:load tag. This detail can be significant for initialization procedures where certain game states might need to be established before continuous tick-based logic begins, or for ensuring systems are ready immediately.
Step-by-Step Configuration Process
Setting up your minecraft:tick function tag involves a series of structured steps within your data pack. Adhering to the correct folder structure and file naming conventions is vital for Minecraft to properly recognize and utilize your custom functions.
1. Create a Data Pack Structure
The foundation of any data pack begins with its folder structure. You must first ensure that your data pack is correctly set up. Inside your data pack’s root directory, you will find a data folder. Within this data folder, you need to create a new folder that will serve as your namespace. A namespace is a unique identifier for your data pack, preventing conflicts with other data packs or vanilla Minecraft resources. For example, if your data pack is named “My Custom Pack,” you might create a folder named my_datapack. This results in a path like /data/my_datapack/.
2. Create Function Folder
Once your namespace folder is established, the next step is to create a dedicated folder for your functions. Inside your namespace folder (e.g., my_datapack), create a folder named functions. This folder will house all of your .mcfunction files. The resulting path will look like /data/my_datapack/functions/. This clear separation helps organize your commands and makes your data pack easier to manage.
3. Create Function Files
Now that your function folder exists, you can begin writing the actual Minecraft commands that you want to execute. Inside the functions folder you just created, create one or more text files with the .mcfunction extension. For instance, you might create a file named my_tick_function.mcfunction. Within this file, you will write your desired Minecraft commands, with each command placed on a new line. For example, you could have a simple command like say Hello from the tick function! or a more complex one such as scoreboard players add @a my_score 1. These commands will be executed every single game tick once the function is linked to the minecraft:tick tag.
4. Create Tag Structure
This step involves creating the specific folder structure where Minecraft looks for its function tags. Navigate to the following path within your data pack: /data/minecraft/tags/functions/. It’s crucial to note that the minecraft folder here is not your custom namespace; it refers to the default Minecraft namespace. This is where global tags like tick.json and load.json are expected to reside, allowing them to affect the game universally, regardless of specific data pack namespaces.
5. Create tick.json
Inside the functions folder you created in the previous step (i.e., /data/minecraft/tags/functions/), create a new file named tick.json. This JSON file is the definition of the minecraft:tick tag itself. It will specify which of your custom functions should be executed every game tick. The name tick.json is specific and must be followed exactly for Minecraft to recognize it as the tick tag.
6. Populate tick.json
The tick.json file must contain a JSON object with a single key: values. The value associated with values must be a JSON array. This array will list the namespaced IDs of all the functions you wish to run at the beginning of every game tick. Each namespaced ID follows the format your_namespace:your_function_path. The your_function_path part corresponds directly to the name of your .mcfunction file, excluding the .mcfunction extension. For example, if your namespace is my_datapack and your function file is my_tick_function.mcfunction, its namespaced ID would be my_datapack:my_tick_function.
An example of the content for your tick.json file would look like this:
{
"values": [
"my_datapack:my_tick_function",
"my_datapack:another_tick_function",
"my_datapack:utility/sub_function"
]
}
In this example, my_datapack:my_tick_function and my_datapack:another_tick_function refer to functions directly within your my_datapack/functions/ folder. If you had a function file located at my_datapack/functions/utility/sub_function.mcfunction, its namespaced ID would be my_datapack:utility/sub_function. You can list as many functions as needed; they will execute in the order they appear in the values array.
Activating and Managing Your Tick Functions
Once all the files are correctly placed and configured within your data pack, you need to load or reload the data pack in your Minecraft world. This can be done by using the command /reload while in-game, provided you have the necessary permissions. Upon successful reload, your functions listed in tick.json will begin executing 20 times per second.
To verify that your tick functions are working, you can include simple commands in your .mcfunction files, such as say commands, which will output messages to the chat. Alternatively, you can observe changes to scoreboards or other game elements that your functions are designed to manipulate. If you encounter issues, double-check your folder paths, file names, JSON syntax, and the exact spelling of namespaced IDs within your tick.json file. Even a small typo can prevent the data pack from loading or the functions from executing.
Best Practices and Considerations
When working with tick functions, it’s essential to keep performance in mind. Since these functions run continuously, inefficient commands or overly complex logic can negatively impact server performance. Strive to keep your tick functions as optimized as possible, avoiding heavy calculations or broad entity selections unless absolutely necessary. For complex systems, it’s a good practice to break down your logic into smaller, more modular functions. The minecraft:tick tag can then call a main ‘orchestrator’ function, which in turn calls other specialized functions based on game state or specific conditions. This modular approach enhances readability, maintainability, and often performance.
Remember that the order of execution for functions listed in the values array of tick.json is sequential. If one function depends on the output or state set by another function within the same tick, ensure they are listed in the correct order. While the tick tag forces execution every tick, you can still implement conditional logic within your .mcfunction files using commands like execute if or execute unless. This allows your functions to perform actions only when specific conditions are met, even though they are technically running every tick.