Skip to content

Recipes and data packs

Lesson 7.3

Recipes don’t need any C. 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
      loot_table/
        blocks/
          ruby_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. clight build packs the whole folder.

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 is ten seconds, like vanilla ores. minecraft:blasting, minecraft:smoking and minecraft:campfire_cooking work the same way.

Tags

A tag is a named group of items or blocks. Other recipes and mods can use the group instead of listing every item. tags/item/gems.json:

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

In a recipe, "#my_mod:gems" (with the #) means “any item in that tag”. To add your item to a vanilla tag, put the file under datapack/minecraft/tags/... with "replace": false, so you add to the list instead of replacing it.

Loot tables

Loot tables go into loot_table/, in vanilla’s format. For your own blocks, loot_table/blocks/<block name>.json decides the drops when the block breaks (by a player, an explosion or /loot), and it may name your mod’s items. Without a table, a mod block drops its own item when mined with the right tool. Mind this version’s format: item changes go into "modifier" and each one has a "type", for example { "type": "minecraft:set_count", "count": 2 }. The SDK’s example mod ships loot_table/blocks/ruby_block.json as a starting point.

Checking your files

The game reports broken JSON and unknown ids in the log when the world loads, like it does for any data pack. /reload in a world reloads the data pack files without a restart, which is handy while you tune recipes.

Try it

Write a shaped recipe that turns 4 rubies in a 2 x 2 square into one minecraft:diamond. Which file name do you pick, and what is the recipe’s id?

Show a solution

datapack/my_mod/recipe/diamond_from_rubies.json:

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

The id is my_mod:diamond_from_rubies. A 2 x 2 pattern also fits the small crafting grid in the player’s inventory.

Recap: recipes, tags and loot tables are vanilla data-pack JSON files in datapack/<mod id>/, and need no code.