Class BlockEvent.BreakEvent
java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.level.BlockEvent
net.neoforged.neoforge.event.level.BlockEvent.BreakEvent
- All Implemented Interfaces:
net.neoforged.bus.api.ICancellableEvent
- Enclosing class:
BlockEvent
public static class BlockEvent.BreakEvent
extends BlockEvent
implements net.neoforged.bus.api.ICancellableEvent
This event is fired on the server when a player attempts to break a block, upon receipt of a block break packet.
The following conditions may cause this event to fire in a cancelled state:
.
- If
Player.blockActionRestricted(net.minecraft.world.level.Level, net.minecraft.core.BlockPos, net.minecraft.world.level.GameType)
is true. - If the target block is a
GameMasterBlock
andPlayer.canUseGameMasterBlocks()
is false. - If the the player is holding an item, and
invalid reference
Item#canAttackBlock
invalid reference
Item#canAttackBlock
-
Nested Class Summary
Nested classes/interfaces inherited from class net.neoforged.neoforge.event.level.BlockEvent
BlockEvent.BlockToolModificationEvent, BlockEvent.BreakEvent, BlockEvent.EntityMultiPlaceEvent, BlockEvent.EntityPlaceEvent, BlockEvent.FarmlandTrampleEvent, BlockEvent.FluidPlaceBlockEvent, BlockEvent.NeighborNotifyEvent, BlockEvent.PortalSpawnEvent
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBreakEvent
(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.entity.player.Player player) -
Method Summary
Modifier and TypeMethodDescriptionnet.minecraft.world.entity.player.Player
Returns the player who is attempting to break the block.void
setCanceled
(boolean canceled) Cancelling this event will prevent the block from being broken, and notifies the client of the refusal.Methods inherited from class net.neoforged.neoforge.event.level.BlockEvent
getLevel, 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
-
player
private final net.minecraft.world.entity.player.Player player
-
-
Constructor Details
-
BreakEvent
public BreakEvent(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.entity.player.Player player)
-
-
Method Details
-
getPlayer
public net.minecraft.world.entity.player.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) Cancelling this event will prevent the block from being broken, and notifies the client of the refusal.- Specified by:
setCanceled
in interfacenet.neoforged.bus.api.ICancellableEvent
-