Item Modifiers
Item modifiers (also called loot functions) transform item stacks by adjusting counts, adding enchantments, copying data, setting components, and more. They can be defined as standalone JSON files referenced by commands, or used inline within loot tables.
Overview
Item modifiers have several key characteristics:
- Composable: Chain multiple functions together for complex transformations
- Conditional: Each function can have a predicate condition
- Context-aware: Access loot context for killer, tool, block entity, etc.
- Reusable: Define once as a file, reference anywhere
Common Use Cases
| Use Case | Functions |
|---|---|
| Set stack count | setCount |
| Add enchantments | enchantRandomly, enchantWithLevels, setEnchantments |
| Modify durability | setDamage |
| Copy NBT/components | copyComponents, copyCustomData, copyName |
| Set name/lore | setName, setLore |
| Create explorer maps | explorationMap |
| Fill containers | setContents, setLootTable |
| Apply formulas | applyBonus, enchantedCountIncrease |
File Structure
Item modifiers are stored as JSON files in data packs at:
A file holds one function object ({ "type": "minecraft:set_count", ... }) whose type names its kind. Several functions, or a lone reference to another item modifier ("my_pack:base") or an item modifier tag ("#my_pack:buffs"), are written as a minecraft:sequence, which Kore does for you. An itemModifier { } without any function throws when the pack is generated.
For complete JSON specification, see the Minecraft Wiki - Item modifier.
Creating Item Modifiers
Use the itemModifier builder function to create item modifiers in Kore:
This generates data/my_datapack/item_modifier/fortune_bonus.json.
Using Item Modifiers
With Commands
Apply modifiers to items using the /item modify command:
An inline modifier is written in the command as SNBT and keeps the short forms a file doesn't have: one function as an object, several as a list, or an ID.
In Loot Tables
Use functions directly in loot tables at table, pool, or entry level:
Each modifier also takes an item modifier ID, modifier { reference(baseModifier) }, see reference.
Function Reference
Count and Damage
setCount
Sets or modifies the stack count:
setDamage
Sets item durability (1.0 = full, 0.0 = broken):
The numeric fields of item functions are context providers: an int provider (1, uniform(1, 5)) or a float provider (1f, uniform(0.5f, 1f)) depending on the field, a fixed value being a plain number. Each also accepts the ID of a context provider file through reference(...):
| Function | Field | Provider |
|---|---|---|
setCount |
count |
int |
limitCount |
min, max |
int |
enchantWithLevels |
levels |
int |
setEnchantments |
the level of each enchantment | int |
setOminousBottleAmplifier |
amplifier |
int |
setRandomDyes |
numberOfDyes |
int |
setStewEffect |
duration of each effect |
int |
setCustomModelData |
colors |
int |
setCustomModelData |
floats |
float |
setDamage |
damage |
float |
setAttributes |
amount of each modifier |
float |
enchantedCountIncrease |
count |
float |
A convenience overload takes a plain Int for an int field and a plain Float for a float field.
limitCount
Clamps stack count to a range. The game only reads the { min, max } object, each bound being an int provider and either one optional:
limitCount(1..32) clamps the count between the two bounds and draws nothing, unlike setCount(1..32), which draws a uniform count. limitCount(max = constant(64)) writes "limit": { "max": 64 }. A single Int isn't accepted, so limitCount(64) can't silently mean a lower bound: pass both bounds, or name the provider bound you set.
Enchantments
enchantRandomly
Adds a random enchantment:
An empty enchantment list leaves options out of the JSON: the game reads "options": [] as an empty candidate set and leaves the item unenchanted.
enchantWithLevels
Enchants as if using an enchanting table:
setEnchantments
Sets specific enchantments and levels:
A level is a plain number, a range drawn uniformly (this[Enchantments.SHARPNESS] = 1..3) or an int provider (this[Enchantments.SHARPNESS] = uniform(1, 3)). The plain number and range forms need import io.github.ayfri.kore.features.itemmodifiers.functions.set, otherwise the standard library set rejects them with a type mismatch.
enchantedCountIncrease
Increases count based on enchantment level (like Looting):
Names and Lore
setName
Sets the item's display name:
setLore
Sets or modifies item lore:
Components
setComponents
Directly set item components:
copyComponents
Copy components from a source:
copyName
Copy entity/block name to item:
setCustomData
Set custom NBT data on an item:
setCustomModelData
Set custom model data on an item:
Each float is a float provider or a plain number, so floats(0.5f, 1f) writes fixed floats and floats(...) can also read one from a score (fromInt turns the int score into a float) or add several sources with add:
Each color is a fixed Color, a decimal RGB number, or an int provider computing that value:
Each colors(...) call replaces the whole list. To mix fixed colors and providers in one list, set colors to a ListOperation of CustomModelDataColor.
copyCustomData
Copy NBT data to custom_data component:
Container Contents
setContents
Fill container items (bundles, shulker boxes):
setLootTable
Set a container's loot table:
The containerLoot item component sets the same loot table.
modifyContents
Apply modifiers to items inside a container. modifier { } takes inline functions, or an item modifier ID with reference(...):
The second one writes "modifier": "my_pack:my_modifier".
Maps and Exploration
explorationMap
Add map data leading to a structure to the item the modifier applies to. The loot entry or trade picks the item (vanilla uses minecraft:buried_treasure_map, minecraft:desert_village_map...). The destination is required: one or several structures or structure tags. The decoration is the map decoration type, the icon marking the destination.
A tag is written with its # ("destination": "#minecraft:on_treasure_maps") and several structures as a list:
When no structure is found the item has no map_id, so discard removes it. Vanilla chest loot does it with a filtered step:
Special Items
setInstrument
Set a goat horn instrument using a tag, a single ID, or multiple IDs/tags:
setItem
Change the item type:
setOminousBottleAmplifier
Set the amplifier of an ominous bottle:
setPotion
Set potion type:
setRandomPotion
Set a random potion from a list of options (or tags):
setRandomDyes
Set a random number of dyes on the item using an int provider:
setStewEffect
Set suspicious stew effects:
setFireworkExplosion
Set a single firework explosion:
setFireworks
Configure firework rocket:
setBookCover
Set written book cover. The title is plain text up to 32 characters, not a text component, pass WritablePage("Adventure Log", filtered = "...") to also give the version shown with chat filtering:
setWritableBookPages
Set pages of a writable book:
setWrittenBookPages
Set pages of a written book:
Attributes
setAttributes
Add attribute modifiers:
Banners and Patterns
setBannerPattern
Add banner patterns:
Block State
copyState
Copy block state to item:
Bonus Formulas
applyBonus
Apply enchantment-based bonus formulas:
Smelting and Decay
furnaceSmelt
Smelt the item as if in a furnace:
explosionDecay
Random chance to destroy items based on explosion:
Player Heads
fillPlayerHead
Set player head skin:
Tooltips
toggleTooltips
Show/hide tooltip sections:
Composition
sequence
Run multiple functions in sequence:
A sequence holding a single function writes it as an object, several ones as a list. sequence { } returns the function, so a condition guards the whole group:
discard
Replaces the produced item stack with an empty one:
filtered
Apply functions depending on whether the item matches a filter:
reference
Wherever the game expects item functions, it also accepts the ID of an item modifier file, or a #tag of item modifiers, written as a bare string. reference(id) builds it, and itemModifier(...) returns the ID to pass:
A file is one function object, so the combined and shortcut files are written as a sequence. A list can mix IDs and inline values, but a tag can't be one of its elements, only the whole functions value.
A reference has no condition of its own: wrap it in a sequence { } function to guard it. An item modifier that references itself, directly or through other files, makes the pack fail to load.
Conditions
Every function can have one condition that must pass:
The first function is written as:
A function can also point at a predicate file by ID: condition(isNight) writes "condition": "my_pack:is_night".
See Predicates for all available conditions.
Full Example
Generated JSON
Best Practices
- Keep modifiers focused - Create small, reusable modifiers and compose with
reference() - Use conditions wisely - Guard expensive operations with appropriate conditions
- Prefer components - Use
setComponentsfor direct component manipulation when possible - Consider context - Some functions require specific loot contexts (killer, tool, etc.)
- Test thoroughly - Verify modifiers work in all intended contexts (loot, commands, etc.)
See Also
- Predicates - Conditions for item functions
- Components - Understanding item components
- Loot Tables - Use item modifiers in loot tables
- Commands - Using the
/itemcommand - Villager Trades - Apply item modifiers to villager trade outputs via
givenItemModifier
External Resources
- Minecraft Wiki: Item modifier - Official JSON format reference
