Package net.risingworld.api.objects
Klasse Inventory
java.lang.Object
net.risingworld.api.objects.Inventory
Represents the inventory of a player (both online or offline players).
-
Verschachtelte Klassen - Übersicht
Modifizierer und TypKlasseBeschreibungstatic enum
Determines the "inventory type" or "slot type", i.e the category in the inventory (regular inventory items, hotbar, equipment etc.) -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungaddClothingItem
(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.Adds an item by name.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) Searches for a particular item group in the provided inventory slot type.int
findItemByType
(Items.Type type, Inventory.SlotType slotType) Searches for a particular item type in the provided inventory slot type.Item[]
Gets a new array containing all items in this inventory.int
Gets the slot of the currently equipped item.Gets the slot type of the currently equipped item.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 currently selected quickslot / hotbar slot.int
getSlotCount
(Inventory.SlotType slotType) Gets the amount of slots the particular inventory/slot type has.static Inventory.SlotType
getSlotType
(int index) Converts a total index to the according inventory slot type.static int
indexToSlot
(int index) Converts a total index to the according inventory slot.void
Merges all compatible item stacks in this inventory.boolean
removeItem
(int index, int amount) Removes an item from a total index in inventory (or more precisely, reduces the stack size of the item by the provided amount).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 from a particular slot in the inventory (or more precisely, reduces the stack size of the item by the provided amount).static int
slotToIndex
(int slot, Inventory.SlotType slotType) Converts a slot to a total index.void
sort
(boolean mergeStacks) Sorts all items in the inventory.void
Force-syncs the entire inventory with the client.
-
Methodendetails
-
getPlayerDbID
public int getPlayerDbID()Gets the database ID of the player this inventory belongs to.- Gibt zurück:
- the unique owner database ID.
-
getQuickslotFocus
public int getQuickslotFocus()Gets the currently selected quickslot / hotbar slot.- Gibt zurück:
- the currently selected quickslot.
- Siehe auch:
-
getEquippedItemSlot
public int getEquippedItemSlot()Gets the slot of the currently equipped item.- Gibt zurück:
- the currently equipped item slot.
- Siehe auch:
-
getEquippedItemSlotType
Gets the slot type of the currently equipped item. Usually it's theSlotType.Quickslot
, but there is no guarantee because the player is able to equip any item in the inventory (rightclick -> equip item).- Gibt zurück:
- the currently equipped item slot type.
- Siehe auch:
-
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).- Gibt zurück:
- the hashcode of this inventory.
-
getSlotCount
Gets the amount of slots the particular inventory/slot type has.- Parameter:
slotType
- the slot type.- Gibt zurück:
- the total amount of slots.
-
getMaxSlotCount
Gets the max possible amount of slots the particular inventory/slot type can have.- Parameter:
slotType
- the slot type.- Gibt zurück:
- 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.- Parameter:
slotType
- the inventory/slot type (i.e the category) you want to get the items from.- Gibt zurück:
- 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.- Gibt zurück:
- 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.- Parameter:
slot
- the slot.slotType
- the slot / inventory type.- Gibt zurück:
- 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.- Parameter:
itemID
- the item ID you're looking for.variant
- the optional item variant/texture. -1 to ignore it.slotType
- the slot / inventory type.- Gibt zurück:
- the slot where such an item was found, or -1 if no suitable item was found.
-
findItemByGroup
Searches for a particular item group in the provided inventory slot type.- Parameter:
group
- the item group you're looking for.slotType
- the inventory slot type.- Gibt zurück:
- the slot of the item, or -1 if no suitable item was found.
-
findItemByType
Searches for a particular item type in the provided inventory slot type.- Parameter:
type
- the item type you're looking for.slotType
- the inventory slot type.- Gibt zurück:
- the slot of the item, or -1 if no suitable item was found.
-
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.- Parameter:
itemID
- the item ID you're looking for.variant
- the optional item variant/texture. -1 to ignore it.slotType
- the slot / inventory type.- Gibt zurück:
- a new array containing all slots where the found items are located.
-
addItem
Adds an item by name. This supports all types of items - regular items, objects (like furniture), construction elements or clothing items.- Parameter:
item
- the internal item/object name, e.g "pickaxe" or "workbench".variant
- the item variant/texture.stack
- the amount of items you want to add.- Gibt zurück:
- the newly created item. Depending on the item type, this could be either a regular
Item
, or anItem.ObjectItem
(if it's an object), or aItem.ConstructionItem
(if it's a block), or aItem.ClothingItem
(if it's a clothing piece). 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.
-
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 with, or a free slot). If there is no free slot, the player will drop the item and receive a message about the inventory being full.- Parameter:
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.- Gibt zurück:
- 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.- Parameter:
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.- Gibt zurück:
- 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.
- Siehe auch:
-
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 with, or a free slot). If there is no free slot, the player will drop the item and receive a message about the inventory being full.- Parameter:
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.- Gibt zurück:
- 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.- Parameter:
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.- Gibt zurück:
- 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.
- Siehe auch:
-
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 with, or a free slot). If there is no free slot, the player will drop the item and receive a message about the inventory being full.- Parameter:
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).- Gibt zurück:
- 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.- Parameter:
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.- Gibt zurück:
- 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.
- Siehe auch:
-
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 with, or a free slot). If there is no free slot, the player will drop the item and receive a message about the inventory being full.- Parameter:
clothingID
- the clothing type ID.variant
- the variant/texture of the cloth (only relevant for certain clothes). Typically the the variant for most clothes 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).- Gibt zurück:
- the newly created clothing 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.- Parameter:
clothingID
- the clothing type ID.variant
- the variant/texture of the cloth (only relevant for certain clothes). Typically the the variant for most clothes 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 clothing item.slotType
- the target slot type.- Gibt zurück:
- the newly created clothing 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.
- Siehe auch:
-
removeItem
Removes an item from a particular slot in the inventory. After calling this method, the particular slot does no longer contain an item.- Parameter:
slot
- the target slot you want to remove the item from.slotType
- the target slot / inventory type.- Gibt zurück:
- true if there was an item in the slot, false if not.
-
removeItem
Removes an item from a particular slot in the inventory (or more precisely, reduces the stack size of the item by the provided amount).- Parameter:
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.- Gibt zurück:
- true if there was an item in the slot, false if not.
-
removeItem
public boolean removeItem(int index, int amount) Removes an item from a total index in inventory (or more precisely, reduces the stack size of the item by the provided amount).- Parameter:
index
- the total index in inventory (not to be confused with the slot!)amount
- the amount of items you want to remove from the stack. Set to -1 to remove the item entirely.- Gibt zurück:
- true if there was an item in that index, false if not.
- Siehe auch:
-
sort
public void sort(boolean mergeStacks) Sorts all items in the inventory. Optionally also merges stacks.- Parameter:
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.- Siehe auch:
-
syncWithClient
public void syncWithClient()Force-syncs the entire inventory with the client. -
clear
public void clear()Clears the inventory, i.e removes all items from the inventory. -
indexToSlot
public static int indexToSlot(int index) Converts a total index to the according inventory slot.- Parameter:
index
- the total index in inventory.- Gibt zurück:
- the related slot.
- Siehe auch:
-
slotToIndex
Converts a slot to a total index. This is useful, for example, if you want to work with the items array (getAllItems()
).- Parameter:
slot
- the slot.slotType
- the slot type.- Gibt zurück:
- the related slot.
- Siehe auch:
-
getSlotType
Converts a total index to the according inventory slot type.- Parameter:
index
- the total index in inventory.- Gibt zurück:
- the related slot type.
- Siehe auch:
-