Table of Contents

Interface IInventory

Namespace
Vintagestory.API.Common
Assembly
VintagestoryAPI.dll

Basic interface representing an item inventory

public interface IInventory : IReadOnlyCollection<ItemSlot>, IEnumerable<ItemSlot>, IEnumerable
Inherited Members
Extension Methods

Properties

ClassName

The name of the class for the inventory

string ClassName { get; }

Property Value

string

DirtySlots

The slots marked dirty.

HashSet<int> DirtySlots { get; }

Property Value

HashSet<int>

Empty

Convenience method to check if this inventory contains anything

bool Empty { get; }

Property Value

bool

InventoryID

The internal named id for the inventory

string InventoryID { get; }

Property Value

string

this[int]

Gets or sets the slot at the given slot number. Returns null for invalid slot number (below 0 or above Count-1). The setter allows for replacing slots with custom ones, though caution is advised.

ItemSlot this[int slotId] { get; set; }

Parameters

slotId int

Property Value

ItemSlot

LastChanged

Milliseconds since server startup when the inventory was last changed (not used currently)

long LastChanged { get; }

Property Value

long

PutLocked

Called by item slot, if true, player cannot take items from this chest

bool PutLocked { get; }

Property Value

bool

RemoveOnClose

Wether or not to remove the inventory from the players inventory list upon closing it

bool RemoveOnClose { get; }

Property Value

bool

TakeLocked

Called by item slot, if true, player cannot take items from this chest

bool TakeLocked { get; }

Property Value

bool

Methods

ActivateSlot(int, ItemSlot, ref ItemStackMoveOperation)

When the player clicks on this slot

object ActivateSlot(int slotId, ItemSlot sourceSlot, ref ItemStackMoveOperation op)

Parameters

slotId int
sourceSlot ItemSlot
op ItemStackMoveOperation

Returns

object

Close(IPlayer)

Removes ability to interact with this inventory for this player. Returns a close inventory packet that can be sent to the server for synchronization.

object Close(IPlayer player)

Parameters

player IPlayer

Returns

object

GetBestSuitedSlot(ItemSlot, List<ItemSlot>)

[Obsolete("Use GetBestSuitedSlot(ItemSlot sourceSlot, ItemStackMoveOperation op, List<ItemSlot> skipSlots = null) instead")]
WeightedSlot GetBestSuitedSlot(ItemSlot sourceSlot, List<ItemSlot> skipSlots)

Parameters

sourceSlot ItemSlot
skipSlots List<ItemSlot>

Returns

WeightedSlot

GetBestSuitedSlot(ItemSlot, ItemStackMoveOperation, List<ItemSlot>)

Returns the best suited slot to hold the item from the source slot. Attached is also a weight, indicating how well the item is suited for it. If no suitable slot was found, the weight will be 0 and the slot will be null. A higher weight means the slot is better suited to hold the item. This method does not check if the player is actually allowed to access or modify this inventory.

Weight will be 1 for a default slot that is empty Weight will be 2 for a default slot that can take one or more items from the source slot Weight could be 10 for an empty armor slot and the source slot contains an armor itemtack

WeightedSlot GetBestSuitedSlot(ItemSlot sourceSlot, ItemStackMoveOperation op = null, List<ItemSlot> skipSlots = null)

Parameters

sourceSlot ItemSlot
op ItemStackMoveOperation
skipSlots List<ItemSlot>

Returns

WeightedSlot

GetSlotId(ItemSlot)

Will return -1 if the slot is not found in this inventory

int GetSlotId(ItemSlot slot)

Parameters

slot ItemSlot

Returns

int

HasOpened(IPlayer)

Checks if given player has this inventory currently opened

bool HasOpened(IPlayer player)

Parameters

player IPlayer

Returns

bool

MarkSlotDirty(int)

Server Side: Will resent the slot contents to the client and mark them dirty there as well Client Side: Will refresh stack size, model and stuff if this stack is currently being rendered

void MarkSlotDirty(int slotId)

Parameters

slotId int

Open(IPlayer)

Marks the inventory available for interaction for this player. Returns a open inventory packet that can be sent to the server for synchronization.

object Open(IPlayer player)

Parameters

player IPlayer

Returns

object

TryFlipItems(int, ItemSlot)

Attempts to flip the contents of both slots

object TryFlipItems(int targetSlotId, ItemSlot sourceSlot)

Parameters

targetSlotId int
sourceSlot ItemSlot

Returns

object

Events

SlotModified

Event that fires when a slot was modified

event Action<int> SlotModified

Event Type

Action<int>

SlotNotified

Event that fires when NotifySlot was called

event Action<int> SlotNotified

Event Type

Action<int>