Package net.risingworld.api.objects
Class Inventory
java.lang.Object
net.risingworld.api.objects.Inventory
Represents the inventory of a player (both online or offline players).
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Determines the "inventory type" or "slot type", i.e the category in the inventory (regular inventory items, hotbar, equipment etc.) -
Method Summary
Modifier and TypeMethodDescriptionaddClothingItem
(short clothingID, int variant, int stack, int color, long infoID) Creates and adds a new clothing item to the inventory.addClothingItemToSlot
(short clothingID, int variant, int stack, int color, long infoID, int slot, Inventory.SlotType slotType) Creates and adds a new clothing item to the inventory.addConstructionItem
(byte constructionID, int texture, int stack, int color) Creates and adds a new construction item to the inventory (e.g a block, window frame etc).addConstructionItemToSlot
(byte constructionID, int texture, int stack, int color, int slot, Inventory.SlotType slotType) Creates and adds a new construction item to the inventory (e.g a block, window frame etc).addItem
(short itemID, int variant, int stack) Creates and adds a new item to the inventory.addItemToSlot
(short itemID, int variant, int stack, int slot, Inventory.SlotType slotType) Creates and adds a new item to the inventory.addObjectItem
(short objectID, int variant, int stack) Creates and adds a new object item to the inventory, i.e an item that represents an object (like furniture).addObjectItemToSlot
(short objectID, int variant, int stack, int slot, Inventory.SlotType slotType) Creates and adds a new object item to the inventory, i.e an item that represents an object (like furniture).void
clear()
Clears the inventory, i.e removes all items from the inventory.int[]
findAllItems
(short itemID, int variant, Inventory.SlotType slotType) Searches for all items with the provided type ID (and optional variant/textures).int
findItem
(short itemID, int variant, Inventory.SlotType slotType) Searches for an item with the provided type ID (and optional variant/texture).int
findItemByGroup
(Items.Group group, Inventory.SlotType slotType) int
findItemByType
(Items.Type type, Inventory.SlotType slotType) Item[]
Gets a new array containing all items in this inventory.int
Gets a hashcode of this inventory.getItem
(int slot, Inventory.SlotType slotType) Gets the item from the specified slot and inventory type.Item[]
getItems
(Inventory.SlotType slotType) Gets a new array containing all items that are currently in the particular inventory type.int
getMaxSlotCount
(Inventory.SlotType slotType) Gets the max possible amount of slots the particular inventory/slot type can have.int
Gets the database ID of the player this inventory belongs to.int
Gets the current quickslot (hotbar) focus (i.e the currently equipped item).int
getSlotCount
(Inventory.SlotType slotType) Gets the amount of slots the particular inventory/slot type has.void
Merges all compatible item stacks in this inventory.boolean
removeItem
(int slot, Inventory.SlotType slotType) Removes an item from a particular slot in the inventory.boolean
removeItem
(int slot, Inventory.SlotType slotType, int amount) Removes an item (or more precisely, reduces the stack size of the item by the provided amount) from a particular slot in the inventory.void
sort
(boolean mergeStacks) Sorts all items in the inventory.
-
Method Details
-
getPlayerDbID
public int getPlayerDbID()Gets the database ID of the player this inventory belongs to.- Returns:
- the unique owner database ID.
-
getQuickslotFocus
public int getQuickslotFocus()Gets the current quickslot (hotbar) focus (i.e the currently equipped item).- Returns:
- the number of the currently selected quickslot.
-
getInventoryHashCode
public int getInventoryHashCode()Gets a hashcode of this inventory. If the content of the inventory changes, the hashcode changes accordingly. Use this value to check if the content of the inventory has changed (although bear in mind that there is the risk of collisions, so there is a very small chance that two different inventories produce the same hash).- Returns:
- the hashcode of this inventory.
-
getSlotCount
Gets the amount of slots the particular inventory/slot type has.- Parameters:
slotType
- the slot type.- Returns:
- the total amount of slots.
-
getMaxSlotCount
Gets the max possible amount of slots the particular inventory/slot type can have.- Parameters:
slotType
- the slot type.- Returns:
- the max possible amount of slots.
-
getItems
Gets a new array containing all items that are currently in the particular inventory type. Note that a new array is always created when calling this function. This array may contain null values if a particular slot in the inventory does not hold any items.- Parameters:
slotType
- the inventory/slot type (i.e the category) you want to get the items from.- Returns:
- a new array containing all items in the particular slot type.
-
getAllItems
Gets a new array containing all items in this inventory. Note that a new array is always created when calling this function. This array may contain null values if a particular slot in the inventory does not hold any items.- Returns:
- a new array containing all items in this inventory.
-
getItem
Gets the item from the specified slot and inventory type. Returns null if there is no item in this slot.- Parameters:
slot
- the slot.slotType
- the slot / inventory type.- Returns:
- the item in the slot, or null if there is no item in the slot.
-
findItem
Searches for an item with the provided type ID (and optional variant/texture). If such an item was found in the provided inventory/slot type, the slot index is returned, otherwise -1 is returned.- Parameters:
itemID
- the item ID you're looking for.variant
- the optional item variant/texture. -1 to ignore it.slotType
- the slot / inventory type.- Returns:
- the slot where such an item was found, or -1 if no suitable item was found.
-
findItemByGroup
-
findItemByType
-
findAllItems
Searches for all items with the provided type ID (and optional variant/textures). The slots of each item that was found in the provided inventory/slot type are returned as a new array.- Parameters:
itemID
- the item ID you're looking for.variant
- the optional item variant/texture. -1 to ignore it.slotType
- the slot / inventory type.- Returns:
- a new array containing all slots where the found items are located.
-
addItem
Creates and adds a new item to the inventory. The item will be added to the next suitable slot (this is either a slot containing an identical item it could be merged to, or a free slot). If there is no free slot, the player will drop the item and get a message about the inventory being full.- Parameters:
itemID
- the item type ID.variant
- the variant/texture of the item (only relevant for certain items, like blocks etc). Typically the the variant for most items is 0.stack
- the stack size, i.e the amount of items.- Returns:
- the newly created item. If there was already a compatible item
in the inventory, that item will be returned instead. Returns null if the
item could not be added to the inventory.
- Example: Add 4 gold ingots to a player inventory
-
addItemToSlot
public Item addItemToSlot(short itemID, int variant, int stack, int slot, Inventory.SlotType slotType) Creates and adds a new item to the inventory. The item will be added to the provided slot if possible.- Parameters:
itemID
- the item type ID.variant
- the variant/texture of the item (only relevant for certain items, like blocks etc). Typically the the variant for most items is 0.stack
- the stack size, i.e the amount of items.slot
- the target slot where you want to insert the item.slotType
- the target slot type.- Returns:
- the newly created item. If there was already a compatible item in the target slot, that item will be returned instead. Returns null if the item could not be added to the inventory.
- See Also:
-
addObjectItem
Creates and adds a new object item to the inventory, i.e an item that represents an object (like furniture). The item will be added to the next suitable slot (this is either a slot containing an identical item it could be merged to, or a free slot). If there is no free slot, the player will drop the item and get a message about the inventory being full.- Parameters:
objectID
- the object type ID.variant
- the variant/texture of the object (only relevant for certain objects). Typically the the variant for most objects is 0.stack
- the stack size, i.e the amount of items.- Returns:
- the newly created object item. If there was already a compatible item
in the inventory, that item will be returned instead. Returns null if the
item could not be added to the inventory.
- Example: Add a workbench to a player inventory
-
addObjectItemToSlot
public Item.ObjectItem addObjectItemToSlot(short objectID, int variant, int stack, int slot, Inventory.SlotType slotType) Creates and adds a new object item to the inventory, i.e an item that represents an object (like furniture). The item will be added to the provided slot if possible.- Parameters:
objectID
- the object type ID.variant
- the variant/texture of the object (only relevant for certain objects). Typically the the variant for most objects is 0.stack
- the stack size, i.e the amount of items.slot
- the target slot where you want to insert the object item.slotType
- the target slot type.- Returns:
- the newly created object item. If there was already a compatible item in the target slot, that item will be returned instead. Returns null if the item could not be added to the inventory.
- See Also:
-
addConstructionItem
public Item.ConstructionItem addConstructionItem(byte constructionID, int texture, int stack, int color) Creates and adds a new construction item to the inventory (e.g a block, window frame etc). The item will be added to the next suitable slot (this is either a slot containing an identical item it could be merged to, or a free slot). If there is no free slot, the player will drop the item and get a message about the inventory being full.- Parameters:
constructionID
- the type ID of the construction element.texture
- the texture of the construction element.stack
- the stack size, i.e the amount of items.color
- the optional RGBA color of the construction element (else 0).- Returns:
- the newly created construction item. If there was already a compatible item
in the inventory, that item will be returned instead. Returns null if the
item could not be added to the inventory.
- Example: Add stack of blocks with texture ID 200 to a player inventory
-
addConstructionItemToSlot
public Item.ConstructionItem addConstructionItemToSlot(byte constructionID, int texture, int stack, int color, int slot, Inventory.SlotType slotType) Creates and adds a new construction item to the inventory (e.g a block, window frame etc). The item will be added to the provided slot if possible.- Parameters:
constructionID
- the type ID of the construction element.texture
- the texture of the construction element.stack
- the stack size, i.e the amount of items.color
- the optional RGBA color of the construction element (else 0).slot
- the target slot where you want to insert the object item.slotType
- the target slot type.- Returns:
- the newly created object item. If there was already a compatible item in the target slot, that item will be returned instead. Returns null if the item could not be added to the inventory.
- See Also:
-
addClothingItem
public Item.ClothingItem addClothingItem(short clothingID, int variant, int stack, int color, long infoID) Creates and adds a new clothing item to the inventory. The item will be added to the next suitable slot (this is either a slot containing an identical item it could be merged to, or a free slot). If there is no free slot, the player will drop the item and get a message about the inventory being full.- Parameters:
clothingID
- the clothing type ID.variant
- the variant/texture of the object (only relevant for certain objects). Typically the the variant for most objects is 0.stack
- the stack size, i.e the amount of items.color
- optional RGBA color. Currently unused (set to 0).infoID
- optional info ID. Currently unused (set to 0).- Returns:
- the newly created object item. If there was already a compatible item in the inventory, that item will be returned instead. Returns null if the item could not be added to the inventory.
-
addClothingItemToSlot
public Item.ClothingItem addClothingItemToSlot(short clothingID, int variant, int stack, int color, long infoID, int slot, Inventory.SlotType slotType) Creates and adds a new clothing item to the inventory. The item will be added to the provided slot if possible.- Parameters:
clothingID
- the clothing type ID.variant
- the variant/texture of the object (only relevant for certain objects). Typically the the variant for most objects is 0.stack
- the stack size, i.e the amount of items.color
- optional RGBA color. Currently unused (set to 0).infoID
- optional info ID. Currently unused (set to 0).slot
- the target slot where you want to insert the object item.slotType
- the target slot type.- Returns:
- the newly created object item. If there was already a compatible item in the target slot, that item will be returned instead. Returns null if the item could not be added to the inventory.
- See Also:
-
removeItem
Removes an item from a particular slot in the inventory. After calling this method, the particular slot does no longer contain an item.- Parameters:
slot
- the target slot you want to remove the item from.slotType
- the target slot / inventory type.- Returns:
- true if there was an item in the slot, false if not.
-
removeItem
Removes an item (or more precisely, reduces the stack size of the item by the provided amount) from a particular slot in the inventory.- Parameters:
slot
- the target slot you want to remove the item from.slotType
- the target slot / inventory type.amount
- the amount of items you want to remove from the stack.- Returns:
- true if there was an item in the slot, false if not.
-
sort
public void sort(boolean mergeStacks) Sorts all items in the inventory. Optionally also merges stacks.- Parameters:
mergeStacks
- true if you also want to merge all compatible item stacks, false if you only want to sort them.
-
mergeStacks
public void mergeStacks()Merges all compatible item stacks in this inventory.- See Also:
-
clear
public void clear()Clears the inventory, i.e removes all items from the inventory.
-