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.

⚠ Version differences
  • Since 1.21 (pack_format 48): folder is singular β€” data/<ns>/item_modifier/. Before 1.21: plural item_modifiers/.
  • Since 1.20.5 (pack_format 41): item NBT was replaced by data components β€” set_nbt was split into set_custom_data and set_components, and copy_nbt became copy_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:

FunctionSuccessor toWhat it writesUse when
set_custom_dataDirect successor to set_nbtThe arbitrary-tag custom_data component only.Round-tripping old {Tag}-style NBT, or storing your own pack's marker data on an item.
set_componentsNew 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:

FunctionSuccessor toCopies
copy_custom_dataDirect successor to copy_nbtNBT paths from a source (context / storage / block entity) into the item's custom_data.
copy_componentsNew general functionTyped components from a block entity into the item (with optional include/exclude).
πŸ“Œ Note

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.

FunctionFields
set_countcount (number provider), add (bool, default false)
set_damagedamage (number provider), add (bool, default false)
set_componentscomponents (component map)
set_custom_datatag (SNBT string or object) β€” writes custom_data
set_lorelore (array of text components), mode (append / insert / replace_all / replace_section), entity (ctx, optional), offset (int), size (int)
set_namename (text component), entity (ctx, optional), target (custom_name / item_name, default custom_name)
set_enchantmentsenchantments (map ID→level, each a number provider), add (bool)
enchant_randomlyoptions (array / #tag, optional), only_compatible (bool, default true)
enchant_with_levelslevels (number provider), options (optional)
enchanted_count_increaseenchantment (ID), count (number provider), limit (int, default 0) β€” the looting replacement
apply_bonusenchantment (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_countlimit (int, or {min, max} clamp)
set_attributesmodifiers (array of {attribute, id, amount(np), operation, slot}), replace (bool, default true)
set_stew_effecteffects (array of {type, duration})
set_potionid (potion ID)
set_ominous_bottle_amplifieramplifier (number provider)
set_instrumentoptions (instrument #tag)
set_book_coverauthor, title (text component), generation (0–3) β€” all optional
set_written_book_pages / set_writable_book_pagespages (array), mode, offset, size
set_banner_patternpatterns (array), append (bool)
set_firework_explosionshape, colors (ints), fade_colors (ints), has_trail, has_twinkle
set_fireworksexplosions (list op: values / mode / offset / size), flight_duration (0–255)
set_custom_model_datafloats / flags / strings / colors (each a list op) β€” 1.21.4+ structured CMD
set_contentsentries (array), component (container / bundle_contents / charged_projectiles)
modify_contentscomponent (container-like), modifier (item modifier(s) applied to contents)
set_loot_tablename (table ID), type (block-entity type), seed (optional) β€” for container block items
set_itemitem (ID) β€” replaces the stack's item type
copy_componentssource (block_entity), include / exclude (arrays, optional)
copy_custom_datasource (context / storage / block_entity), ops (array of {source, target, op})
copy_namesource (context: block_entity / entity)
copy_stateblock (ID), properties (array of state names) β€” copies mined block states into block_state
exploration_mapdestination (#tag), decoration, zoom (int, def 2), search_radius (int, def 50), skip_existing_chunks (bool, def true)
fill_player_headentity (ctx ref) β€” writes the profile of a player from context
filtereditem_filter (item predicate), modifier (item modifier applied on match)
toggle_tooltipstoggles (booleans: attribute_modifiers, can_break, can_place_on, dyed_color, enchantments, stored_enchantments, trim, unbreakable)
set_random_dyes / set_random_potionrandomised dye / potion helpers
referencename (referenced item-modifier ID or array)
sequencefunctions (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

πŸ’‘ Best practice

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.

🎩 Trick

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.

🚧 Workaround

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 ….

πŸ’‘ Best practice

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.

Sources