Package net.risingworld.api.objects
Klasse Storage
java.lang.Object
net.risingworld.api.objects.Storage
Represents a storage. Storages could be chests in the world, but also vehicle storages, saddle bags etc.
Storages are not necessarily bound to an object.
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungaddClothingItem
(short clothingID, int variant, int stack, int color, long infoID) Creates and adds a new clothing item to the storage.addClothingItemToSlot
(short clothingID, int variant, int stack, int color, long infoID, int slot) Creates and adds a new clothing item to the storage.addConstructionItem
(byte constructionID, int texture, int stack, int color) Creates and adds a new construction item to the storage (e.g a block, window frame etc).addConstructionItemToSlot
(byte constructionID, int texture, int stack, int color, int slot) Creates and adds a new construction item to the storage (e.g a block, window frame etc).addItem
(short itemID, int variant, int stack) Creates and adds a new item to the storage.addItemToSlot
(short itemID, int variant, int stack, int slot) Creates and adds a new item to the storage.addObjectItem
(short objectID, int variant, int stack) Creates and adds a new object item to the storage, i.e an item that represents an object (like furniture).addObjectItemToSlot
(short objectID, int variant, int stack, int slot) Creates and adds a new object item to the storage, i.e an item that represents an object (like furniture).void
clear()
Clears the storage, i.e removes all items from it.long
Gets the creation date of the storage as a timestamp in secondsint
Gets a hashcode of this storage.long
getID()
Gets the global, unique ID of this storage.getItem
(int slot) Gets the item from the specified slot.Item[]
getItems()
Gets an array containing all items that are currently in the storage.int
Gets the database id of the player who last modified the storage (added or removed items from it).int
Gets the amount of slots the storage has.boolean
Gets whether or not this is a transient storage, i.e a non-persistent storage.void
Merges all compatible item stacks in this storage.void
removeItem
(int slot) Removes an item from a particular slot in the storage.void
removeItem
(int slot, 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 storage.int
removeItem
(short itemID, int variation, int amount) Removes the next item with the given type id and variation from the storage (more precisely, the stack size of the item is reduced by the provided amount).void
setSlotCount
(int slots) Overrides the amount of slots the storage has.void
sort
(boolean mergeStacks) Sorts all items in the storage.
-
Methodendetails
-
getID
public long getID()Gets the global, unique ID of this storage.- Gibt zurück:
- the unique storage ID.
-
getHashCode
public int getHashCode()Gets a hashcode of this storage. If the content of the storage changes, the hashcode changes accordingly. Use this value to check if the content of the storage has changed.- Gibt zurück:
- the hashcode of this storage.
-
isTransient
public boolean isTransient()Gets whether or not this is a transient storage, i.e a non-persistent storage. If true, it's only valid during the session. If false, it's a persistent storage that will remain after a server/game restart.- Gibt zurück:
- true if this is a transient (temporary) storage, false if it is a persistent storage.
-
getSlotCount
public int getSlotCount()Gets the amount of slots the storage has.- Gibt zurück:
- the total amount of slots.
-
setSlotCount
public void setSlotCount(int slots) Overrides the amount of slots the storage has. Please note that this changes the max amount of slots permanently for this particular storage! Also keep in mind that reducing the amount of slots could make certain items inaccessible for existing storages (e.g if slot 100 already contains an item, but you reduce the slot count to 10, the item is no longer accessible and will be removed eventually).- Parameter:
slots
- the new slot count. Must be greater than 0..- Example: Increase chest size to 480 slots
-
getItems
Gets an array containing all items that are currently in the storage. Note that the array may also contain null if there is no item in a particular slot.- Gibt zurück:
- an array containing all items in the storage.
-
getItem
Gets the item from the specified slot. Returns null if there is no item in this slot.- Parameter:
slot
- the slot.- Gibt zurück:
- the item in the slot, or null if there is no item in the slot.
-
addItem
Creates and adds a new item to the storage. 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).- 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 storage, that item will be returned instead. Returns null if the item could not be added to the storage.
-
addItemToSlot
Creates and adds a new item to the storage. 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.- 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 storage.
- Siehe auch:
-
addObjectItem
Creates and adds a new object item to the storage, 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).- 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 storage, that item will be returned instead. Returns null if the
item could not be added to the storage.
- Example: Add a furnace object to a chest
-
addObjectItemToSlot
Creates and adds a new object item to the storage, 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.- 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 storage.
- Siehe auch:
-
addConstructionItem
public Item.ConstructionItem addConstructionItem(byte constructionID, int texture, int stack, int color) Creates and adds a new construction item to the storage (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).- 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 storage, that item will be returned instead. Returns null if the
item could not be added to the storage.
- Example: Add stack of blocks with texture ID 200 to a chest
-
addConstructionItemToSlot
public Item.ConstructionItem addConstructionItemToSlot(byte constructionID, int texture, int stack, int color, int slot) Creates and adds a new construction item to the storage (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.- 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 storage.
- 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 storage. 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).- 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 storage, that item will be returned instead. Returns null if the item could not be added to the storage.
-
addClothingItemToSlot
public Item.ClothingItem addClothingItemToSlot(short clothingID, int variant, int stack, int color, long infoID, int slot) Creates and adds a new clothing item to the storage. 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.- 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 storage.
- Siehe auch:
-
removeItem
public void removeItem(int slot) Removes an item from a particular slot in the storage. After calling this method, the particular slot does no longer contain an item and the item also gets disposed (so you can no longer use the item instance).- Parameter:
slot
- the target slot you want to remove the item from.
-
removeItem
public void removeItem(int slot, 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 storage.- Parameter:
slot
- the target slot in the storage you want to remove the item from.amount
- the amount you want to remove.
-
removeItem
public int removeItem(short itemID, int variation, int amount) Removes the next item with the given type id and variation from the storage (more precisely, the stack size of the item is reduced by the provided amount). If the item stack size is smaller than amount, the rest will be removed from the next item. If amount is -1, all items with this id and variation will be removed.- Parameter:
itemID
- the item type id.variation
- the item variation (e.g block texture), usually 0.amount
- the amount you want to remove. Set -1 to remove all items of this type.- Gibt zurück:
- the rest, or 0 if all items were removed successfully.
- Example: Remove 40 gold ingots from chest
-
sort
public void sort(boolean mergeStacks) Sorts all items in the storage. 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 storage.- Siehe auch:
-
clear
public void clear()Clears the storage, i.e removes all items from it. -
getCreationDate
public long getCreationDate()Gets the creation date of the storage as a timestamp in seconds- Gibt zurück:
- a timestamp (seconds) representing the original creation date of the storage.
-
getLastModifyPlayerDbID
public int getLastModifyPlayerDbID()Gets the database id of the player who last modified the storage (added or removed items from it).- Gibt zurück:
- the player database id.
-