Skip to content

Recipes and data packs

Lesson 12.3

Recipes don’t need any Lua. They are data-pack files, exactly like the ones in a vanilla data pack, and your mod ships them in its datapack/ folder. The game loads them with the world, above vanilla’s own data.

Where the files go

my_mod/
  datapack/
    my_mod/
      recipe/
        ruby_block.json
        ruby_from_block.json
      tags/
        item/
          gems.json

The folder under datapack/ is the namespace. Use your mod id for your own files. It is the same layout as data/<namespace>/ in a normal data pack.

A shaped recipe

Nine rubies in a 3 x 3 grid make a ruby block:

{
  "type": "minecraft:crafting_shaped",
  "category": "building",
  "pattern": [
    "###",
    "###",
    "###"
  ],
  "key": {
    "#": "my_mod:ruby"
  },
  "result": {
    "id": "my_mod:ruby_block",
    "count": 1
  }
}

pattern draws the grid with one character per slot, and key says which item each character means. A space is an empty slot. The recipe’s id comes from the file name: this one is my_mod:ruby_block.

A shapeless recipe

One ruby block back into nine rubies, in any slot:

{
  "type": "minecraft:crafting_shapeless",
  "category": "misc",
  "ingredients": [
    "my_mod:ruby_block"
  ],
  "result": {
    "id": "my_mod:ruby",
    "count": 9
  }
}

Smelting

Raw ore in the furnace:

{
  "type": "minecraft:smelting",
  "category": "misc",
  "ingredient": "my_mod:raw_ruby",
  "result": { "id": "my_mod:ruby" },
  "experience": 1.0,
  "cookingtime": 200
}

cookingtime is in ticks: 200 ticks are 10 seconds. minecraft:blasting (twice as fast) and minecraft:smoking work the same way.

Tags

A tag is a named group of items or blocks. Recipes can ask for “any item in this group” instead of one item. datapack/my_mod/tags/item/gems.json:

{
  "values": [
    "minecraft:emerald",
    "minecraft:diamond",
    "my_mod:ruby"
  ]
}

In a recipe, a tag is written with #:

"key": { "G": "#my_mod:gems" }

You can also add to vanilla’s tags by putting a file under datapack/minecraft/tags/.... Your values are merged with vanilla’s, unless the file says "replace": true.

Changing vanilla data

Because your datapack/ sits above vanilla, a file with the same path as a vanilla file replaces it. datapack/minecraft/recipe/torch.json would change the torch recipe for everybody who has your mod. That is powerful, and easy to get wrong when two mods replace the same file. Prefer adding new recipes over replacing vanilla ones.

Checking your recipes

Data files have no hot reload of their own. After a change, run /reload in the world (with cheats on), or leave and rejoin it. If a recipe doesn’t show up, look in logs/latest.log for a line about the file: a typo in an item id or a missing comma is the usual reason.

The recipe book shows mod recipes like vanilla ones, because they are vanilla recipes.

Try it

You have the items my_mod:ruby and my_mod:ruby_pickaxe. Write a shaped recipe for the pickaxe: three rubies on top, two sticks in the middle column below, like vanilla pickaxes.

Show a solution

datapack/my_mod/recipe/ruby_pickaxe.json:

{
  "type": "minecraft:crafting_shaped",
  "category": "equipment",
  "pattern": [
    "RRR",
    " S ",
    " S "
  ],
  "key": {
    "R": "my_mod:ruby",
    "S": "minecraft:stick"
  },
  "result": {
    "id": "my_mod:ruby_pickaxe",
    "count": 1
  }
}

The spaces in " S " matter: they keep the stick in the middle column.

Recap: recipes and tags are plain data-pack JSON in datapack/<namespace>/; use your mod id as the namespace and /reload to test changes.