Class BlockBreakLootHandler
java.lang.Object
io.artificial.enchantments.internal.loot.BlockBreakLootHandler
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:
- Extract enchantments from the tool
- Get vanilla drops from the block
- Create LootContext with drops, tool, block, player
- For each enchantment with modifiers, invoke modifiers
- 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 Summary
ConstructorsConstructorDescriptionBlockBreakLootHandler(@NotNull LootModifierRegistry modifierRegistry, @NotNull ItemEnchantmentService enchantmentService) Creates a new handler with the required dependencies. -
Method Summary
Modifier and TypeMethodDescriptionintGets the last processed exp to drop value.@NotNull List<org.bukkit.inventory.ItemStack> processBlockBreak(@NotNull org.bukkit.entity.Player player, @NotNull org.bukkit.inventory.ItemStack tool, @NotNull org.bukkit.block.Block block, @NotNull List<org.bukkit.inventory.ItemStack> vanillaDrops, int expToDrop) Processes loot modifications for a block break event.
-
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 modifiersenchantmentService- 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 blocktool- the tool being usedblock- the block being brokenvanillaDrops- the vanilla drops that would normally spawnexpToDrop- 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
-