Interface LootModifierRegistry

All Known Implementing Classes:
LootModifierRegistryImpl

public interface LootModifierRegistry
Registry for managing loot modifiers per-enchantment.

This registry provides explicit registration of LootModifier instances for specific enchantments. Only enchantments with registered modifiers can affect loot drops - this ensures clear ownership boundaries and prevents implicit modification of non-targeted loot sources.

Explicit Ownership Model:

  • Plugins decide which enchantments affect which loot sources
  • No automatic modification without explicit opt-in registration
  • Non-targeted loot remains untouched unless explicitly opted in
  • Multiple modifiers can be registered for the same enchantment
  • Registration is idempotent (duplicate modifiers are ignored)

Usage Example:


 // Get the registry from the API
 ArtificialEnchantmentsAPI api = ArtificialEnchantmentsAPI.getInstance();
 LootModifierRegistry registry = api.getLootModifierRegistry();

 // Create a modifier
 LootModifier fortuneLike = context -> {
     int bonus = context.getLevel() * 0.5; // 50% bonus per level
     for (ItemStack drop : context.getDrops()) {
         drop.setAmount(drop.getAmount() + bonus);
     }
 };

 // Register for your enchantment
 registry.register(myEnchantment, fortuneLike);

 // Check if enchantment has modifiers
 if (registry.hasModifier(myEnchantment)) {
     List<LootModifier> modifiers = registry.getModifiers(myEnchantment);
 }

 // Unregister when needed
 registry.unregister(myEnchantment, fortuneLike);
 

Extension Points:
This registry manages block-break loot modifiers. Future extensions can add:

  • EntityLootModifierRegistry - for entity death drops
  • FishingLootModifierRegistry - for fishing rewards
  • ContainerLootModifierRegistry - for container loot
Each follows the same pattern of explicit registration and clear ownership.
Since:
0.4.0
See Also:
  • Method Details

    • register

      void register(@NotNull @NotNull EnchantmentDefinition enchantment, @NotNull @NotNull LootModifier modifier)
      Registers a loot modifier for an enchantment.

      The modifier will be invoked whenever a player breaks a block with a tool containing this enchantment. Multiple modifiers can be registered for the same enchantment - they will all be invoked in registration order.

      Registration is idempotent - registering the same modifier twice for the same enchantment has no effect.

      Parameters:
      enchantment - the enchantment to register the modifier for
      modifier - the modifier to register
      Throws:
      IllegalArgumentException - if enchantment or modifier is null
      Since:
      0.4.0
    • unregister

      boolean unregister(@NotNull @NotNull EnchantmentDefinition enchantment, @NotNull @NotNull LootModifier modifier)
      Unregisters a specific loot modifier from an enchantment.

      Removes a previously registered modifier. If the modifier was not registered for this enchantment, this method does nothing.

      Parameters:
      enchantment - the enchantment to remove the modifier from
      modifier - the modifier to unregister
      Returns:
      true if the modifier was found and removed, false otherwise
      Throws:
      IllegalArgumentException - if enchantment or modifier is null
      Since:
      0.4.0
    • unregisterAll

      boolean unregisterAll(@NotNull @NotNull EnchantmentDefinition enchantment)
      Unregisters all loot modifiers for an enchantment.

      Removes all modifiers for the specified enchantment. After this call, hasModifier(EnchantmentDefinition) will return false.

      Parameters:
      enchantment - the enchantment to clear modifiers for
      Returns:
      true if any modifiers were removed, false if none existed
      Throws:
      IllegalArgumentException - if enchantment is null
      Since:
      0.4.0
    • getModifiers

      @NotNull @NotNull List<LootModifier> getModifiers(@NotNull @NotNull EnchantmentDefinition enchantment)
      Gets all loot modifiers registered for an enchantment.

      Returns the list of modifiers in registration order. The returned list is unmodifiable - use register(io.artificial.enchantments.api.EnchantmentDefinition, io.artificial.enchantments.api.loot.LootModifier) and unregister(io.artificial.enchantments.api.EnchantmentDefinition, io.artificial.enchantments.api.loot.LootModifier) to modify registrations.

      Parameters:
      enchantment - the enchantment to get modifiers for
      Returns:
      list of registered modifiers (may be empty, never null)
      Throws:
      IllegalArgumentException - if enchantment is null
      Since:
      0.4.0
    • hasModifier

      boolean hasModifier(@NotNull @NotNull EnchantmentDefinition enchantment)
      Checks if an enchantment has any registered loot modifiers.

      This is the primary API for checking if an enchantment affects loot drops. Use this before processing loot modifications.

      Parameters:
      enchantment - the enchantment to check
      Returns:
      true if at least one modifier is registered
      Throws:
      IllegalArgumentException - if enchantment is null
      Since:
      0.4.0
    • getModifierCount

      int getModifierCount(@NotNull @NotNull EnchantmentDefinition enchantment)
      Gets the number of modifiers registered for an enchantment.
      Parameters:
      enchantment - the enchantment to check
      Returns:
      the number of registered modifiers (0 if none)
      Throws:
      IllegalArgumentException - if enchantment is null
      Since:
      0.4.0
    • clear

      void clear()
      Clears all registrations from this registry.

      Warning: This removes ALL loot modifier registrations from ALL enchantments. This is primarily for cleanup during shutdown.

      Since:
      0.4.0
    • isRegistered

      boolean isRegistered(@NotNull @NotNull EnchantmentDefinition enchantment, @NotNull @NotNull LootModifier modifier)
      Checks if a specific modifier is registered for an enchantment.
      Parameters:
      enchantment - the enchantment to check
      modifier - the modifier to look for
      Returns:
      true if the modifier is registered for this enchantment
      Throws:
      IllegalArgumentException - if enchantment or modifier is null
      Since:
      0.4.0