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
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:
.
- If
Player.blockActionRestricted(Level, BlockPos, GameType)is true. - If the target block is a
GameMasterBlockandPlayer.canUseGameMasterBlocks()is false. - If the the player is holding an item, and
is false.
invalid reference
Item#canAttackBlock
invalid reference
Item#canAttackBlock
-
Nested Class Summary
Nested classes/interfaces inherited from class BlockEvent
BlockEvent.BlockToolModificationEvent, BlockEvent.EntityMultiPlaceEvent, BlockEvent.EntityPlaceEvent, BlockEvent.FarmlandTrampleEvent, BlockEvent.FluidPlaceBlockEvent, BlockEvent.NeighborNotifyEvent, BlockEvent.PortalSpawnEvent -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the player who is attempting to break the block.voidsetCanceled(boolean canceled) Canceling this event will prevent the block from being broken.voidsetNotifyClient(boolean notify) Used to enable (or disable) notifying the client.booleanWhether or not the client should receive aClientboundBlockUpdatePacketwhen this event is canceled on the server.Methods inherited from class BlockEvent
getLevel, getPos, getStateMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.neoforged.bus.api.ICancellableEvent
isCanceled
-
Field Details
-
player
-
notifyClient
private boolean notifyClient
-
-
Constructor Details
-
BreakBlockEvent
-
-
Method Details
-
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 aClientboundBlockUpdatePacket.- Specified by:
setCanceledin interfacenet.neoforged.bus.api.ICancellableEvent
-
shouldNotifyClient
public boolean shouldNotifyClient()Whether or not the client should receive aClientboundBlockUpdatePacketwhen 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.
-