Class Storage

java.lang.Object
net.risingworld.api.objects.Storage

public final class Storage extends Object
Represents a storage. Storages are not necessarily objects (i.e chests or crates in the world), instead this is just an abstract representation for all kind of storages (for example, it could also be the content of a mounts saddle bag).
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears the chest, i.e removes all items.
    int
    Gets a hashcode of this chest.
    long
    Gets the global, unique ID of this chest.
    getItem(int slot)
    Gets the item from the specified slot.
    Gets an array containing all items that are currently in the chest.
    int
    Gets the amount of slots the chest has.
    void
    removeItem(int slot)
    Removes an item from a particular slot in the chest.
    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 chest.
    int
    removeItem(short itemID, int variation, int amount)
    Removes the next item with the given type id and variation from the chest (more precisely, the stack size of the item is reduced by the provided amount).
    void
    setSlotCount(int slots)
    Overrides the amount of slots the chest has.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getID

      public long getID()
      Gets the global, unique ID of this chest.
      Returns:
      the unique chest ID.
    • getHashCode

      public int getHashCode()
      Gets a hashcode of this chest. If the content of the chest changes, the hashcode changes accordingly. Use this value to check if the content of the chest has changed.
      Returns:
      the hashcode of this chest.
    • getSlotCount

      public int getSlotCount()
      Gets the amount of slots the chest has.
      Returns:
      the total amount of slots.
    • setSlotCount

      public void setSlotCount(int slots)
      Overrides the amount of slots the chest has. Please note that this changes the max amount of slots permanently for this particular chest! Also keep in mind that reducing the amount of slots could make certain items inaccessible for existing chests (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).
      Parameters:
      slots - the new slot count. Must be greater than 0 and less or equal than 480 (10 "pages"). Every chest "page" has 48 slots.
    • getItems

      public Item[] getItems()
      Gets an array containing all items that are currently in the chest. Note that the array may also contain null if there is no item in a particular slot.
      Returns:
      an array containing all items in the chest.
    • getItem

      public Item getItem(int slot)
      Gets the item from the specified slot. Returns null if there is no item in this slot.
      Parameters:
      slot - the slot.
      Returns:
      the item in the slot, or null if there is no item in the slot.
    • removeItem

      public void removeItem(int slot)
      Removes an item from a particular slot in the chest. 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).
      Parameters:
      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 chest.
      Parameters:
      slot - the target slot in the chest 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 chest (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.
      Parameters:
      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.
      Returns:
      the rest, or 0 if all items were removed successfully.
    • clear

      public void clear()
      Clears the chest, i.e removes all items.