Class BreakBlockEvent

java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.level.BlockEvent
net.neoforged.neoforge.event.level.block.BreakBlockEvent
All Implemented Interfaces:
net.neoforged.bus.api.ICancellableEvent

public class BreakBlockEvent extends BlockEvent implements net.neoforged.bus.api.ICancellableEvent
This event is fired when a player attempts to break a block, on both the client and server. The following conditions may cause this event to fire in a cancelled state: In the first two cases, un-cancelling the event will not permit the block to be broken. In the third case, un-cancelling will allow the break, bypassing the behavior of
invalid reference
Item#canAttackBlock
.
  • Field Details

    • player

      private final Player player
    • notifyClient

      private boolean notifyClient
  • Constructor Details

  • Method Details

    • getPlayer

      public Player getPlayer()
      Returns the player who is attempting to break the block.
      Returns:
      the player who is attempting to break the block
    • setCanceled

      public void setCanceled(boolean canceled)
      Canceling this event will prevent the block from being broken.

      When canceled on the server, If shouldNotifyClient(), the client will receive a ClientboundBlockUpdatePacket.

      Specified by:
      setCanceled in interface net.neoforged.bus.api.ICancellableEvent
    • shouldNotifyClient

      public boolean shouldNotifyClient()
      Whether or not the client should receive a ClientboundBlockUpdatePacket when this event is canceled on the server.
    • setNotifyClient

      public void setNotifyClient(boolean notify)
      Used to enable (or disable) notifying the client.

      This should be set when canceling the event only on the server, without a matching client-side event handler.

      However, in general, prefer to run your event handler on both sides, rather than relying on the notifying path.