Class BlockBreakLootHandler

java.lang.Object
io.artificial.enchantments.internal.loot.BlockBreakLootHandler

public final class BlockBreakLootHandler extends Object
Handles block-break loot modification for enchanted tools.

This class processes loot modifications when a player breaks a block with a tool containing enchantments that have registered loot modifiers. It extracts vanilla drops, creates a LootContext, and invokes all registered modifiers in sequence.

Processing Order:

  1. Extract enchantments from the tool
  2. Get vanilla drops from the block
  3. Create LootContext with drops, tool, block, player
  4. For each enchantment with modifiers, invoke modifiers
  5. Apply modified drops back to the event

Explicit Ownership: Only enchantments with registered loot modifiers are processed. Non-targeted loot (vanilla drops, unenchanted tools) remains untouched.

Since:
0.4.0
  • Constructor Details

    • BlockBreakLootHandler

      public BlockBreakLootHandler(@NotNull @NotNull LootModifierRegistry modifierRegistry, @NotNull @NotNull ItemEnchantmentService enchantmentService)
      Creates a new handler with the required dependencies.
      Parameters:
      modifierRegistry - the registry for loot modifiers
      enchantmentService - the service for reading enchantments from items
  • Method Details

    • processBlockBreak

      @NotNull public @NotNull List<org.bukkit.inventory.ItemStack> processBlockBreak(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull org.bukkit.inventory.ItemStack tool, @NotNull @NotNull org.bukkit.block.Block block, @NotNull @NotNull List<org.bukkit.inventory.ItemStack> vanillaDrops, int expToDrop)
      Processes loot modifications for a block break event.

      This is the main entry point called when a block is broken. It handles the entire modification pipeline from extracting enchantments to applying modified drops.

      Parameters:
      player - the player breaking the block
      tool - the tool being used
      block - the block being broken
      vanillaDrops - the vanilla drops that would normally spawn
      expToDrop - the experience points to drop
      Returns:
      the modified drops list, or original if no modifications applied
    • getLastExpToDrop

      public int getLastExpToDrop()
      Gets the last processed exp to drop value.
      Returns:
      the XP amount from the last processing