The PlayerInteractWithBlockBeforeEvent interface in @minecraft/server.
Interface in @minecraft/server
Extends PlayerInteractWithBlockAfterEvent, CancellableEvent
import type { PlayerInteractWithBlockBeforeEvent } from '@minecraft/server';Subscribe to it with world.beforeEvents.playerInteractWithBlock.
Example
Section titled “Example”import { world, type PlayerInteractWithBlockBeforeEvent } from '@minecraft/server';
world.beforeEvents.playerInteractWithBlock.subscribe((event: PlayerInteractWithBlockBeforeEvent) => { console.log('playerInteractWithBlock', event.player.name, event.block.typeId, event.itemStack?.typeId);
// Uncomment to stop it from happening. // event.cancel = true;});import { world } from '@minecraft/server';
world.beforeEvents.playerInteractWithBlock.subscribe((event) => { console.log('playerInteractWithBlock', event.player.name, event.block.typeId, event.itemStack?.typeId);
// Uncomment to stop it from happening. // event.cancel = true;});Used by
Section titled “Used by”WorldBeforeEvents.playerInteractWithBlock, PlayerInteractWithBlockBeforeEventSignal.subscribe, PlayerInteractWithBlockBeforeEventSignal.unsubscribe
Inherited
Section titled “Inherited”From PlayerInteractWithBlockAfterEvent: player, block, blockFace, itemStack, isFirstEvent
From CancellableEvent: cancel