Minecraft Blogs / Tutorial

Function Data Packs for Dummies #3 | Creating a new data pack and your first function

  • 10,748 views, 5 today
  • 72
  • 28
  • 35
Bertiecrafter avatar Bertiecrafter
Site Moderator
Level 66 : High Grandmaster Stack
601
This series of tutorials will teach you how to create your very own data packs, assuming you know absolutely nothing about commands. Although data packs could just contain files that replace built-in assets like resource packs, these posts will focus on adding new features and mechanics to the game. In every part I assume you've read the previous parts.

Getting an editor

Although the default text editor that comes with your computer or laptop can be used to create data packs, I recommend a more professional editor like Notepad++. Although it won't give you any smart suggestions or auto complete, it still provides you with suggestions based on the words you typed earlier. This can come in handy later on in the tutorial series, when you need to refer to something that you have created earlier by name. Visual Studio Code is an editor often used by programmers, which is also fine if you already have it, but a little bit much if you plan on using it just for Minecraft data packs. This editor does have extensions that claim to have smart suggestions, but they are not at a stage that makes them worth downloading yet.

A new world, a new data pack

Open up Minecraft and create a world if you want to. Click a world, then click "Edit" and "Open World Folder". Go back to the single player menu and join the world. The folder containing the world should have opened up. Go into "datapacks" and create a new folder. The name should represent what you're going to create. Next up we're going to create the pack.mcmeta file. It turns our now empty folder into a valid data pack and gives Minecraft some other information.

​For Windows Users
It's important to turn on file extensions if you are on Windows. They tell programs how files should be read. Other operating systems read the file content to know what to do with them and therefore don't hide the extensions for safety. In order to make file extensions visible, go to the View tab in the files/folders window (it's called "the Explorer") and check "File name extensions" in the "Show/Hide" category. You should see a dot followed by a couple of characters appear behind every file. These characters represent the extension.

Create a file called pack.mcmeta in the folder you've just created. You can do this by opening up a text editor, like Notepad and then clicking "File" > "Save as...". You must make sure to select "All Files" in the save as drop-down menu below the text box for the file name. If you do not do this, the file will be saved as pack.mcmeta.txt instead of simply pack.mcmeta. Another way is to right click the empty folder > New > Text Document and change the name (including extension) right away. I recommend the second way, because you would spot it faster if your extension is wrong.
For Mac/Linux Users
Start by opening a text editor like TextEdit. If you're using this application, make sure to go to Format > Make Plain Text every time you create a new file. Then click "File" > "Save as..." and after entering the full file name (e.g. "pack.mcmeta"), uncheck the box that says "If no extension is provided, use ".txt"". Another way is to right click the empty folder > New Text File and change the name right away. I recommend the second way, because you would spot it faster if your extension is wrong. The "extension" is the part behind the last dot in the file name. In this case it's "mcmeta".

Use right-click and "Get Info" to view the full file name. If it says "pack.mcmeta.txt", it's wrong.

Now fill that file with the JSON below. Any content between braces should be indented with 4 extra spaces if you want to format it nicely.

File Contents

{
"pack": {
"pack_format": 7,
"description": "put some text here"
}
}

The fun thing is that the description key has the same JSON structure as the tellraw command, so with knowledge from the previous tutorial you can do something really fancy there if you want to. You should also know already that a simple string is permitted as well. The text is only displayed if you hover over the datapack entry in a command we'll get to soon, so don't spend much time on it.

The pack_format number is 7 for 1.17, have a look here for the latest pack_format number.

Now go back to your world and do "/reload" followed by "/datapack list". You should see your folder in the list, in green. If it's not in the list, your pack.mcmeta has a mistake. If it's in the list, but red, use "/datapack enable file/<folder name>" to enable it. If you hover over it, it should show the description you specified.

Your first function


Functions are awesome. They allow you to turn thoughts into magic and you can look cool by calling your "list of instructions" an "ALGORITHM".

Note: Any folder or file within the data pack folder (containing pack.mcmeta) can only contain the following characters: a-z 0-9 . _ -
(Which means no capital letters or spaces!)

In order for every data pack to be combined with any other data pack, every function must be unique in the whole wide world. Sounds impossible, but we can try. Start with creating a "data" folder alongside the pack.mcmeta file. Then create a folder in the "data" folder and give it a name that you own. An easy one is your Minecraft username, but feel free to use a bought domain name. This folder will become your "namespace". Programmers have namespaces too and they make sure they are unique in the very same way.

Now create a "functions" folder inside your namespace folder. By using a namespace you own, you can prevent data packs from other users colliding with yours. However, it doesn't prevent one of your data packs from colliding with another one of yours. In order to avoid this, we're not going to create a function file right away. Create a folder in the "functions" folder first and give it a name that should distinguish this pack from others. Usually a shortened version (no spaces) of the data pack name should be enough.

Now we can create our first function file. Make sure that it has "mcfunction" as extension. You can do it the same way you created the "mcmeta" file before. The path to the file should look like this:
.minecraft/saves/<World Name>/datapacks/<Data Pack Name>/data/<namespace>/functions/<dp_identifier>/<function_name>.mcfunction

Just like a real programmer, it's tradition to output "Hello world!" as the first thing you do in every new language you learn. Remember, function files are just lists of commands, so at the first line you can write your say or tellraw command right away. Make sure to omit the leading /. Any lines starting with # are ignored and can be used for comments. Once you got your command in place, you can simply do /reload and then /function <namespace>:<dp_identifier>/<function_name> (Don't put ".mcfunction" at the end of it)

If you see "Hello World!" appear in chat, it's a success! Keep in mind that I won't tell you do a /reload after every data pack edit in the next tutorials anymore, you'll have to remember this yourself.

Challenge Yourself

After every tutorial, I'll include a section where you are challenged to apply what you've learned. I recommend you playing with what you've learned, it helps you getting familiar with new concepts and be able to find solutions to problems. You don't have to do exactly what's written below, you can always challenge yourself in a different way.

Create a mob challenge that admins could do for times when there are no hackers to catch. It should /clear the inventory, /give the player armor + a weapon and spawn like 10-20 zombies or skeletons. You can do this last part by simply doing "/summon zombie" or "/summon skeleton" a bunch of times. It's okay to put a player name in the function file for now. You'll learn how to dynamically select players in another tutorial.

What's next?

Next up we're going to look at how to quickly fix problems as well as making sure that your data pack is of a high quality.
Subscribe if you want to get notified of new posts.

Function Data Packs for Dummies #3 | Creating a new data pack and your first function
Function Data Packs for Dummies #3 | Creating a new data pack and your first function
Tags

4 Update Logs

Update #4 : by Bertiecrafter 05/15/2021 6:38:03 pmMay 15th, 2021

Talked to djmushyjp for a bit to discover a couple difficulties for Mac users that I didn't know about as a Windows user. I modified the text in the "For Mac/Linux Users" spoiler to hopefully fix these issues.
LOAD MORE LOGS

Create an account or sign in to comment.

2
12/26/2021 3:59 pm
Level 1 : New Explorer
omegaguy
omegaguy avatar
Yoooo
Thank u a lot for the tutorial. I tried your datapack challenge and it works!
1
07/21/2021 12:59 pm
Level 1 : New Miner
MinerSteve100
MinerSteve100 avatar
what if I'm using iPad :(
1
01/30/2022 7:28 am
Level 1 : New Miner
INQIZZO
INQIZZO avatar
u should buy a pc
1
07/21/2021 12:59 pm
Level 1 : New Miner
MinerSteve100
MinerSteve100 avatar
Cause my gaming platform is iPad and I'm typing on PC
1
07/21/2021 4:03 pm
Level 66 : High Grandmaster Stack
Bertiecrafter
Bertiecrafter avatar
Data packs only work on Java Edition :/
2
07/18/2021 7:18 pm
Level 1 : New Crafter
SDesires
SDesires avatar
It took a few tries, but I got it too work! Woot! Thank you for explaining this in a simple fashion :)
2
07/19/2021 1:01 pm
Level 66 : High Grandmaster Stack
Bertiecrafter
Bertiecrafter avatar
Glad you got it working!
1
06/22/2021 8:07 am
Level 11 : Journeyman Miner
NovaModz
NovaModz avatar
Hey so i added everything correctly to the datapack but the fucntion says unknown function pls help
2
06/22/2021 8:11 am
Level 66 : High Grandmaster Stack
Bertiecrafter
Bertiecrafter avatar
We can chat on Discord if you want, you can find me in the server linked above (click the Discord image).
1
06/22/2021 8:33 am
Level 11 : Journeyman Miner
NovaModz
NovaModz avatar
wut ur disc name?
Planet Minecraft

Website

© 2010 - 2022
www.planetminecraft.com

Welcome