Class EnchantedBlockLootEvent
java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.level.BlockEvent
net.neoforged.neoforge.event.enchanting.EnchantedBlockLootEvent
Fired on the server when a block's loot table queries the level of an enchantment to determine what the block will drop.
Notably, this fires when ApplyBonusCount or BonusLevelTableCondition check the level of an enchantment in-context.
Mods that implement similar loot conditions or functions should fire this event as well.
If you do not need the additional context of this event, prefer GetEnchantmentLevelEvent for managing enchantment levels.
-
Nested Class Summary
Nested classes/interfaces inherited from class BlockEvent
BlockEvent.BlockToolModificationEvent, BlockEvent.EntityMultiPlaceEvent, BlockEvent.EntityPlaceEvent, BlockEvent.FarmlandTrampleEvent, BlockEvent.FluidPlaceBlockEvent, BlockEvent.NeighborNotifyEvent, BlockEvent.PortalSpawnEvent -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Holder<Enchantment> private intprivate final ItemInstance -
Constructor Summary
ConstructorsConstructorDescriptionEnchantedBlockLootEvent(ServerLevel level, BlockPos pos, BlockState state, ItemInstance tool, Holder<Enchantment> enchantment, int enchantmentLevel, @Nullable Entity entity) -
Method Summary
Modifier and TypeMethodDescriptionintGets the entity that broke the block fromLootContextParams.THIS_ENTITY.getTool()Returns the tool used to break the block, fromLootContextParams.TOOL.voidsetEnchantmentLevel(int enchantmentLevel) Sets the new enchantment level.Methods inherited from class BlockEvent
getLevel, getPos, getState
-
Field Details
-
tool
-
enchantment
-
enchantmentLevel
private int enchantmentLevel -
entity
-
-
Constructor Details
-
EnchantedBlockLootEvent
@Internal public EnchantedBlockLootEvent(ServerLevel level, BlockPos pos, BlockState state, ItemInstance tool, Holder<Enchantment> enchantment, int enchantmentLevel, @Nullable Entity entity)
-
-
Method Details
-
getTool
Returns the tool used to break the block, fromLootContextParams.TOOL.- Returns:
- the tool used to break the block, from
LootContextParams.TOOL
-
getEnchantment
-
getEnchantmentLevel
public int getEnchantmentLevel() -
setEnchantmentLevel
public void setEnchantmentLevel(int enchantmentLevel) Sets the new enchantment level.- Throws:
IllegalArgumentException- if the enchantment level is negative.
-
getEntity
Gets the entity that broke the block from
LootContextParams.THIS_ENTITY.- Might be the player when blocks are mined using tools.
- For explosions will be the direct cause such as TNT.
- Might be null if the block was broken without an entity, such as neighbor change.
- Returns:
- the entity that broke the block.
-