Class Item

java.lang.Object
net.risingworld.api.objects.Item
Direct Known Subclasses:
Item.BlueprintItem, Item.ClothingItem, Item.ConstructionItem, Item.ObjectItem

public class Item extends Object
Represents an item that exists in the inventory of a player or in a storage box.
Please note that this item does not really exists in the game world. If a player drops an item, the original Item instance will be deleted and a WorldItem will be spawned in the world instead.

Some items have a specific subtype, e.g blocks or objects (like furniture). They're all derived from Item and can be casted accordingly.
Example: Check equipped item type
1//Get equipped item
2Item item = player.getEquippedItem();
3
4//Check if item is a construction element
5if (item instanceof Item.ConstructionItem construction) {
6 System.out.println(construction.getConstructionName()); //prints "block", for example
7}
8
9//Check if item is an object
10else if (item instanceof Item.ObjectItem object){
11 System.out.println(object.getObjectName()); //prints "workbench", for example
12}
13
14//Check if item is a garment
15else if (item instanceof Item.ClothingItem clothing){
16 System.out.println(clothing.getClothingName()); //prints "mininghelmet", for example
17}
18
19//Check if item is a blueprint
20else if (item instanceof Item.BlueprintItem blueprint){
21 System.out.println(blueprint.getBlueprintName()); //prints "My summer house", for example
22}
See Also:
  • Method Details

    • isValid

      public boolean isValid()
    • getDefinition

      public Items.ItemDefinition getDefinition()
      Gets the item definition of this item.
      Returns:
      the definition of this item.
    • getName

      public String getName()
      Gets the ingame name (not the localized name) of the item. Never null.
      Returns:
      the name of the item, e.g "pickaxe".
    • getTypeID

      public short getTypeID()
      Gets the type ID of the item.
      Returns:
      the type ID of the item.
    • getVariant

      public int getVariant()
      Gets the item variant, i.e the texture of the item. For construction elements, for example, this is the texture.
      Returns:
      the variant/texture of the item. Usually this returns for most regular items.
    • getStack

      public int getStack()
      Gets the current stack size of the item.
      Returns:
      the stack size of the item.
    • setStack

      public void setStack(int stack)
    • getMaxStackSize

      public int getMaxStackSize()
      Gets the max possible stack size of the item.
      Returns:
      the max stack size of the item (between 1 and 64).
    • getValue

      public float getValue()
      Gets the current value of the item. Usually the value is used to describe a "fill level" or "charging level", for example it describes how much water is in a bottle etc.
      Returns:
      the value of the item. 0 for most items.
    • setValue

      public void setValue(float value)
    • getStatus

      public short getStatus()
      Gets the current status of the item. The status is used to store additional information about an item (for example the water type in a bucket, or if an electronic device is switched on/off).
      Returns:
      the status of the item.
    • setStatus

      public void setStatus(short status)
      Sets the item status.
      Parameters:
      status - the new status you want to set for the item.
      Example: Turn off the torch the player holds in his hands
      1//Get equipped item
      2Item item = player.getEquippedItem();
      3
      4//Check if item is not null
      5if(item != null) {
      6 //Check if item is a torch
      7 if(item.getName().equals("torch")) {
      8 //Turn off by setting status to 0
      9 item.setStatus(0);
      10 }
      11}
    • getModifier

      public Items.Modifier getModifier()
    • setModifier

      public void setModifier(Items.Modifier modifier)
    • getDurability

      public int getDurability()
    • setDurability

      public void setDurability(int durability)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object