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.

@FunctionalInterface public interface LootModifier
Functional interface for modifying loot drops from enchanted items.

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)
Future extensions should follow the same pattern: explicit registration, clear ownership, modifiable context.

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 Type
    Method
    Description
    void
    modify(@NotNull LootContext context)
    Modifies the loot drops based on the context.
  • Method Details

    • modify

      void modify(@NotNull @NotNull LootContext context)
      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:

      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