Skip to content

PlayerInteractEvent

Namespace Mc.Scripting.Events · Kind struct (ref)

public ref struct PlayerInteractEvent : IEvent

A player clicked (left or right, air or block). Cancel to stop the default action: block breaking start, block use, item use.

Id 118
Key mc:player_interact
Cancellable yes
Fired by the engine yes
Field Type Handlers may write Description
Player player no (readonly) The player.
Action enum:InteractAction no (readonly) What was clicked.
Hand enum:Hand no (readonly) The hand.
Item item no (readonly) The item in that hand.
Pos BlockPos no (readonly) The clicked block (only for block actions).
Face enum:BlockFace no (readonly) The clicked face (only for block actions).
HasBlock bool no (readonly) Whether pos/face are valid.

Set e.Cancelled = true in a handler to cancel it; lower-priority handlers are skipped unless they subscribed with receiveCancelled: true.

Member Description
Constructor Creates the event (for firing it from a plugin; native code builds its own).
public PlayerInteractEvent(Player player, InteractAction action, Hand hand, ItemView item, BlockPos pos, BlockFace face, bool hasBlock)

Creates the event (for firing it from a plugin; native code builds its own). Signature of API 1.0.

Parameters

Name Type Description
player Player
action InteractAction
hand Hand
item ItemView
pos BlockPos
face BlockFace
hasBlock bool
Member Description
InteractAction Action { get; } What was clicked.
bool Cancelled { get; set; } Cancelling stops lower-priority handlers (unless they opt in) and the action itself.
BlockFace Face { get; } The clicked face (only for block actions).
Hand Hand { get; } The hand.
bool HasBlock { get; } Whether pos/face are valid.
ItemView Item { get; } The item in that hand.
Player Player { get; } The player.
BlockPos Pos { get; } The clicked block (only for block actions).
static ushort CatalogueId { get; } Catalogue id (stable ABI).
static bool IsCancellable { get; } Whether handlers can cancel the event.
static string Key { get; } Registry key of the event.
public InteractAction Action { get; }

What was clicked.

public bool Cancelled { get; set; }

Cancelling stops lower-priority handlers (unless they opt in) and the action itself.

public BlockFace Face { get; }

The clicked face (only for block actions).

public Hand Hand { get; }

The hand.

public bool HasBlock { get; }

Whether pos/face are valid.

public ItemView Item { get; }

The item in that hand.

public Player Player { get; }

The player.

public BlockPos Pos { get; }

The clicked block (only for block actions).

public static ushort CatalogueId { get; }

Catalogue id (stable ABI).

public static bool IsCancellable { get; }

Whether handlers can cancel the event.

public static string Key { get; }

Registry key of the event.

BlockFace · BlockPos · Hand · IEvent · InteractAction · ItemView · Player