Project icon

Data pack basics

Minecraft Version(s)
  • none
What is a data pack?
A data pack is a folder which is used to hold and organize Minecraft functions, recipes, structures...

What are Minecraft functions?
Minecraft functions are files with the .mcfunction extension. They are used to store normal Minecraft commands and run them when the function is called.

example of a function file:
# this is a comment
say hi
say this is a function file
execute as @a run say hello world!
just some normal vanilla Minecraft commands stacked up in one file and ran line by line, that's a function file.

to create a function file, paste the above commands or your own commands into an empty text file (.txt) and then save the file with the ".mcfunction" extension.

to test this function, we need a data pack to put it in. If you don't know how to create your own data pack, here's an empty template which you can download and use for this tutorial:

This is what the file structure of a data pack looks like (source: Minecraft wiki)

the first file you will see is "pack.mcmeta" which looks like this:
       "pack": {
           "pack_format": 1,
           "description": "new data pack"
this file tells Minecraft that this folder is a data pack.
"pack_format" is the format of your data pack, its purpose is for Minecraft to distinguish different formats of the data pack structure. It’s currently not enforced but you should put 1 for compatibility with future versions.
"description" is pretty self-explanatory

next, you will see "(namespace)" which is a folder where your functions, loot tables, recipes, structures, and other things are going to go. Rename the namespace folder to anything you want.

you can have multiple namespace folders with different names to organize things
and each one of those namespaces can contain its own functions, recipes...

now that you know the basic file structure of a data pack, we can continue.

so where do we put the function? go into the template or your own data pack and navigate to data > your_namespace > functions and paste the function file in this folder.

done! your data pack is now ready for use. Go into .minecraft > saves > your_save > datapacks
and paste the data pack you just created into this folder.

if your game is already running, do /reload to register the data pack.

you can view all loaded data packs by doing /datapack list in game. You should see your data pack show up in the list.

so how do we run our function now? to run a function, use the /function command
/function namespace:function_name

example with namespace called "megacrafter" and function called "myFunction":
/function megacrafter:myFunction

This is nice and all but 99% of the time you will want your function file to run all the time in the background. For example, if I put this command into my function file to detect if there is a pig called "bob":
/execute if entity @e[type=pig,name=bob] run say hi bob
we would have to run the /function command the whole time if we want the command to keep testing for the condition.

We can tell Minecraft to run our function in the background every tick by registering it into a file called "tick.json".

The "tick.json" file is located in the minecraft namespace, found here: your_datapack > data > minecraft > tags > functions

if you open the "tick.json" file, you should see the following code:


this file tells the game what function to run every tick.

"values" - any function stored within this tag will run every tick

so let's add our function to the "values" tag. The syntax is the same as with /function (namespace:function)


our function will now run in the background as soon as the world loads.

now you might be wondering what that second file was for, the "load.json"? that file is used to run function only once (when the world loads). Which is perfect for initializing things like scoreboard objectives which only need to be created once.

so for example, if I have to create some scoreboard objectives, I would create another function file, write the commands in it and then register it in the "load.json" file just like we did with "tick.json" so it only runs once.
First release
Last update
4.50 star(s) 2 ratings

More projects from MegaCrafter10

Latest updates

  1. Loot table update

    The loot table section was too large to include in the data pack tutorial so I've made it a...

Latest reviews

Should be helpful for beginners, but isn’t the pack format supposed to be set to 1, I thought it was used when they need to change the format of data packs in the future to distinguish folder structures.
I thought so too but according to the wiki, it can be any number you want. I always put 4 and it works fine.
Short & Simple.
Could have explained more about other features of Data packs, like loot_tables, recipes, advancements etc. This is more of a "functions" basics rather than data packs basics.
I will try and update this tutorial and add all of those things