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.

  • Nested Class Summary

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final @Nullable net.minecraft.world.level.block.entity.BlockEntity
     
    private final @Nullable net.minecraft.world.entity.Entity
     
    private final List<net.minecraft.world.entity.item.ItemEntity>
     
    private int
     
    private final net.minecraft.world.item.ItemStack
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    BlockDropsEvent(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, @Nullable net.minecraft.world.level.block.entity.BlockEntity blockEntity, List<net.minecraft.world.entity.item.ItemEntity> drops, @Nullable net.minecraft.world.entity.Entity breaker, net.minecraft.world.item.ItemStack tool)
    Constructs a new BlockDropsEvent
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable net.minecraft.world.level.block.entity.BlockEntity
    Returns the block entity from the current position, if available.
    @Nullable net.minecraft.world.entity.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.
    List<net.minecraft.world.entity.item.ItemEntity>
    Returns a mutable list of item entities that will be dropped by this block.
    net.minecraft.server.level.ServerLevel
     
    net.minecraft.world.item.ItemStack
    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 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.
    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

      @Nullable private final @Nullable net.minecraft.world.level.block.entity.BlockEntity blockEntity
    • drops

      private final List<net.minecraft.world.entity.item.ItemEntity> drops
    • breaker

      @Nullable private final @Nullable net.minecraft.world.entity.Entity breaker
    • tool

      private final net.minecraft.world.item.ItemStack tool
    • experience

      private int experience
  • Constructor Details

    • BlockDropsEvent

      public BlockDropsEvent(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, @Nullable @Nullable net.minecraft.world.level.block.entity.BlockEntity blockEntity, List<net.minecraft.world.entity.item.ItemEntity> drops, @Nullable @Nullable net.minecraft.world.entity.Entity breaker, net.minecraft.world.item.ItemStack tool)
      Constructs a new BlockDropsEvent
      Parameters:
      level - The level of the broken block
      pos - The position of the broken block
      state - The state of the broken block
      blockEntity - The block entity of the broken block, if available
      drops - The list of drops from Block.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 any
      tool - The tool used to break the block. May be empty
  • Method Details

    • getDrops

      public List<net.minecraft.world.entity.item.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 net.minecraft.world.level.block.entity.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 net.minecraft.world.entity.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 net.minecraft.world.item.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 net.minecraft.server.level.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.