Table of Contents

Interface IPlayerInventoryManager

Namespace
Vintagestory.API.Common
Assembly
VintagestoryAPI.dll

Let's you do various interesting things with the players inventory.

public interface IPlayerInventoryManager

Properties

ActiveHotbarSlot

Returns the currently selected hotbar slot. Might return null if there is no hotbar!

ItemSlot ActiveHotbarSlot { get; }

Property Value

ItemSlot

ActiveHotbarSlotNumber

The players currently active hot bar slot

int ActiveHotbarSlotNumber { get; set; }

Property Value

int

ActiveTool

If the player currently holds a tool in his hands, this value will be set

EnumTool? ActiveTool { get; }

Property Value

EnumTool?

CurrentHoveredSlot

The slot the player currently hovers over with his mouse cursor

ItemSlot CurrentHoveredSlot { get; set; }

Property Value

ItemSlot

Inventories

Dictionary of all inventories currently available to the player (some may however not be opened)
Note: for iterating through these, Inventories.Values will not be ordered. Instead use InventoriesOrdered if you want consistent ordering on server and client e.g. for shift-click operations

Dictionary<string, IInventory> Inventories { get; }

Property Value

Dictionary<string, IInventory>

InventoriesOrdered

An iterable collection of all inventories currently available to the player, arranged in the same order (by creation order) on both server and client to prevent syncing / ghosting issues

IEnumerable<InventoryBase> InventoriesOrdered { get; }

Property Value

IEnumerable<InventoryBase>

MouseItemSlot

Returns the slot that holds the currently dragged itemstack

ItemSlot MouseItemSlot { get; }

Property Value

ItemSlot

OpenedInventories

List of inventories currently opened by the player

List<IInventory> OpenedInventories { get; }

Property Value

List<IInventory>

Methods

BroadcastHotbarSlot()

Server Side: Resends the hotbar slot contents to all other clients to make sure they render the correct held item Client side: No effect

void BroadcastHotbarSlot()

CloseInventory(IInventory)

Notifies the inventory manager that the player has closed an inventory. Should always be called on both sides (client and server). After closing interaction with given inventory becomes no longer possible until reopened

object CloseInventory(IInventory inventory)

Parameters

inventory IInventory

Returns

object

DiscardAll()

Will discard all of the players inventory contents

void DiscardAll()

DropAllInventoryItems(IInventory)

Drops the contents of given inventory

void DropAllInventoryItems(IInventory inv)

Parameters

inv IInventory

DropItem(ItemSlot, bool)

Drops the current contents of given slot onto the ground

bool DropItem(ItemSlot slot, bool fullStack)

Parameters

slot ItemSlot
fullStack bool

Returns

bool

DropMouseSlotItems(bool)

Drops the current contents of the mouse slot onto the ground

bool DropMouseSlotItems(bool dropAll)

Parameters

dropAll bool

If false, will only drop 1

Returns

bool

Find(Func<ItemSlot, bool>)

Iterates over all inventory slots, returns true if your matcher returns true

bool Find(Func<ItemSlot, bool> matcher)

Parameters

matcher Func<ItemSlot, bool>

Returns

bool

GetBestSuitedSlot(ItemSlot, bool, ItemStackMoveOperation, List<ItemSlot>)

Returns a slot that would best fit the contents of the source slot. This checks all inventories currently opened by the player.

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

Parameters

sourceSlot ItemSlot
onlyPlayerInventory bool
op ItemStackMoveOperation
skipSlots List<ItemSlot>

Returns

ItemSlot

GetBestSuitedSlot(ItemSlot, ItemStackMoveOperation, List<ItemSlot>)

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

Parameters

sourceSlot ItemSlot
op ItemStackMoveOperation
skipSlots List<ItemSlot>

Returns

ItemSlot

GetHotbarInventory()

Returns the hotbar inventory object. Obvious comment is being obvious.

IInventory GetHotbarInventory()

Returns

IInventory

GetHotbarItemstack(int)

Gets the itemstack that in the given slot number of the players hotbar

ItemStack GetHotbarItemstack(int slotId)

Parameters

slotId int

Returns

ItemStack

GetInventory(string)

Retrieve a players inventory. Returns null if not found.

IInventory GetInventory(string inventoryId)

Parameters

inventoryId string

Returns

IInventory

GetInventory(string, out InventoryBase)

Returns true if the invID is found, and the found IInventory value is in invFound; similar to Dictionary.TryGetValue, invFound is undefined if the result is false

bool GetInventory(string invID, out InventoryBase invFound)

Parameters

invID string
invFound InventoryBase

Returns

bool

GetInventoryName(string)

Returns the full inventory id for given inventory class name, e.g. GlobalConstants.creativeInvClassName

string GetInventoryName(string inventoryClassName)

Parameters

inventoryClassName string

Returns

string

GetOwnInventory(string)

Same as GetInventory() with playeruid appended to the inventoryClassName. Returns null if not found. You can use GlobalConstants.*ClassName to get the vanilla player inventories.

IInventory GetOwnInventory(string inventoryClassName)

Parameters

inventoryClassName string

Returns

IInventory

HasInventory(IInventory)

Shorthand for Inventories.ContainsValue(inventory)

bool HasInventory(IInventory inventory)

Parameters

inventory IInventory

Returns

bool

NotifySlot(IPlayer, ItemSlot)

Produces a visual cue on given slot, if it's currently part of an inventory and visible to the player If called on server side, the server will send a network packet to notify the client.

void NotifySlot(IPlayer player, ItemSlot slot)

Parameters

player IPlayer
slot ItemSlot

OnDeath()

Will drop all of the players inventory contents

void OnDeath()

OpenInventory(IInventory)

Notifies the inventory manager that the player has opened an inventory. Should always be called on both sides (client and server). Only then interaction with other inventories becomes possible

object OpenInventory(IInventory inventory)

Parameters

inventory IInventory

Returns

object

TryGiveItemstack(ItemStack, bool)

Tries to add given itemstack to the players inventory

bool TryGiveItemstack(ItemStack itemstack, bool slotNotifyEffect = false)

Parameters

itemstack ItemStack
slotNotifyEffect bool

Returns

bool

TryTransferAway(ItemSlot, ref ItemStackMoveOperation, bool, bool)

Tries to move away items from the source slot into any other slot of another inventory

object[] TryTransferAway(ItemSlot sourceSlot, ref ItemStackMoveOperation op, bool onlyPlayerInventory, bool slotNotifyEffect = false)

Parameters

sourceSlot ItemSlot
op ItemStackMoveOperation
onlyPlayerInventory bool

Forces to place the item only into the players personal inventory

slotNotifyEffect bool

Returns

object[]

One or more client packets that may be sent to the server for synchronisation

TryTransferAway(ItemSlot, ref ItemStackMoveOperation, bool, StringBuilder, bool)

object[] TryTransferAway(ItemSlot sourceSlot, ref ItemStackMoveOperation op, bool onlyPlayerInventory, StringBuilder shiftClickDebugText, bool slotNotifyEffect = false)

Parameters

sourceSlot ItemSlot
op ItemStackMoveOperation
onlyPlayerInventory bool
shiftClickDebugText StringBuilder
slotNotifyEffect bool

Returns

object[]

TryTransferTo(ItemSlot, ItemSlot, ref ItemStackMoveOperation)

Tries to move items from source slot to target slot (useful for client side inventory utilities)

object TryTransferTo(ItemSlot sourceSlot, ItemSlot targetSlot, ref ItemStackMoveOperation op)

Parameters

sourceSlot ItemSlot
targetSlot ItemSlot
op ItemStackMoveOperation

If successfull, a client packet that may be sent to the server for synchronisation

Returns

object