类 BlockDropsEvent

java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.level.BlockEvent
net.neoforged.neoforge.event.level.BlockDropsEvent
所有已实现的接口:
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.

  • 字段详细资料

    • 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
  • 构造器详细资料

  • 方法详细资料

    • 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.

      返回:
      A mutable list of item entities.
      API Note:
      Prefer using LootModifiers to add additional loot drops.
    • getBlockEntity

      @Nullable public @Nullable BlockEntity getBlockEntity()
      返回 the block entity from the current position, if available。
      返回:
      the block entity from the current position, if available
    • getBreaker

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

      public ItemStack getTool()
      返回 the tool used when breaking this block; may be empty。
      返回:
      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.

      指定者:
      setCanceled 在接口中 net.neoforged.bus.api.ICancellableEvent
    • getLevel

      public ServerLevel getLevel()
      覆盖:
      getLevel 在类中 BlockEvent
    • getDroppedExperience

      public int getDroppedExperience()
      返回 the amount of experience points that will be dropped by the block。
      返回:
      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.
      参数:
      experience - The new amount. Must not be negative.
      API Note:
      When cancelled, no experience is dropped, regardless of this value.