Tutorials/Creating a data pack

This tutorial shows how to create a data pack.

Getting Started
''Note: This tutorial should take around 1 to 1.5 hours to complete. This can also only be done in Mincraft 1.13 and up''

Data packs can be used to add or modify functions, loot tables, world structures, advancements, recipes and tags.

What not to do
There are some things that you should not do before creating a data pack. Here is a list of "don'ts":
 * Do anything that violates Mojang's terms of use for Minecraft.
 * Release Minecraft versions or modifications that allow players to play without having bought Minecraft from Mojang.
 * Release the decompiled source code of Minecraft in any way.

Creating a data pack
To create a data pack, start off by navigating to the  folder inside the world folder. To find the world folder, locate the  folder inside .minecraft. Once you are in the folder, create and open a folder and name it: "Tutorial Data Pack". This is the name of your data pack, which can be whatever you want.

The first thing to do after you have created the folder is to create a  file. This lets Minecraft know that the folder is a data pack.

Creating an MCMETA file
To create an MCMETA file, right click in the 'Tutorial_Data_Pack' folder and create a new text document. Name this file “pack.mcmeta”.

Requirement
You can download Notepad++ from here:
 * Any text editor should work but a suggested editor is Notepad++. It's a free text editor, with syntax highlighting for many programming languages, including JSON, which is the format used by most files in a datapack.

Make sure the file extension is  and not   when you rename it. You may be warned that changing a file name extension could make the file unusable. However, don't worry about that message; keep the correct file extension no matter what.
 * Note

If you are using Windows and can’t see file extensions, you can turn them on by going to the View menu of the file explorer and checking the check box for file name extensions.



pack.mcmeta
Open  in a text editor of your choice and copy or type the following:

{       "pack": { "pack_format": 1, "description": "Tutorial Data Pack" }   }

The  can be any number as it's currently not enforced. The  can be any string and will show when hovering over your data pack in the output from.

This file is written in JSON! This tutorial does not go into specifics about the format now, but be aware about how things are laid out. '''Be very careful not to forget quotation marks, colons, and curly or square brackets. Missing one of these can lead to your data pack not working correctly!''' To check your files you can use a JSON validator, such as the one found on JSONLint.
 * Note

data
Make a folder called  in your datapack folder, the same folder you placed the   file in. In this  folder you have to create another folder which will act as your. Most things in the game have a namespace, so that if both, something and a mod (or map, or whatever) are added to the game, they both act as different "somethings".

Whenever you're asked to name something, for example, a loot table, you're expected to also provide what namespace that thing comes from. If you don't specify the namespace it will be  by default. The game uses the  namespace, which means that this namespace should be used when the data pack needs to overwrite existing Minecraft data.

Make sure to always use your own namespace for anything new that you add, and only use other namespaces if you're explicitly overriding something else, or in the case of tags appending to something else. Basically, try not to add new things in. Namespace and other folder and file names in the data pack should only contain the following symbols:

•  Numbers

•  Lowercase letters

•  Underscore

•  Hyphen/minus

•  Forward Slash/Directory separator (Can't be used in namespace)

•  Period (Can't be used in namespace)

The preferred naming convention is.

Testing your Pack
Once you have created your data pack, try testing it out in-game! Launch Minecraft and open the world, then type. It should say two things. One is for “vanilla”, the second one should start with “file/”.

Troubleshooting
If you don’t see your pack working, make sure your  is correct. If it isn't, look for any missing curly braces { }, commas, colons :, quotation marks “”, or square brackets [ ]. Remember that for each open brace, quotation, or square bracket, you must have a closing brace, quotation, or square bracket.

Functions
Functions are a set of commands that can be run in order.

To add functions, first create a folder named  inside the namespace folder. Then, create a file named  in this folder or in any of its subfolders. This will be your function file. Your function will be named in the game as  or   when the function file is located in a subfolder.

Loot tables
Loot tables will tell Minecraft what should be dropped when a mob dies or what should be generated inside containers, like chests, when opened for the first time.

To add loot tables, first create a folder named  inside the namespace folder. Then, create a file named  in this folder or in any of its subfolders. This will be your loot table file. Your loot table will be named in the game as  or   if the file is located in a subfolder.

Here is an example of a cow's loot table, it can be used as a reference: {       "pools": [ {               "rolls": 1, "entries": [ {                       "type": "item", "name": "minecraft:leather", "weight": 1, "functions": [ {                               "function": "set_count", "count": { "min": 0, "max": 2 }                           },                            {                                "function": "looting_enchant", "count": { "min": 0, "max": 1 }                           }                        ]                    }                ]            },            {                "rolls": 1, "entries": [ {                       "type": "item", "name": "minecraft:beef", "weight": 1, "functions": [ {                               "function": "set_count", "count": { "min": 1, "max": 3 }                           },                            {                                "function": "furnace_smelt", "conditions": [ {                                       "condition": "entity_properties", "entity": "this", "properties": { "on_fire": true }                                   }                                ]                            },                            {                                "function": "looting_enchant", "count": { "min": 0, "max": 1 }                           }                        ]                    }                ]            }        ]    }

To learn what each tag means, see Loot tables. There are also a list of vanilla loot tables on that page.

Structures
Structures can be used with structure blocks and/or can overwrite how certain vanilla structures look in Minecraft. It is saved in an NBT format. You can create an NBT file by using a structure block or by exporting a build using a third party program like MCEdit.

To add structures to a data pack, first create a folder named  inside the namespace folder. Then, put your structure file in this folder or in any of its subfolders. Your structure will be named in the game as  or   if the file is located in a subfolder.

Advancements
Advancements can be completed by players and give various rewards.

To add advancements, first create a folder named  inside the namespace folder. Then, create a file named  in this folder or in any of its subfolders. This will be your advancement file. Your advancement will be named in the game as  or   if the file is located in a subfolder.

Recipes
Recipes are used to let players craft items.

To add recipes, first create a folder named  inside the namespace folder. Then, create a file named  in this folder or in any of its subfolders. This will be your recipe file. Your recipe will be named in the game as  or   if the file is located in a subfolder.

Shaped crafting
The first common type of crafting is shaped crafting.

{       "type": "crafting_shaped", "pattern": [ "123",           "231",            "312"        ],        "key": { "1": {               "item": "" },           "2": {                "item": "" },           "3": {                "item": "" }       },        "result": { "item": "", "count": 5 }   }

This is a rough example of a shaped crafting recipe, as specified by the  type. is a list used to specify the shape of the crafting recipe. It contains a maximum of 3 strings, each string standing for one row in the crafting grid. These strings then contain a maximum of 3 single characters next to each other, each character standing for one spot in the crafting grid. You don't need all 3 strings, nor do you need to have 3 characters in each string. But each string should contain the same amount of characters. You can use spaces to indicate empty spots.

is a compound used to specify what item should be used for which character in. This can either be specified using  followed by an item ID or   followed by an item datapack tag.

The  compound speaks for itself, it specified what the resulting item should be. is used to specify how many of the item should be given.

This is the original recipe for a piston (can be used as a reference):

{       "type": "crafting_shaped", "pattern": [ "TTT", "#X#", "#R#" ],       "key": { "R": { "item": "minecraft:redstone" },           "#": {                "item": "minecraft:cobblestone" },           "T": { "tag": "minecraft:planks" },           "X": { "item": "minecraft:iron_ingot" }       },        "result": { "item": "minecraft:piston" }   }

Shapeless crafting
There's another common type of recipes, a shapeless recipe. {       "type": "crafting_shapeless", "ingredients": [ {               "item": "" },           {                "item": "" },           [                {                    "item": "" },               {                    "item": "" }           ]        ],        "result": { "item": "", "count": 5 }   }

As specified by the  type, this is a recipe without a. The  can be put in the crafting grid in any shape or form. In the example, there's a list inside the  compound. This means any of the items in this list can be used.

This is the original recipe for Fire Charge (can be used as a reference): {       "type": "crafting_shapeless", "ingredients": [ {               "item": "minecraft:gunpowder" },           {                "item": "minecraft:blaze_powder" },           [                {                    "item": "minecraft:coal" },               {                    "item": "minecraft:charcoal" }           ]        ],        "result": { "item": "minecraft:fire_charge", "count": 3 }   }

Tags
Tags are used to group blocks, items, or functions together. Additionally, the  function tag is used to run functions every tick and the   function tag is used to run functions every time the world is (re)loaded.

To add tags, first create a folder named  inside the namespace folder. Inside this folder, create folders named,   and. Then, create a file named  in one of these folders or in any of their subfolders. This will be your tag file. Your tag will be named in the game as  or   if the file is located in a subfolder.