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 predicate conditions
  • 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:

data/<namespace>/item_modifier/<name>.json
Null

For complete JSON specification, see the Minecraft Wiki - Item modifier.

Creating Item Modifiers

Use the itemModifier builder function to create item modifiers in Kore:

dataPack("my_datapack") {
	val modifier = itemModifier("fortune_bonus") {
		enchantRandomly {
			options += Enchantments.FORTUNE
		}
		setCount(uniform(1f, 5f))
	}
}
Kotlin

This generates data/my_datapack/item_modifier/fortune_bonus.json.

Using Item Modifiers

With Commands

Apply modifiers to items using the /item modify command:

load {
	items {
		// Modify item in player's mainhand
		modify(self(), WEAPON.MAINHAND, modifier)

		// Modify item in container
		modify(block(0, 64, 0), slot(0), modifier)
	}
}
Kotlin

In Loot Tables

Use functions directly in loot tables at table, pool, or entry level:

lootTable("treasure") {
	// Table-level functions (applied to all drops)
	functions {
		enchantRandomly()
	}

	pool {
		// Pool-level functions
		functions {
			setCount(uniform(1f, 3f))
		}

		entries {
			item(Items.DIAMOND) {
				// Entry-level functions
				functions {
					setName("Lucky Diamond")
				}
			}
		}
	}
}
Kotlin

Function Reference

Count and Damage

setCount

Sets or modifies the stack count:

itemModifier("set_count") {
	// Exact count
	setCount(5f)

	// Random range
	setCount(uniform(1f, 10f))

	// Add to current count
	setCount(5f, add = true)

	// With condition
	setCount(10f) {
		conditions {
			killedByPlayer()
		}
	}
}
Kotlin

setDamage

Sets item durability (1.0 = full, 0.0 = broken):

itemModifier("damage") {
	// Set to 80% durability
	setDamage(0.8f)

	// Random damage
	setDamage(uniform(0.5f, 1.0f))

	// Add to current damage
	setDamage(-0.1f, add = true)  // Repair 10%
}
Kotlin

limitCount

Clamps stack count to a range:

itemModifier("limit") {
	// Exact limit
	limitCount(64)

	// Range
	limitCount(providersRange(min = constant(1f), max = constant(32f)))
}
Kotlin

Enchantments

enchantRandomly

Adds a random enchantment:

itemModifier("random_enchant") {
	// Any enchantment
	enchantRandomly()

	// From specific list
	enchantRandomly {
		options += Enchantments.SHARPNESS
		options += Enchantments.SMITE
		options += Enchantments.BANE_OF_ARTHROPODS
	}

	// Only compatible enchantments
	enchantRandomly(onlyCompatible = true)
}
Kotlin

enchantWithLevels

Enchants as if using an enchanting table:

itemModifier("table_enchant") {
	// Fixed level
	enchantWithLevels(levels = constant(30f))

	// Random level range
	enchantWithLevels(levels = uniform(20f, 39f))

	// Limit to specific enchantments
	enchantWithLevels(Enchantments.PROTECTION, levels = constant(30f))
}
Kotlin

setEnchantments

Sets specific enchantments and levels:

itemModifier("specific_enchants") {
	setEnchantments {
		enchantment(Enchantments.SHARPNESS, 5)
		enchantment(Enchantments.UNBREAKING, 3)
		enchantment(Enchantments.MENDING, 1)
	}
}
Kotlin

enchantedCountIncrease

Increases count based on enchantment level (like Looting):

itemModifier("looting_bonus") {
	enchantedCountIncrease(Enchantments.LOOTING, count = 1f, limit = 5)
}
Kotlin

Names and Lore

setName

Sets the item's display name:

itemModifier("named") {
	// Simple string
	setName("Legendary Sword")

	// Text component with formatting
	setName(textComponent("Legendary Sword") {
		color = Color.GOLD
		bold = true
	})

	// Set item name vs custom name
	setName("Base Name") {
		target = SetNameTarget.ITEM_NAME  // or CUSTOM_NAME
	}
}
Kotlin

setLore

Sets or modifies item lore:

itemModifier("lore") {
	setLore {
		lore("First line", Color.GRAY)
		lore("Second line", Color.DARK_GRAY)

		// Insert at specific position
		mode(Mode.INSERT, offset = 0)
	}
}
Kotlin

Components

setComponents

Directly set item components:

itemModifier("components") {
	setComponents {
		customName(textComponent("Custom Item", Color.GOLD))
		damage(10)
		unbreakable(showInTooltip = false)

		// Remove component with !
		!food {}
	}
}
Kotlin

copyComponents

Copy components from a source:

itemModifier("copy_from_block") {
	copyComponents {
		source = Source.BLOCK_ENTITY

		// Include specific components
		include(ItemComponentTypes.CUSTOM_NAME, ItemComponentTypes.LORE)

		// Or exclude specific components
		exclude(ItemComponentTypes.DAMAGE)
	}
}
Kotlin

copyName

Copy entity/block name to item:

itemModifier("named_drop") {
	copyName(Source.BLOCK_ENTITY)
	// Or from entity
	copyName(Source.THIS)
	copyName(Source.KILLER)
}
Kotlin

copyCustomData

Copy NBT data to custom_data component:

itemModifier("copy_nbt") {
	copyCustomData {
		source(Source.BLOCK_ENTITY)

		operations {
			operation("Items", "BlockItems", CopyOperation.REPLACE)
			operation("Lock", "OriginalLock", CopyOperation.MERGE)
		}
	}
}
Kotlin

Container Contents

setContents

Fill container items (bundles, shulker boxes):

itemModifier("filled_bundle") {
	setContents(ContentComponentTypes.BUNDLE_CONTENTS) {
		entries {
			item(Items.DIAMOND) {
				functions {
					setCount(16f)
				}
			}
			item(Items.EMERALD) {
				functions {
					setCount(32f)
				}
			}
		}
	}
}
Kotlin

setLootTable

Set a container's loot table:

itemModifier("chest_loot") {
	setLootTable(
		LootTableType.CHEST,
		LootTables.Chests.SIMPLE_DUNGEON,
		seed = 12345L
	)
}
Kotlin

modifyContents

Apply modifiers to items inside a container:

itemModifier("enchant_bundle_contents") {
	modifyContents(ContentComponentTypes.BUNDLE_CONTENTS) {
		modifiers {
			enchantRandomly()
		}
	}
}
Kotlin

Maps and Exploration

explorationMap

Convert empty map to explorer map:

itemModifier("treasure_map") {
	explorationMap {
		destination = Tags.Worldgen.Structure.BURIED_TREASURE
		decoration = MapDecorationTypes.RED_X
		zoom = 2
		searchRadius = 50
		skipExistingChunks = true
	}
}
Kotlin

Special Items

setInstrument

Set goat horn instrument:

itemModifier("horn") {
	setInstrument(Tags.Instrument.GOAT_HORNS)
}
Kotlin

setPotion

Set potion type:

itemModifier("potion") {
	setPotion(Potions.STRONG_HEALING)
}
Kotlin

setStewEffect

Set suspicious stew effects:

itemModifier("stew") {
	setStewEffect {
		potionEffect(Effects.REGENERATION, duration = 100)
		potionEffect(Effects.SATURATION, duration = 200)
	}
}
Kotlin

setFireworks

Configure firework rocket:

itemModifier("firework") {
	setFireworks(flightDuration = 2) {
		explosions {
			explosion(FireworkExplosionShape.LARGE_BALL) {
				colors(Color.RED, Color.ORANGE)
				fadeColors(Color.YELLOW)
				hasTrail = true
				hasTwinkle = true
			}
		}
	}
}
Kotlin

setBookCover

Set written book cover:

itemModifier("book") {
	setBookCover(
		title = "Adventure Log",
		author = "Player",
		generation = 0
	)
}
Kotlin

Attributes

setAttributes

Add attribute modifiers:

itemModifier("buffed") {
	setAttributes {
		attribute(
			attribute = Attributes.ATTACK_DAMAGE,
			operation = AttributeModifierOperation.ADD_VALUE,
			amount = constant(5f),
			id = "bonus_damage",
			slot = EquipmentSlot.MAINHAND
		)
		attribute(
			attribute = Attributes.MOVEMENT_SPEED,
			operation = AttributeModifierOperation.ADD_MULTIPLIED_BASE,
			amount = constant(0.1f),
			id = "speed_boost",
			slot = EquipmentSlot.FEET
		)
	}
}
Kotlin

Banners and Patterns

setBannerPattern

Add banner patterns:

itemModifier("banner") {
	setBannerPattern(append = true) {
		pattern(BannerPatterns.STRIPE_TOP, DyeColors.RED)
		pattern(BannerPatterns.STRIPE_BOTTOM, DyeColors.BLUE)
	}
}
Kotlin

Block State

copyState

Copy block state to item:

itemModifier("block_state") {
	copyState(Blocks.FURNACE) {
		properties("facing", "lit")
	}
}
Kotlin

Bonus Formulas

applyBonus

Apply enchantment-based bonus formulas:

itemModifier("fortune") {
	// Ore drops formula
	applyBonus(Enchantments.FORTUNE) {
		formula = OreDrops()
	}

	// Uniform bonus
	applyBonus(Enchantments.FORTUNE) {
		formula = UniformBonusCount(bonusMultiplier = 1f)
	}

	// Binomial distribution
	applyBonus(Enchantments.FORTUNE) {
		formula = BinomialWithBonusCount(extra = 3, probability = 0.5f)
	}
}
Kotlin

Smelting and Decay

furnaceSmelt

Smelt the item as if in a furnace:

itemModifier("auto_smelt") {
	furnaceSmelt()
}
Kotlin

explosionDecay

Random chance to destroy items based on explosion:

itemModifier("explosion") {
	explosionDecay()
}
Kotlin

Player Heads

fillPlayerHead

Set player head skin:

itemModifier("head") {
	fillPlayerHead(Source.KILLER)
}
Kotlin

Tooltips

toggleTooltips

Show/hide tooltip sections:

itemModifier("clean_tooltip") {
	toggleTooltips {
		enchantments = false
		modifiers = false
		canBreak = false
		canPlaceOn = false
	}
}
Kotlin

Composition

sequence

Run multiple functions in sequence:

itemModifier("complex") {
	sequence {
		setCount(1f)
		enchantRandomly()
		setName("Mystery Item")
	}
}
Kotlin

filtered

Apply functions only to matching items:

itemModifier("filter") {
	filtered {
		itemFilter(Items.DIAMOND, Items.EMERALD)

		modifiers {
			setCount(uniform(1f, 5f))
		}
	}
}
Kotlin

reference

Reference another item modifier:

val baseModifier = itemModifier("base") {
	setCount(1f)
}

itemModifier("extended") {
	reference(baseModifier)
	enchantRandomly()
}
Kotlin

Conditions

Every function can have conditions that must pass:

itemModifier("conditional") {
	setCount(10f) {
		conditions {
			// Multiple conditions are AND-ed
			killedByPlayer()
			randomChance(0.5f)
		}
	}

	enchantRandomly {
		conditions {
			weatherCheck(raining = true)
		}
	}
}
Kotlin

See Predicates for all available conditions.

Full Example

dataPack("legendary_items") {
	val legendaryModifier = itemModifier("legendary_weapon") {
		// High-level enchantments
		enchantWithLevels(levels = constant(30f)) {
			conditions {
				randomChance(0.3f)
			}
		}

		// Guaranteed enchantments
		setEnchantments {
			enchantment(Enchantments.UNBREAKING, 3)
		}

		// Custom name with formatting
		setName(textComponent("Legendary Weapon") {
			color = Color.GOLD
			bold = true
		})

		// Lore
		setLore {
			lore("Forged in ancient flames", Color.GRAY)
			lore("", Color.WHITE)
			lore("▸ +5 Attack Damage", Color.GREEN)
			mode(Mode.REPLACE_ALL)
		}

		// Attributes
		setAttributes(replace = false) {
			attribute(
				attribute = Attributes.ATTACK_DAMAGE,
				operation = AttributeModifierOperation.ADD_VALUE,
				amount = constant(5f),
				id = "legendary_damage",
				slot = EquipmentSlot.MAINHAND
			)
		}

		// Full durability
		setDamage(1.0f)
	}

	// Use in loot table
	lootTable("boss_weapon") {
		pool {
			rolls = constant(1f)

			entries {
				item(Items.DIAMOND_SWORD) {
					functions {
						reference(legendaryModifier)
					}
				}
			}
		}
	}

	// Use with command
	load {
		items {
			modify(self(), WEAPON.MAINHAND, legendaryModifier)
		}
	}
}
Kotlin

Generated JSON

[
	{
		"function": "minecraft:enchant_with_levels",
		"levels": 30.0,
		"conditions": [
			{
				"condition": "minecraft:random_chance",
				"chance": 0.3
			}
		]
	},
	{
		"function": "minecraft:set_enchantments",
		"enchantments": {
			"minecraft:unbreaking": 3
		}
	},
	{
		"function": "minecraft:set_name",
		"name": {
			"text": "Legendary Weapon",
			"color": "gold",
			"bold": true
		}
	},
	{
		"function": "minecraft:set_lore",
		"lore": [
			{
				"text": "Forged in ancient flames",
				"color": "gray"
			},
			{
				"text": ""
			},
			{
				"text": "▸ +5 Attack Damage",
				"color": "green"
			}
		],
		"mode": "replace_all"
	},
	{
		"function": "minecraft:set_attributes",
		"modifiers": [
			{
				"attribute": "minecraft:attack_damage",
				"id": "minecraft:legendary_damage",
				"amount": 5.0,
				"operation": "add_value",
				"slot": "mainhand"
			}
		],
		"replace": false
	},
	{
		"function": "minecraft:set_damage",
		"damage": 1.0
	}
]
JSON

Best Practices

  1. Keep modifiers focused - Create small, reusable modifiers and compose with reference()
  2. Use conditions wisely - Guard expensive operations with appropriate conditions
  3. Prefer components - Use setComponents for direct component manipulation when possible
  4. Consider context - Some functions require specific loot contexts (killer, tool, etc.)
  5. Test thoroughly - Verify modifiers work in all intended contexts (loot, commands, etc.)

See Also

External Resources