Recipes and loot
Status: Implemented for recipes (vanilla and mod items), loot tables (mod items allowed) and mod block drops, all as data. Changing loot tables from code and new recipe types are Planned.
Goal: a cheaper recipe for an existing item, a mod ore that drops rubies with fortune, and rubies in dungeon chests.
APIs: Recipes, loot and tags. No code needed except the block registration.
1. A recipe (data only)
datapack/my_mod/recipe/cheap_saddle.json:
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"pattern": ["LLL", "L L"],
"key": { "L": "minecraft:leather" },
"result": { "id": "minecraft:saddle", "count": 1 }
}
Every vanilla recipe type works. /reload picks up changes.
Mod items go in by id, as ingredients and results. datapack/my_mod/recipe/ruby_block.json:
{
"type": "minecraft:crafting_shaped",
"category": "building",
"pattern": ["###", "###", "###"],
"key": { "#": "my_mod:ruby" },
"result": { "id": "my_mod:ruby_block", "count": 1 }
}
Mod items work as ingredients and results (by id, "my_mod:ruby"): a mod item matches only itself, never its base item, so nine rubies make a ruby block and nine emeralds still make an emerald block. Item tags can list mod items too (datapack/my_mod/tags/item/gems.json with { "values": ["my_mod:ruby", "minecraft:emerald"] }, then "#my_mod:gems" as an ingredient). Smithing results and brewing outputs can be mod items, and a smithing result keeps the base item’s name, enchantments and damage like vanilla.
2. A mod ore that drops rubies
Register the ore and the ruby item (A custom block, Custom items (tools, food, usable items)), then add its block loot table, datapack/my_mod/loot_table/blocks/ruby_ore.json:
{
"type": "minecraft:block",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:alternatives",
"children": [
{ "type": "minecraft:item", "condition": "minecraft:tool/can_silk_touch", "name": "my_mod:ruby_ore" },
{
"type": "minecraft:item",
"name": "my_mod:ruby",
"modifier": [
{ "type": "minecraft:set_count", "count": { "type": "minecraft:uniform", "min": 1, "max": 2 } },
{ "type": "minecraft:apply_bonus", "enchantment": "minecraft:fortune", "formula": "minecraft:ore_drops" }
]
}
]
}
]
}
]
}
The table is used for player breaks, explosions and /loot. Start from a vanilla block table and change the names; mind this version’s format (item changes go into "modifier", each with a "type").
Experience from code:
cl.on("block.break", function(event)
if event.block == "my_mod:ruby_ore" then event.xp = 3 end
end)
3. Rubies in dungeon chests
Changing loot tables from code is planned. Today, replace the vanilla table with a copy that adds your pool: datapack/minecraft/loot_table/chests/simple_dungeon.json (the vanilla file plus a pool with "name": "my_mod:ruby"). A replaced table conflicts with other mods or data packs that replace the same file (the higher pack wins), so only do this for tables you really need.
4. Planned
Mod items in item tags, adding pools to loot tables when they load, and recipe types and serializers of your own.