Skip to content

API reference Obsidian.API.Inventory

IItemAccess interface

A way into the items of something, from one side: a chest's slots, a furnace's slots as a hopper on a given face reaches them, or a plugin machine's buffers. Like NeoForge's item handler capability: what a hopper, a dropper, a pipe or a storage network moves items through. Get one with IBlockLevel.GetItemAccess or ILevel.GetItemAccess.

public interface IItemAccess

In Obsidian.API.

Remarks

Slots are numbered from 0 to IItemAccess.SlotCount - 1 in the order the side reaches them, which is the order IItemAccess.Insert fills them in. From a side that reaches only some of a container's slots (a furnace's top reaches its ingredient slot), slot 0 is the first slot that side reaches, not the container's first slot.

With simulate set, a call reports what it would do and changes nothing, so that a transfer can be planned on both ends before either end changes: simulate the extraction and the insertion, then do both. Each call is atomic, but two calls aren't one transaction: another player's click can come between them, so check what the real call returns rather than assuming it matches the simulation.

Stacks passed in are never changed, and stacks returned are the caller's own copies.

Properties

SlotCount

int SlotCount { get; }

How many slots the side reaches. A container that was removed keeps its count, but takes and gives nothing.

Methods

Extract(int, int, bool)

ItemStack Extract(int slot, int count, bool simulate = false);

Takes up to count items out of slot, if the slot gives them up to this side.

Returns

What came out, or null when nothing did.

GetItem(int)

ItemStack GetItem(int slot);

A copy of the stack in slot, or null when it's empty.

Insert(int, ItemStack, bool)

ItemStack Insert(int slot, ItemStack stack, bool simulate = false);

Puts as much of stack as fits into slot: into an empty slot, or onto a stack of the same item with the same components, up to its stack size, if the slot takes the item from this side.

Returns

What didn't go in, or null when all of it did.

Insert(ItemStack, bool)

ItemStack Insert(ItemStack stack, bool simulate = false);

Puts as much of stack as fits into the slots, in their order, like a hopper fills a container: each slot in turn tops up a matching stack or takes the rest when empty.

Returns

What didn't go in, or null when all of it did.

On this page