Class BlockDropsEvent
java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.level.BlockEvent
net.neoforged.neoforge.event.level.BlockDropsEvent
- All Implemented Interfaces:
net.neoforged.bus.api.ICancellableEvent
Fired when a block is broken and the drops have been determined, but before they have been added to the world. This event can be used to manipulate the dropped items and experience.
No guarantees can be made about the block. It will either have already been removed from the world, or will be removed after the event terminates.
If you wish to edit the state of the block in-world, use BlockEvent.BreakEvent
.
-
Nested Class Summary
Nested classes/interfaces inherited from class net.neoforged.neoforge.event.level.BlockEvent
BlockEvent.BlockToolModificationEvent, BlockEvent.BreakEvent, BlockEvent.EntityMultiPlaceEvent, BlockEvent.EntityPlaceEvent, BlockEvent.FarmlandTrampleEvent, BlockEvent.FluidPlaceBlockEvent, BlockEvent.NeighborNotifyEvent, BlockEvent.PortalSpawnEvent
-
Field Summary
Modifier and TypeFieldDescriptionprivate final @Nullable BlockEntity
private final @Nullable Entity
private final List
<ItemEntity> private int
private final ItemStack
-
Constructor Summary
ConstructorDescriptionBlockDropsEvent
(ServerLevel level, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, List<ItemEntity> drops, @Nullable Entity breaker, ItemStack tool) Constructs a new BlockDropsEvent -
Method Summary
Modifier and TypeMethodDescription@Nullable BlockEntity
Returns the block entity from the current position, if available.@Nullable Entity
Returns the entity that broke the block, or null if unknown.int
Returns the amount of experience points that will be dropped by the block.getDrops()
Returns a mutable list of item entities that will be dropped by this block.getLevel()
getTool()
Returns the tool used when breaking this block; may be empty.void
setCanceled
(boolean canceled) Cancels this event, preventing any drops from being spawned and preventingBlockBehaviour.spawnAfterBreak(net.minecraft.world.level.block.state.BlockState, net.minecraft.server.level.ServerLevel, net.minecraft.core.BlockPos, net.minecraft.world.item.ItemStack, boolean)
from being called.void
setDroppedExperience
(int experience) Set the amount of experience points that will be dropped by the block.Methods inherited from class net.neoforged.neoforge.event.level.BlockEvent
getPos, getState
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.neoforged.bus.api.ICancellableEvent
isCanceled
-
Field Details
-
blockEntity
-
drops
-
breaker
-
tool
-
experience
private int experience
-
-
Constructor Details
-
BlockDropsEvent
public BlockDropsEvent(ServerLevel level, BlockPos pos, BlockState state, @Nullable @Nullable BlockEntity blockEntity, List<ItemEntity> drops, @Nullable @Nullable Entity breaker, ItemStack tool) Constructs a new BlockDropsEvent- Parameters:
level
- The level of the broken blockpos
- The position of the broken blockstate
- The state of the broken blockblockEntity
- The block entity of the broken block, if availabledrops
- The list of drops fromBlock.getDrops(net.minecraft.world.level.block.state.BlockState, net.minecraft.server.level.ServerLevel, net.minecraft.core.BlockPos, net.minecraft.world.level.block.entity.BlockEntity)
breaker
- The entity who broke the block, if anytool
- The tool used to break the block. May be empty
-
-
Method Details
-
getDrops
Returns a mutable list of item entities that will be dropped by this block.When this event completes successfully, all entities in this list will be added to the world.
- Returns:
- A mutable list of item entities.
-
getBlockEntity
Returns the block entity from the current position, if available.- Returns:
- the block entity from the current position, if available
-
getBreaker
Returns the entity that broke the block, or null if unknown.- Returns:
- the entity that broke the block, or null if unknown
-
getTool
Returns the tool used when breaking this block; may be empty.- Returns:
- the tool used when breaking this block; may be empty
-
setCanceled
public void setCanceled(boolean canceled) Cancels this event, preventing any drops from being spawned and preventingBlockBehaviour.spawnAfterBreak(net.minecraft.world.level.block.state.BlockState, net.minecraft.server.level.ServerLevel, net.minecraft.core.BlockPos, net.minecraft.world.item.ItemStack, boolean)
from being called.Also prevents experience from being spawned.
- Specified by:
setCanceled
in interfacenet.neoforged.bus.api.ICancellableEvent
-
getLevel
- Overrides:
getLevel
in classBlockEvent
-
getDroppedExperience
public int getDroppedExperience()Returns the amount of experience points that will be dropped by the block.- Returns:
- the amount of experience points that will be dropped by the block
-
setDroppedExperience
public void setDroppedExperience(int experience) Set the amount of experience points that will be dropped by the block. This is the true value, after enchantments have been applied.- Parameters:
experience
- The new amount. Must not be negative.
-