Item modifiers
Standalone, reusable loot functions stored at data/<namespace>/item_modifier/ and applied to real item stacks with /item modify. They share the exact same function system as loot-table functions. Primary syntax targets 1.21+ (singular item_modifier/ folder).
What an item modifier is
An item modifier file is a standalone, reusable loot function β or an array of functions applied in order. Its root is either a single function object or an array of them. It uses the identical function schema as the functions lists inside loot tables, so any function documented for loot tables works here and vice-versa. The folder is singular item_modifier/ since 1.21.
Every function object has the form {"function": "minecraft:<id>", β¦params} and may carry an optional conditions array (loot conditions β see predicates). A bare array of functions behaves exactly like the sequence function.
- Since 1.21 (pack_format 48): folder is singular β
data/<ns>/item_modifier/. Before 1.21: pluralitem_modifiers/. - Since 1.20.5 (pack_format 41): item NBT was replaced by data components β
set_nbtwas split intoset_custom_dataandset_components, andcopy_nbtbecamecopy_custom_data(see below).
Applying with /item modify
Item modifiers are applied to a real stack in the world with the /item modify command, targeting a slot on an entity or a block container:
In a function or the chat console
/item modify entity @s weapon.mainhand mypack:sharpen
/item modify block ~ ~ ~ container.0 mypack:sharpen
The modifier's own conditions can only reference loot context, so to gate application on live entity state, gate the command with a predicate instead:
/execute as @a if predicate mypack:holding_sword run item modify entity @s weapon.mainhand mypack:sharpen
set_nbt successors β set_custom_data vs set_components
The 1.20.5 component migration split the old set_nbt function into two distinct functions. Choosing the right one matters:
| Function | Successor to | What it writes | Use when |
|---|---|---|---|
set_custom_data | Direct successor to set_nbt | The arbitrary-tag custom_data component only. | Round-tripping old {Tag}-style NBT, or storing your own pack's marker data on an item. |
set_components | New general function (no old equivalent) | Any typed data component (name, lore, enchantments, rarity, β¦). | Setting real vanilla components that drive item behaviour or display. |
The copy family mirrors this split:
| Function | Successor to | Copies |
|---|---|---|
copy_custom_data | Direct successor to copy_nbt | NBT paths from a source (context / storage / block entity) into the item's custom_data. |
copy_components | New general function | Typed components from a block entity into the item (with optional include/exclude). |
The shorthand "set_nbt β set_components" is only loosely true. For arbitrary custom tags the correct replacement is set_custom_data; reserve set_components for typed vanilla components. See Data components for the component catalogue.
Function catalogue
The complete 1.21+ function set. Every function is {"function": "minecraft:<id>", β¦} and may carry an optional conditions array. Fields shown as "number provider" accept the shorthand and explicit forms documented for loot tables.
| Function | Fields |
|---|---|
set_count | count (number provider), add (bool, default false) |
set_damage | damage (number provider), add (bool, default false) |
set_components | components (component map) |
set_custom_data | tag (SNBT string or object) β writes custom_data |
set_lore | lore (array of text components), mode (append / insert / replace_all / replace_section), entity (ctx, optional), offset (int), size (int) |
set_name | name (text component), entity (ctx, optional), target (custom_name / item_name, default custom_name) |
set_enchantments | enchantments (map IDβlevel, each a number provider), add (bool) |
enchant_randomly | options (array / #tag, optional), only_compatible (bool, default true) |
enchant_with_levels | levels (number provider), options (optional) |
enchanted_count_increase | enchantment (ID), count (number provider), limit (int, default 0) β the looting replacement |
apply_bonus | enchantment (ID), formula (uniform_bonus_count / ore_drops / binomial_with_bonus_count), parameters (extra / probability / bonusMultiplier) |
furnace_smelt | (none) β outputs the smelted form |
explosion_decay | (none) β randomly removes items per explosion radius |
limit_count | limit (int, or {min, max} clamp) |
set_attributes | modifiers (array of {attribute, id, amount(np), operation, slot}), replace (bool, default true) |
set_stew_effect | effects (array of {type, duration}) |
set_potion | id (potion ID) |
set_ominous_bottle_amplifier | amplifier (number provider) |
set_instrument | options (instrument #tag) |
set_book_cover | author, title (text component), generation (0β3) β all optional |
set_written_book_pages / set_writable_book_pages | pages (array), mode, offset, size |
set_banner_pattern | patterns (array), append (bool) |
set_firework_explosion | shape, colors (ints), fade_colors (ints), has_trail, has_twinkle |
set_fireworks | explosions (list op: values / mode / offset / size), flight_duration (0β255) |
set_custom_model_data | floats / flags / strings / colors (each a list op) β 1.21.4+ structured CMD |
set_contents | entries (array), component (container / bundle_contents / charged_projectiles) |
modify_contents | component (container-like), modifier (item modifier(s) applied to contents) |
set_loot_table | name (table ID), type (block-entity type), seed (optional) β for container block items |
set_item | item (ID) β replaces the stack's item type |
copy_components | source (block_entity), include / exclude (arrays, optional) |
copy_custom_data | source (context / storage / block_entity), ops (array of {source, target, op}) |
copy_name | source (context: block_entity / entity) |
copy_state | block (ID), properties (array of state names) β copies mined block states into block_state |
exploration_map | destination (#tag), decoration, zoom (int, def 2), search_radius (int, def 50), skip_existing_chunks (bool, def true) |
fill_player_head | entity (ctx ref) β writes the profile of a player from context |
filtered | item_filter (item predicate), modifier (item modifier applied on match) |
toggle_tooltips | toggles (booleans: attribute_modifiers, can_break, can_place_on, dyed_color, enchantments, stored_enchantments, trim, unbreakable) |
set_random_dyes / set_random_potion | randomised dye / potion helpers |
reference | name (referenced item-modifier ID or array) |
sequence | functions (array run in order) |
Worked examples
A multi-step modifier that renames, enchants, adds lore and stamps components onto whatever stack it is applied to. As an array, its four functions run in order like sequence.
data/<namespace>/item_modifier/make_masterwork.json
[
{ "function": "minecraft:set_name",
"name": "{\"text\":\"Masterwork\",\"color\":\"aqua\",\"italic\":false}",
"target": "item_name" },
{ "function": "minecraft:set_enchantments",
"enchantments": { "minecraft:unbreaking": 3, "minecraft:mending": 1 }, "add": false },
{ "function": "minecraft:set_lore",
"mode": "append",
"lore": ["{\"text\":\"Forged by the datapack gods\",\"color\":\"gray\",\"italic\":true}"] },
{ "function": "minecraft:set_components",
"components": { "minecraft:rarity": "epic", "minecraft:custom_data": "{masterwork:1b}" } }
]
Apply it with:
/item modify entity @s weapon.mainhand mypack:make_masterwork
A single-function modifier that writes only your pack's marker tag using the direct set_nbt successor β the right tool when you just need a private flag, not a vanilla component.
data/<namespace>/item_modifier/tag_quest_item.json
{
"function": "minecraft:set_custom_data",
"tag": "{quest_item:1b, quest_id:\"ember\"}"
}
A filtered modifier that only enchants swords within a mixed stack of drops β useful as a table-wide loot function that should act selectively.
data/<namespace>/item_modifier/enchant_only_swords.json
{
"function": "minecraft:filtered",
"item_filter": { "items": "#minecraft:swords" },
"modifier": {
"function": "minecraft:enchant_with_levels",
"levels": { "min": 20, "max": 30 }
}
}
Tricks & best practices
Store one modifier, reuse everywhere. Pull a canonical modifier into loot tables and other modifiers with {"function": "minecraft:reference", "name": "mypack:x"} β this keeps a custom-item definition in a single file.
filtered lets one table-wide modifier act only on matching stacks (e.g. only enchant swords in a mixed drop), so you don't have to duplicate functions per entry.
A modifier's own conditions only see loot context, so they cannot test live player/entity state. To gate application on real state, gate the command: /execute if predicate β¦ run item modify β¦.
copy_* functions (copy_name, copy_components, copy_custom_data, copy_state) are how block-entity data β custom names, container contents β survives a block being broken. Use them in block loot tables for custom container blocks.