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