API reference Obsidian.API.Events
ContainerClickEventArgs class
A player's click in their open window, raised before the server applies it.
public sealed class ContainerClickEventArgs : ContainerEventArgs, ICancellable
In Obsidian.API.
Remarks
Handlers run outside the container's lock, so a handler may wait, even for another viewer's click. The server's own handler runs last: inside the lock it checks that the window is still open and that neither the container, the player's inventory nor the cursor changed since the click arrived (see BaseContainer.Revision: a slot set, or a stack in one changing its count or components), then applies the click, unless it's cancelled, and sends the window's contents and cursor to its viewers. A click whose slots changed meanwhile isn't applied, so a handler's decision is never applied to contents it didn't see; the player's window is corrected instead, like after a cancelled click.
A handler may cancel the click and read ContainerClickEventArgs.Item, a copy of what the slot held as the click arrived. To change slots as part of the click, register the change with ContainerClickEventArgs.ApplyWithClick, which runs it inside the lock with the click. A handler that changes the container itself, through its methods, makes its own click stale, and its change may race other viewers' clicks.
Properties
Button
public required sbyte Button { get; init; }The button that was clicked in the inventory. Can vary depending on the inventory type.
ClickedSlot
public required short ClickedSlot { get; init; }Gets the slot that was clicked
public required ClickType ClickType { get; init; }ContainerId
public required int ContainerId { get; init; }The ID of the inventory. Usually incremented by one every time an inventory is opened and resets when it reaches 255.
Remarks
This value is unique per client.
IsCancelled
public bool IsCancelled { get; }Gets a value indicating whether the default behaviour should be cancelled.
public bool IsPlayerInventory { get; }Item
public ItemStack Item { get; }What the clicked slot held when the click arrived, as a copy made each time it's read: it shares nothing with the slot's stack or with other reads, components included, so changing it changes nothing.
public required int StateId { get; init; }Methods
ApplyWithClick(Action)
public void ApplyWithClick(Action change);Registers a change to make with the click: the server runs change inside the container's lock, right after applying the click, or in its place when the click is cancelled, and only if the click's slots didn't change since it arrived, so the change acts on what ContainerClickEventArgs.Item shows. The window's viewers then see the result.
Parameters
change- The change, which reads and sets slots through the container's methods. It runs on the server's handler, so it must not block or wait.
Cancel()
public void Cancel();Sets a flag which prevents default (vanilla) behavior from executing.
Remarks
This flag only affects vanilla behavior. If you wish to prevent other handlers from running, see AsyncEventArgs.Handled.