-
Notifications
You must be signed in to change notification settings - Fork 21
Datapack Tutorial
Knowing how to create a datapack is essential when creating new Alloy Forge recipes. If you already know how to create a basic datapack you can start making recipes [WIP, INSERT LINK HERE].
Creating a basic datapack is fairly simple. To start out you need a folder or a zip file that contains the datapack.
The main components for the datapack are:
- A
pack.mcmeta
file, which tells Minecraft what versions your datapack supports. - A data folder, which contains all the data of your pack.
These are found in any data pack, and you can look at any datapack for these. This tutorial will teach you how to format these.
At any point where JSON is used, using a JSON checker like JSONLint is useful for catching bad formatting, especially comma errors.
A .mcmeta
file is just a JSON file with a custom extension. The file usually looks something like this:
{
"pack": {
"pack_format": 7,
"description": "Put your description here"
}
}
The pack_format
file determines what versions of Minecraft your datapack supports.
You can still load outdated packs, but the game warns you about loading them.
To create this file you can simply save/edit a text file with the .mcmeta extension.
Currently for 1.17+ the pack format is 7
.
For future versions of Minecraft this can change, and the best page to find the latest number is on the Minecraft Wiki.
If you are struggling with creating the file, you can simply copy a mcmeta from ANY datapack. It's not stealing.
The data folder frankly contains all your data files. When putting data inside you separate it using folders. The first folder you create is a namespace
.
A namespace
is a core/root folder, which prevents conflicts with data from other places.
The standard structure for your pack would be data/namespace
, and in this folder you put your data.
Having limitless possibility can cause some confusion between packs (for the better), which is why Minecraft only loads specific things from specific folders.
An example is the fact that recipes will only be loaded under a recipes
folder. A list of folders that work this way are:
advancements
dimensions
functions
loot_tables
predicates
-
recipes
<--- This one is the most important for Alloy Forging structures
tags
worldgen
When putting files inside these main folders but you can create subfolders to sort it as you please.
Note that every file and folder inside the data folder MUST BE LOWERCASE.
Now to try to create a datapack!
To get started we will do the following:
- Create a new single player world (with cheats enabled)
- Exit back to the menu
- Navigate to the world we created
- Click "Edit World"
- Finally, click "Open World Folder".
Then we will head into the datapacks
folder, where we can create our datapack.
NOTE! that when we are done with this we can turn this folder into a zip file, and then install it on other worlds/servers.*
First we will create the pack folder, which can be named anything you please. For this example we will call it "TestPack".
Inside we create a pack.mcmeta
file, and an empty data
folder. Since I am playing on 1.17.1 I set the pack_format
to 7 and give it a description.
Now we open the world again, and as long as the datapack was properly formatted it will be loaded automatically.
We can verify this by running the command /datapack list
. If done correctly it should load!
Now we can add something to the pack which could be useful. Considering we are making an Alloy Forgery recipe later, we should probably add a tag which we can use in our recipes. I want to be able to smelt certain stone blocks into deepslate using an Alloy Forge.
NOTE! At this point you do not need to go back to the main menu when changing things, as you can run the /reload
command to reload the datapack.
We start by creating a new folder inside data
which for the namespace. We will choose based_tutorial
for this.
Then we create a tags
folder. Since Minecraft separates block and item tags we will create an items
folder.
NOTE! Mixing blocks and items in an item tag is fine, but doing it in a block tag will fail.
Inside it we create a new tag file called "rocks_and_stones". Tags has to be JSON files (Most files in datapacks are .json files).
The structure of the file looks like this:
{
"replace": false,
"values": [
"minecraft:andesite",
"minecraft:diorite",
"minecraft:granite"
]
}
The replace
boolean here decides if the tag should be overwritten.
By default this should be false. The reason being that other mods/datapacks may want to be able to add new values to this tag.
The values
field is an array, and contains all the blocks or items you want in the tag.
NOTE! If you create a tag with the same namespace and path of another tag (I.E: minecraft:gold_ores) you can add to it or overwrite it by setting replace to false or true.
We can now test to see if this tag exists in the game. We will use /reload
to reload the datapack, and then we will use the /clear
command, which supports removing tags from your inventory!
If done correctly we can now remove andesite, diorite, and granite from our inventory!
[WIP]