Confirmedusers, Bureaucrats, editor, Administrators
1,522
edits
No edit summary |
VeryGoodDog (talk | contribs) m (VeryGoodDog moved page API: Basic Inventory Handling to Modding:Basic Inventory Handling) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{ | {{GameVersion|1.12}} | ||
== Overview == | == Overview == | ||
Line 40: | Line 40: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
If you need access to other inventories like e.g. the backpack inventories, you can use the <code>InventoryManager.Inventories</code> Property. This contains a dictionary with the name of the inventory (for example "hotbar-APlayerUID") and the corresponding inventory. Another cleaner looking way if you only need a single inventory would be the <code>InventoryManager.GetOwnInventory()</code> method. | If you need access to other inventories like e.g. the backpack inventories, you can use the <code>InventoryManager.Inventories</code> Property. This contains a dictionary with the name of the inventory (for example "hotbar-APlayerUID") and the corresponding inventory. Another cleaner looking way if you only need a single inventory would be the <code>InventoryManager.GetOwnInventory()</code> method, which appends the player uid to the classname and returns the inventory. To avoid errors when typing the classnames, check first if the classname is already in the <code>GlobalConstants</code>. | ||
Because backpack inventory contains the bags as well as the slots, you have to check if it is valid to put the item there. For this you can use the <code>ItemSlot.CanHold()</code> method. | |||
If for example you want to fill every empty slot in the backpack with single torches you could do the following: | If for example you want to fill every empty slot in the backpack with single torches you could do the following: |