Interface LootModifier
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Loot modifiers are explicitly registered per-enchantment via
LootModifierRegistry. Only enchantments with registered modifiers
can affect drops - this ensures clear ownership and prevents implicit
modification of non-targeted loot sources.
Usage Example:
// Define a modifier that doubles drops
LootModifier fortuneModifier = context -> {
int level = context.getLevel();
List<ItemStack> drops = context.getDrops();
// Modify quantities
for (ItemStack drop : drops) {
drop.setAmount(drop.getAmount() * (1 + level));
}
};
// Register for your enchantment
LootModifierRegistry registry = api.getLootModifierRegistry();
registry.register(myEnchantment, fortuneModifier);
Extension Points:
This system is designed for extension to other loot sources:
- Entity death loot (entity loot modifiers)
- Fishing rewards (fishing loot modifiers)
- Container loot (chest/barrel modifiers)
- Block interaction loot (non-break sources)
Ownership Model:
- Plugins decide which enchantments affect which loot sources
- No automatic modification without explicit opt-in
- Non-targeted loot remains untouched
- Multiple modifiers can stack on same enchantment
- Since:
- 0.4.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidmodify(@NotNull LootContext context) Modifies the loot drops based on the context.
-
Method Details
-
modify
Modifies the loot drops based on the context.This method is called when a block is broken by a tool with an enchantment that has registered loot modifiers. The context provides access to:
- The tool item with the enchantment
- The block being broken
- The player breaking the block
- The modifiable drops list
- The enchantment level
The drops list is directly modifiable - you can:
- Add new items with
LootContext.addDrop(ItemStack) - Remove items with
LootContext.removeDrop(ItemStack) - Modify quantities of existing items
- Replace the entire drops list with
LootContext.setDrops(List)
Important: This method should not perform heavy operations. Keep modifications lightweight and synchronous. If you need to do expensive work, schedule it via the scheduler.
- Parameters:
context- the loot context containing all relevant data and the modifiable drops list- Since:
- 0.4.0
-