Ore Loot Tables
FORMAT VERSION 1.26.50
This tutorial assumes a basic understanding of blocks. Check out the blocks guide before starting.
This tutorial aims to show a new way of creating custom ore blocks with a proper loot table. The minecraft:loot component will run the specified loot table regardless of the tool used, but by adding the match_tool condition to your loot table you can specify what tools are required per pool.
In addition, through use of scripts and custom components, we can create the experience orb reward offered by vanilla ores if the correct tool is used to destroy the block.
Features:
- Can only be mined using an appropriate tool
- Can specify enchantments on items
- Also drops experience reward
Issues:
- Non-player methods of breaking the block (explosions, commands, etc.) will fail to drop the loot
Loot Table
In the example below, you can see how the match_tool condition is used to test for a pickaxe item that is iron tier or higher, or that has a custom wiki:silver_tier tag. The tier tags are just item tags, so a custom pickaxe can opt in by listing wiki:silver_tier in its minecraft:tags component:
{
"pools": [
{
"rolls": 1,
"conditions": [
{
"condition": "match_tool",
"minecraft:match_tool_filter_all": [
"minecraft:is_tool",
"minecraft:is_pickaxe"
],
"minecraft:match_tool_filter_any": [
"minecraft:iron_tier",
"minecraft:diamond_tier",
"minecraft:netherite_tier",
"wiki:silver_tier"
],
"count": 1
}
],
"entries": [
{
"type": "item",
"name": "wiki:raw_silver"
}
]
}
]
}"minecraft:tags": {
"tags": ["minecraft:is_tool", "minecraft:is_pickaxe", "wiki:silver_tier"]
}Specifying Enchantments
If needed you can add the enchantments section to your condition, but remember each tool and level must be listed as separate pools.
Also note that it can correctly detect only 1st and 2nd enchantment level.
{
"condition": "match_tool",
...
"enchantments": [
{
"fortune": {
"level": 1
}
}
]
}XP Reward Script
To spawn experience orbs when your ore block is destroyed, custom components can be used. Here, we use the onPlayerBreak event hook. If you don't want your block to spawn XP, this step can be ignored.
Rather than duplicating the tool requirements in script, we read them straight from the loot table. The LootTableManager can load any loot table in the pack, and each of its pools exposes its LootItemConditions. We look for a MatchToolCondition and check the item in the player's hand against it, so the script stays in sync with silver_ore.json even if you change the required tool tier later.
import { system, world, EquipmentSlot, MatchToolCondition } from "@minecraft/server";
/**
* @param {number} min The minimum integer
* @param {number} max The maximum integer
* @returns {number} A random integer between the `min` and `max` parameters (inclusive)
* */
const randomInt = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
/**
* @param {number} value The value to test
* @param {import("@minecraft/common").NumberRange} range The range read from the loot table
* @returns {boolean} Whether the value is within the range (inclusive)
* */
const inRange = (value, range) => value >= range.min && value <= range.max;
/**
* @param {import("@minecraft/server").ItemStack} itemStack The tool to test
* @param {MatchToolCondition} condition The `match_tool` condition read from the loot table
* @returns {boolean} Whether the tool satisfies the condition
* */
const matchesTool = (itemStack, condition) => {
// Item type and tags
if (condition.itemName && !itemStack.matches(condition.itemName)) return false;
if (!condition.itemTagsAll.every((tag) => itemStack.hasTag(tag))) return false;
if (
condition.itemTagsAny.length > 0 &&
!condition.itemTagsAny.some((tag) => itemStack.hasTag(tag))
)
return false;
if (condition.itemTagsNone.some((tag) => itemStack.hasTag(tag))) return false;
// Stack size
if (!inRange(itemStack.amount, condition.count)) return false;
// Remaining durability
const durable = itemStack.getComponent("minecraft:durability");
if (durable && !inRange(durable.maxDurability - durable.damage, condition.durability))
return false;
// Enchantments
const enchantable = itemStack.getComponent("minecraft:enchantable");
for (const { enchantment, range } of condition.enchantments) {
const level = enchantable?.getEnchantment(enchantment)?.level ?? 0;
if (!inRange(level, range)) return false;
}
return true;
};
/**
* @param {import("@minecraft/server").ItemStack} itemStack The tool to test
* @param {string} lootTablePath Path of the loot table, without the `loot_tables/` prefix or file extension
* @returns {boolean} Whether every `match_tool` condition in the loot table passes for this tool
* */
const canDropLoot = (itemStack, lootTablePath) => {
const lootTable = world.getLootTableManager().getLootTable(lootTablePath);
if (!lootTable) return false; // Exit if the loot table doesn't exist
return lootTable.pools.every((pool) =>
pool.conditions.every((condition) => {
if (!(condition instanceof MatchToolCondition)) return true; // Only `match_tool` conditions are checked
return matchesTool(itemStack, condition);
})
);
};
const BlockExperienceRewardComponent = {
onPlayerBreak({ block, dimension, player }, { params }) {
// Check the tool in the player's hand
const equippable = player?.getComponent("minecraft:equippable");
if (!equippable) return; // Exit if the player or its equipment are undefined
const itemStack = equippable.getEquipment(EquipmentSlot.Mainhand);
if (!itemStack || !canDropLoot(itemStack, params.loot_table)) return; // Exit if the tool wouldn't drop the block's loot
// Specify enchantments
const enchantable = itemStack.getComponent("minecraft:enchantable");
const silkTouch = enchantable?.getEnchantment("silk_touch");
if (silkTouch) return; // Exit if the pickaxe has the Silk Touch enchantment
// Spawn the XP orbs
const xpAmount = randomInt(params.min, params.max); // Number of XP orbs to spawn
for (let i = 0; i < xpAmount; i++) {
dimension.spawnEntity("minecraft:xp_orb", block.location);
}
},
};
// Register a custom component before the world is loaded
system.beforeEvents.startup.subscribe(({ blockComponentRegistry }) => {
blockComponentRegistry.registerCustomComponent(
"wiki:experience_reward",
BlockExperienceRewardComponent
);
});Block JSON
The following block behavior can be used as a template. Don't forget to set the block's texture using terrain_texture.json.
Here you need to do two things:
- Point to the new loot table with the
minecraft:lootcomponent. - Add our experience reward custom component to the block's
components.
{
"format_version": "1.26.50",
"minecraft:block": {
"description": {
"identifier": "wiki:silver_ore",
"menu_category": {
"category": "nature",
"group": "minecraft:itemGroup.name.ore"
}
},
"components": {
"minecraft:loot": "loot_tables/blocks/silver_ore.json", // Won't be dropped if using Silk Touch.
"wiki:experience_reward": {
"min": 0,
"max": 3
}
}
}
}Result









