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 Link icon

    • blockEntity Link icon

      @Nullable private final @Nullable BlockEntity blockEntity
    • drops Link icon

      private final List<ItemEntity> drops
    • breaker Link icon

      @Nullable private final @Nullable Entity breaker
    • tool Link icon

      private final ItemStack tool
    • experience Link icon

      private int experience
  • Constructor Details Link icon

  • Method Details Link icon

    • getDrops Link icon

      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 Link icon

      @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 Link icon

      @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 Link icon

      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 Link icon

      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 Link icon

      public ServerLevel getLevel()
      Overrides:
      getLevel in class BlockEvent
    • getDroppedExperience Link icon

      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 Link icon

      public void setDroppedExperience(int experience)
      Set the amount of experience points that will be dropped by the block
      Parameters:
      experience - The new amount. Must not be negative.