Interface IPlayerInventoryManager
- Namespace
- Vintagestory.API.Common
- Assembly
- VintagestoryAPI.dll
Let's you do various interesting things with the players inventory.
public interface IPlayerInventoryManager
- Extension Methods
Properties
ActiveHotbarSlot
Returns the currently selected hotbar slot. Might return null if there is no hotbar!
ItemSlot ActiveHotbarSlot { get; }
Property Value
ActiveHotbarSlotNumber
The players currently active hot bar slot
int ActiveHotbarSlotNumber { get; set; }
Property Value
ActiveTool
If the player currently holds a tool in his hands, this value will be set
EnumTool? ActiveTool { get; }
Property Value
CurrentHoveredSlot
The slot the player currently hovers over with his mouse cursor
ItemSlot CurrentHoveredSlot { get; set; }
Property Value
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
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
MouseItemSlot
Returns the slot that holds the currently dragged itemstack
ItemSlot MouseItemSlot { get; }
Property Value
OpenedInventories
List of inventories currently opened by the player
List<IInventory> OpenedInventories { get; }
Property Value
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
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
Returns
DropMouseSlotItems(bool)
Drops the current contents of the mouse slot onto the ground
bool DropMouseSlotItems(bool dropAll)
Parameters
dropAll
boolIf false, will only drop 1
Returns
Find(Func<ItemSlot, bool>)
Iterates over all inventory slots, returns true if your matcher returns true
bool Find(Func<ItemSlot, bool> matcher)
Parameters
Returns
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
ItemSlotonlyPlayerInventory
boolop
ItemStackMoveOperationskipSlots
List<ItemSlot>
Returns
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
ItemSlotop
ItemStackMoveOperationskipSlots
List<ItemSlot>
Returns
GetHotbarInventory()
Returns the hotbar inventory object. Obvious comment is being obvious.
IInventory GetHotbarInventory()
Returns
GetHotbarItemstack(int)
Gets the itemstack that in the given slot number of the players hotbar
ItemStack GetHotbarItemstack(int slotId)
Parameters
slotId
int
Returns
GetInventory(string)
Retrieve a players inventory. Returns null if not found.
IInventory GetInventory(string inventoryId)
Parameters
inventoryId
string
Returns
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
stringinvFound
InventoryBase
Returns
GetInventoryName(string)
Returns the full inventory id for given inventory class name, e.g. GlobalConstants.creativeInvClassName
string GetInventoryName(string inventoryClassName)
Parameters
inventoryClassName
string
Returns
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
HasInventory(IInventory)
Shorthand for Inventories.ContainsValue(inventory)
bool HasInventory(IInventory inventory)
Parameters
inventory
IInventory
Returns
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
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
TryGiveItemstack(ItemStack, bool)
Tries to add given itemstack to the players inventory
bool TryGiveItemstack(ItemStack itemstack, bool slotNotifyEffect = false)
Parameters
Returns
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
ItemSlotop
ItemStackMoveOperationonlyPlayerInventory
boolForces 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
ItemSlotop
ItemStackMoveOperationonlyPlayerInventory
boolshiftClickDebugText
StringBuilderslotNotifyEffect
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
ItemSlottargetSlot
ItemSlotop
ItemStackMoveOperationIf successfull, a client packet that may be sent to the server for synchronisation