![]() |
VOOZH | about |
Item modifiers (also known as loot modifiers) can be used to apply modifications to item stacks, such as adjusting the stack size or adding enchantments. They can be defined in datapacks as JSON files, or used in loot tables. The /item command also accepts item modifiers in SNBT format.
A single modification in item modifiers is called item function or loot function.
An item modifier is a single loot function or an array of loot functions to apply to the item. The root element of an item modifier can be either an [NBT Compound / JSON Object] JSON object or NBT compound tag, following the structure of a loot function below, or an [NBT List / JSON Array] JSON array or NBT list, containing multiple loot functions.
Item modifiers are defined using the JSON format in data packs, or the SNBT format in /item command.
Item modifiers defined in data packs in the following directory structure, highlighted below:
Item modifiers can be invoked with the /item command. When doing so, it is required to specify a target slot to invoke the modifier upon, either an item inside a container block's contents, or inside an entity's inventory.
There are two variations of this command: /item modify invokes a modifier alone upon the target slot, /item replace replaces the item in the target slot with another and subsequently invokes a modifier upon it.
/item modify (block <pos> | entity <targets>) <slot> <modifier>/item replace (block <pos> | entity <targets>) <slot> from (block <pos> | entity <targets>) [<modifier>]In loot tables, item modifiers can be defined without the need for a separate file; however, separate files can also be explicitly referenced using the reference function.
The format of a single item modifier is:
Multiple modifiers may be bundled into one by placing them into a JSON array or an NBT list. In this case, all listed modifiers are applied in sequence, similar to the sequence modifier type.
The possible resource locations (namespace minecraft: is omitted) for [String] function field and associated extra contents:
binomial_with_bonus_count for 1 bonus item plus bonus determined by binomial distribution with n=level + extra, p=probability. Can be uniform_bonus_count for uniform distribution (from 0 to level * bonusMultiplier), or ore_drops for a special function used for ore drops in the vanilla game (Count *= (max(1; randomInt(0(inclusive) .. (Level + 2)(exclusive))))).block_entity, this, attacker, direct_attacker, attacking_player, target_entity, interacting_entity, toolminecraft:custom_data component.
context. Specifies an entity or block entity from loot context. Can be block_entity, this, attacker, direct_attacker, attacking_player, target_entity, or interacting_entity..context to use a block entity or an entity as the source, or storage to use a command storage as the source.type is set to context. Specifies an entity or block entity from loot context to copy NBT from. Can be block_entity, this, attacker, direct_attacker, attacking_player, target_entity, or interacting_entity..type is set to storage. A resource location specifying the storage ID to copy NBT from.minecraft:custom_data component.replace to replace any existing contents of the target NBT path, append to append to a list or array, or merge to merge into a compound tag.minecraft:custom_name component.
block_entity, this, attacking_entity, last_damage_player, direct_attacker, target_entity or interacting_entity.minecraft:block_state component.
#, or an [NBT List / JSON Array] array containing [String] IDs). List of enchantments to choose from. If omitted, all enchantments are possible.true. Whether only enchantments that are compatible with the item should be chosen (i.e. the item is listed in the enchantments supported_items). Books are always considered compatible.false. Whether to add a additional_trade_cost component to the item. The value is calculated as 2 + random(0, 5 + level * 10) + 3 * level where level is the level of the enchantment applied.#, or an [NBT List / JSON Array] array containing [String] IDs). List of enchantments to choose from. If omitted, all enchantments are possible.false. Whether to add a additional_trade_cost component to the item. The value is equal to the value determined by [Int][NBT Compound / JSON Object] levels.killer entity provided by loot context.
on_treasure_maps.mansion or monument is used, the color of the lines on the item texture changes to match the corresponding explorer map. Defaults to mansion.this, attacker, direct_attacker, attacking_player, target_entity, or interacting_entity..bundle_contents, charged_projectiles, container}}.add_value, add_multiplied_base, or add_multiplied_total.mainhand, offhand, feet, legs, chest, head.true to replace the existing item attributes with the attributes in [NBT List / JSON Array] modifiers. If false, the lines are appended to the list of existing attributes. Defaults to true.square_bottom_left.white, orange, magenta, light_blue, yellow, lime, pink, gray, light_gray, cyan, purple, blue, brown, green, red, black.minecraft:written_book_content component. If present, any pages in the book are left untouched.
0 to 3. If omitted, the original generation is kept (or 0 is used if there was no component).! prefix (e.g. "!minecraft:damage": {}) causes this component to be removed.container, bundle_contents, and charged_projectiles. Both bundle_contents and charged_projectiles ignore empty stacks.[2]true, change is relative to current count. Defaults to false.minecraft:custom_data component.
minecraft:custom_data component, either within a JSON string or as unflattened tags. That means that {"tag": "{a:1}"} and {"tag": {"a":1}} are equivalent. When using the string representation, additional care is required: the outer braces { } of the component must still be present and if the NBT contains quotation marks ", they must be escaped with a backslash \.minecraft:custom_model_data component.
"append", "insert", "replace_all", "replace_section"."insert" or "replace_section". Specifies index to insert or replace values from. Defaults to 0"replace_section". Specifies the size of the range to be replaced. If omitted, the size of [NBT List / JSON Array] values field is used."append", "insert", "replace_all", "replace_section"."insert" or "replace_section". Specifies index to insert or replace values from. Defaults to 0"replace_section". Specifies the size of the range to be replaced. If omitted, the size of [NBT List / JSON Array] values field is used."append", "insert", "replace_all", "replace_section"."insert" or "replace_section". Specifies index to insert or replace values from. Defaults to 0"replace_section". Specifies the size of the range to be replaced. If omitted, the size of [NBT List / JSON Array] values field is used."append", "insert", "replace_all", "replace_section"."insert" or "replace_section". Specifies index to insert or replace values from. Defaults to 0"replace_section". Specifies the size of the range to be replaced. If omitted, the size of [NBT List / JSON Array] values field is used.true, change is relative to current damage. Defaults to false.true, change is relative to current level. A nonexistent enchantment is presumed to start at 0. Defaults to false.minecraft:fireworks component.
small_ball, large_ball, star, creeper, or burst."append", "insert", "replace_all", "replace_section"."insert" or "replace_section". Specifies index to insert or replace explosions from. Defaults to 0"replace_section". Specifies the size of the range to be replaced. If omitted, the size of [NBT List / JSON Array] explosions field is used.0 to 255. Determines flight duration measured in number of gunpowder. If omitted, the flight duration of the item is left untouched (or set to 0 if the component did not exist before).minecraft:firework_explosion component.
small_ball, large_ball, star, creeper, or burst.# of an instrument tag, one of the listings is selected randomly.BlockEntityTag.id.entity successfully targets an entity.@s when referenced in the JSON text component. Specifies an entity from loot context. Can be this, attacker, direct_attacker, attacking_player, target_entity, or interacting_entity.."append", "insert", "replace_all", "replace_section"."insert" or "replace_section". Specifies index to insert or replace lines of lore from. Defaults to 0"replace_section". Specifies the size of the range to be replaced. If omitted, the size of [NBT List / JSON Array] lore field is used.entity successfully targets an entity.@s when referenced in the JSON text component. Specifies an entity from loot context. Can be this, attacker, direct_attacker, attacking_player, target_entity, or interacting_entity..custom_name or item_name, corresponding with the component to be set. Defaults to custom_name.ominous_bottle_amplifier component of an item.
ominous_bottle_amplifier component.potion_contents component of an item.
empty to remove the Potion tag.dyed_color component of an item.
minecraft:writable_book_content component.
"append", "insert", "replace_all", "replace_section"."insert" or "replace_section". Specifies index to insert or replace pages from. Defaults to 0"replace_section". Specifies the size of the range to be replaced. If omitted, the size of [NBT List / JSON Array] pages field is used.minecraft:written_book_content component.
"append", "insert", "replace_all", "replace_section"."insert" or "replace_section". Specifies index to insert or replace pages from. Defaults to 0"replace_section". Specifies the size of the range to be replaced. If omitted, the size of [NBT List / JSON Array] pages field is used.| Java Edition | |||||||
|---|---|---|---|---|---|---|---|
| 1.9 | 15w43a | Added loot functions as part of loot tables. | |||||
| 1.17 | 20w46a | Added the ability to create dedicated item modifier files in data packs using the same syntax as existing loot functions. | |||||
| 1.18 | 21w39a | Added set_potion function. | |||||
| 1.19 | 22w18a | Added set_instrument function. | |||||
| 1.20 | 23w14a | Added reference function. | |||||
| 1.20.2 | 23w32a | Added sequence function. | |||||
| 1.20.5 | 24w09a | Added set_components function. | |||||
Added copy_components function. | |||||||
set_nbt and copy_nbt functions have been renamed to set_custom_data and copy_custom_data respectively.
| |||||||
set_attributes function has been updated:
| |||||||
| 24w11a | Added set_fireworks function.
| ||||||
Added set_firework_explosion function.
| |||||||
Added set_book_cover function.
| |||||||
Added set_writable_book_pages function.
| |||||||
Added set_written_book_pages function. | |||||||
| 24w12a | Added toggle_tooltips function. | ||||||
Replaced the replace field for set_lore with the mode and offset fields. | |||||||
| 24w13a | Removed field components from copy_components function and replaced it with include and exclude. Only components that are included (explicitly or implicitly) but not excluded are copied.
| ||||||
Added optional field target to the set_name function to specify whether the custom_name or item_name component should be set. | |||||||
| 24w14a | Added replace field to the set_attributes function. | ||||||
| Pre-Release 1 | Updated set_contents function:
| ||||||
Updated set_custom_data function:
| |||||||
Added filtered function.
| |||||||
Added modify_contents function.
| |||||||
Added set_custom_model_data function.
| |||||||
Added set_item function.
| |||||||
| Pre-Release 2 | set_fireworks function has been updated:
| ||||||
| 1.21 | 24w18a | Target entities killer, direct_killer, killer_player were renamed to attacker, direct_attacker, attacking_player
| |||||
copy_name source entities killer and killer_player were renamed to attacking_entity and last_damage_player | |||||||
| 24w21a | Moved item modifiers from π File directory.png: Sprite image for directory in Minecraft to π File directory.png: Sprite image for directory in Minecraft | ||||||
| 1.21.4 | 24w45a | minecraft:set_custom_model_data now has more fields to accommodate more complex component structure. | |||||
| 1.21.9 | Pre-Release 1 | minecraft:copy_name: The source field now accepts new context values. | |||||
minecraft:copy_components: The source field now accepts new context values. | |||||||
| 1.21.11 | 25w43a | Added minecraft:discard. | |||||
minecraft:filtered: The field modifier has been replaced with two fields: on_pass and on_fail. | |||||||
| 26.1 | snap1 | Added minecraft:set_random_dyes, and minecraft:set_random_potion. | |||||
Changed minecraft:enchant_with_levels, now also takes the following field: include_additional_cost_component. | |||||||
Changed minecraft:enchant_randomly, now also takes the following field: include_additional_cost_component. | |||||||
| snap5 | minecraft:set_random_dyes: No longer works only for items in #dyeable tag. | ||||||
| pre1 | minecraft:set_instrument: The options field now also accepts an ID and a list of IDs in addition to a tag. | ||||||
| Upcoming Java Edition | |||||||
| 26.3 | snapshot1 | Added minecraft:command_slot_source loot table type. | |||||
Issues relating to "Item modifier" are maintained on the bug tracker. Issues should be reported and viewed there.