Skip to content

API reference Obsidian.API

MenuSlot class

Where a slot of a plugin's menu keeps its item, and the rules players' clicks follow in it, like vanilla's Slot and NeoForge's SlotItemHandler (see MenuContainer.Slots).

public sealed class MenuSlot

In Obsidian.API.

Remarks

A slot kept in a container is the container's slot: clicks change it with the container's lock held, like a chest's, and the players who have the container open, on its own or in another menu, see it change. A slot behind IItemAccess, like a plugin machine's buffer, moves its items through the access as a click ends: what the click took is extracted first, and if a slot no longer holds it the whole click is undone; then what it put in is inserted, and what the access refuses goes back to the player. The access is called with the menu's locks held, so it must not wait on a container's lock (a container block entity's access doesn't: a busy one takes and gives nothing), and a menu mustn't show a container's slots both ways.

The rules are checked as a click moves items, with the window's lock held, inside a call into the plugin; they must not wait on anything. A shift-click follows them too (see MenuContainer.QuickMove).

Constructors

MenuSlot()

public MenuSlot();

A slot the menu keeps itself.

MenuSlot(BaseContainer, int)

public MenuSlot(BaseContainer container, int index);

A slot kept in container's slot index, like a chest's or a block entity's.

MenuSlot(IItemAccess, int)

public MenuSlot(IItemAccess items, int index);

A slot kept behind items' slot index, like NeoForge's SlotItemHandler.

Properties

Container

public BaseContainer Container { get; }

The container the slot is kept in, if it is.

Index

public int Index { get; }

The slot of MenuSlot.Container or MenuSlot.Items that the menu's slot shows.

Items

public IItemAccess Items { get; }

The item access the slot is kept behind, if it is.

MaxStackSize

public int MaxStackSize { get; init; }

The most items the slot holds, up to each item's own stack size, like vanilla's getMaxStackSize: 99 by default, so that the item's stack size decides. A container-backed slot also respects its owning ContainerBlockEntity's slot limit.

MayPickup

public Func<IPlayer, bool> MayPickup { get; init; }

Whether a player may take the slot's stack, like vanilla's mayPickup; always when null.

MayPlace

public Func<ItemStack, bool> MayPlace { get; init; }

Whether players may put a stack of an item in the slot, like vanilla's mayPlace; anything when null. A slot that takes nothing, like a machine's output, still gives its stack whole to a cursor of the same item.

On this page