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

public class BlockDropsEvent extends BlockEvent implements 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.

  • Field Details

    • blockEntity

      @Nullable private final @Nullable BlockEntity blockEntity
    • drops

      private final List<ItemEntity> drops
    • breaker

      @Nullable private final @Nullable Entity breaker
    • tool

      private final ItemStack tool
    • experience

      private int experience
  • Constructor Details

  • Method Details

    • getDrops

      public List<ItemEntity> 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

      @Nullable public @Nullable BlockEntity getBlockEntity()
      Returns the block entity from the current position, if available.
      Returns:
      the block entity from the current position, if available
    • getBreaker

      @Nullable public @Nullable Entity getBreaker()
      Returns the entity that broke the block, or null if unknown.
      Returns:
      the entity that broke the block, or null if unknown
    • getTool

      public ItemStack 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 preventing BlockBehaviour.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 interface net.neoforged.bus.api.ICancellableEvent
    • getLevel

      public ServerLevel getLevel()
      Overrides:
      getLevel in class BlockEvent
    • 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.