Item modifier

Item modifiers are technical JSON files can be created inside data packs and are used to add loot table functions into existing items using the command.

Usage
An item modifier is a loot table function or an array of functions to apply at the item. They can be applied using the command.



JSON structure
Item modifiers are defined using the JSON format. Below are a list of tags used.


 * The root tag
 * : Namespaced ID of the function to apply.
 * Other parts of the function, specified below.

The possible values for and associated extra contents:


 * apply_bonus - Applies a predefined bonus formula.
 * : Enchantment ID used for level calculation.
 * : Can be  for a binomial distribution (with ,  ),   for uniform distribution (from   to  ), or   for a special function used for ore drops in the vanilla game.
 * : Values required for the formula.
 * : For formula 'binomial_with_bonus_count', the extra value.
 * : For formula 'binomial_with_bonus_count', the probability.
 * : For formula 'uniform_bonus_count', the bonus multiplier.


 * copy_name - For loot table type 'block', copies a block entity's  tag into the item's   tag.
 * - Needs to be set to 'block_entity'.


 * copy_nbt - Copies nbt to the item's  tag.
 * : Specifies the source. Set to  for the block entity of the destroyed block,   to use the entity that died or the player that gained the advancement, opened the container or broke the block,   for the killer, or   for a killer that is a player.
 * : Nbt provider type. One of,.
 * If  is  :
 * : Same as  above.
 * If  is  :
 * : A resource location specifying the storage ID.
 * : A list of copy operations.
 * An operation
 * : The nbt path to copy from.
 * : The nbt path to copy to, starting from the item's  tag.
 * : Can be  to replace any existing contents of the target,   to append to a list, or   to merge into a compound tag.
 * : Can be  to replace any existing contents of the target,   to append to a list, or   to merge into a compound tag.


 * copy_state - Copies state properties from dropped block to the item's  tag.
 * : A block ID. Function fails if the block doesn't match.
 * : A list of property names to copy.
 * A block state name to copy.


 * enchant_randomly - Enchants the item with one randomly-selected enchantment. The level of the enchantment, if applicable, is random.
 * : List of enchantment IDs to choose from. If omitted, all enchantments applicable to the item are possible.


 * enchant_with_levels - Enchants the item, with the specified enchantment level (roughly equivalent to using an enchantment table at that level).
 * : Determines whether treasure enchantments are allowed on this item.
 * : Number provider. Specifies the exact enchantment level to use.


 * exploration_map - Converts an empty map into an explorer map leading to a nearby generated structure.
 * : The type of generated structure to locate. Accepts any of the s used by the  command (case insensitive).
 * : The icon used to mark the destination on the map. Accepts any of the map icon text IDs (case insensitive). If  or   is used, the color of the lines on the item texture changes to match the corresponding explorer map.
 * : The zoom level of the resulting map. Defaults to 2.
 * : The size, in chunks, of the area to search for structures. The area checked is square, not circular. Radius 0 causes only the current chunk to be searched, radius 1 causes the current chunk and eight adjacent chunks to be searched, and so on. Defaults to 50.
 * : Don't search in chunks that have already been generated. Defaults to true.


 * explosion_decay - For loot tables of type 'block', removes some items from a stack, if there was an explosion. Each item has a chance of 1/explosion radius to be lost.


 * furnace_smelt - Smelts the item as it would be in a furnace. Used in combination with the  condition to cook food from animals on death.


 * fill_player_head - Adds required item tags of a player head
 * : Specifies an entity to be used for the player head. Set to  to use the entity that died or the player that gained the advancement, opened the container or broke the block,   for the killer, or   for a killer that is a player.


 * limit_count - Limits the count of every item stack.
 * : Number provider. Specifies the exact limit to use.
 * : Limits the count between a minimum and maximum value. Both are not required.
 * : Number provider. Minimum limit to use.
 * : Number provider. Maximum limit to use.


 * looting_enchant - Adjusts the stack size based on the level of the Looting enchantment on the  entity.
 * : Number provider. Specifies the number of additional items per level of looting. Note the number may be fractional, rounded after multiplying by the looting level.
 * : Specifies the maximum amount of items in the stack after the looting calculation. If the value is 0, no limit is applied.


 * set_attributes - Add attribute modifiers to the item.
 * : A modifier.
 * : Name of the modifier.
 * : The name of the attribute this modifier is to act upon.
 * : Must be either "addition", "multiply_base" or "multiply_total".
 * : Specifies the exact amount of change of the modifier.
 * : Specifies a random amount within a range.
 * : Minimum amount.
 * : Maximum amount.
 * : Optional : UUID of the modifier following. If none specified, a new UUID is generated.
 * : Slots the item must be in for the modifier to take effect, this value can be one of the following : "mainhand", "offhand", "feet", "legs", "chest", or "head".
 * : One of the listed slots is chosen randomly.
 * : One of the listed slots is chosen randomly.


 * set_banner_pattern - Sets tags needed for banner patterns.
 * : List of patterns.
 * : The pattern type. For example.
 * : The color for this pattern. One of,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,.
 * : Optional. If true, new patterns will be appended to existing ones.
 * : Optional. If true, new patterns will be appended to existing ones.


 * set_contents - For loot tables of type 'block', sets the contents of a container block item to a list of entries.
 * : The entries to use as contents.


 * set_count - Sets the stack size.
 * : Number provider. Specifies the stack size to set.
 * : Optional. If, change will be relative to current count.

<span id="function_set_damage">
 * set_damage - Sets the item's damage value (durability) for tools.
 * : Number provider. Specifies the damage fraction to set (1.0 is undamaged, 0.0 is zero durability left).
 * : Optional. If, change will be relative to current damage.

<span id="function_set_enchantments">
 * set_enchantments - Sets the item's enchantments.
 * : Enchantments to add.
 * : Key name is the enchantment ID. Value is a number provider specifying the enchantment level.
 * : Optional. If, change will be relative to current level.

<span id="function_set_loot_table">
 * set_loot_table - Sets the loot table for a container (chest etc.).
 * : Specifies the resource location of the loot table to be used.
 * : Optional. Specifies the loot table seed. If absent or set to 0, a random seed will be used.

<span id="function_set_lore">
 * set_lore - Adds lore to the item
 * : List of JSON text components. Each list entry represents one line of the lore.
 * : Specifies the entity to act as the source  in the JSON text component. Set to   to use the entity that died or the player that gained the advancement, opened the container or broke the block,   for the killer, or   for a killer that is a player.
 * : If true, replaces all existing lines of lore, if false appends the list.

<span id="function_set_name">
 * set_name - Adds display name of the item.
 * : A JSON text component name, allowing color, translations, etc.
 * : Specifies an entity to act as source  in the JSON text component. Set to   to use the entity that died or the player that gained the advancement, opened the container or broke the block,   for the killer, or   for a killer that is a player.

<span id="function_set_nbt">
 * set_nbt - Adds NBT data to the item.
 * : Tag string to add, similar to those used by commands. Note that the first bracket is required and quotation marks need to be escaped using a backslash.

<span id="function_set_stew_effect">
 * set_stew_effect - Sets the status effects for suspicious stew.
 * : The effects to apply.
 * An effect.
 * : The effect ID.
 * : Number provider. The duration of the effect.

Data packs
Custom data packs can add new item modifiers. This is the file structure:


 * world save folder
 * datapacks
 * data pack
 * data
 * custom_namespace
 * item_modifiers
 * item modifier name.json

The JSON files go in this folder. Item modifiers are namespaced. To create an item modifier, first create a new folder for the custom namespace, and then create item modifiers within following a similar structure. Then, use /item ... modify with the name of the directory and file (without the .json extension) as the, such as.

Issues
物品修饰符