Klasse Item

java.lang.Object
net.risingworld.api.objects.Item
Bekannte direkte Unterklassen:
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}
Siehe auch:
  • Verschachtelte Klassen - Übersicht

    Verschachtelte Klassen
    Modifizierer und Typ
    Klasse
    Beschreibung
    static class 
    Represents a blueprint item in the inventory of a player or in a storage box.
    A blueprint item is a ready-to-use blueprint (this does not apply to empty blueprints!), i.e a blueprint item representing an actual blueprint.
    static class 
    Represents a clothing item in the inventory of a player or in a storage box.
    This is any type of clothes (or headgear or accessory).
    static class 
    Represents a construction item in the inventory of a player or in a storage box.
    This is, for example, a block.
    static class 
    Represents an object item in the inventory of a player or in a storage box.
    This is, for example, a furniture item.
  • Methodenübersicht

    Modifizierer und Typ
    Methode
    Beschreibung
    void
    Destroys this item, i.e remove it from inventory/storage.
    boolean
     
    Gets the item definition of this item.
    int
     
    int
    Gets the max possible stack size of the item.
     
    Gets the ingame name (not the localized name) of the item.
    int
    Gets the current stack size of the item.
    short
    Gets the current status of the item.
    short
    Gets the type ID of the item.
    float
    Gets the current value of the item.
    int
    Gets the item variant, i.e the texture of the item.
    int
     
    boolean
    Checks whether or not the item still exists and is valid.
    void
    setDurability(int durability)
     
    void
     
    void
    setStack(int stack)
     
    void
    setStatus(short status)
    Sets the item status.
    void
    setValue(float value)
     

    Von Klasse geerbte Methoden java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Methodendetails

    • isValid

      public boolean isValid()
      Checks whether or not the item still exists and is valid.
      Gibt zurück:
      true if the item still exists, false if the item instance had been disposed (i.e the item is no longer valid).
    • getDefinition

      public Items.ItemDefinition getDefinition()
      Gets the item definition of this item.
      Gibt zurück:
      the definition of this item.
    • getName

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

      public short getTypeID()
      Gets the type ID of the item.
      Gibt zurück:
      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.
      Gibt zurück:
      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.
      Gibt zurück:
      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.
      Gibt zurück:
      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.
      Gibt zurück:
      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).
      Gibt zurück:
      the status of the item.
    • setStatus

      public void setStatus(short status)
      Sets the item status.
      Parameter:
      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)
    • destroy

      public void destroy()
      Destroys this item, i.e remove it from inventory/storage. After calling this method, you can no longer use this item instance.
    • equals

      public boolean equals(Object o)
      Setzt außer Kraft:
      equals in Klasse Object
    • hashCode

      public int hashCode()
      Setzt außer Kraft:
      hashCode in Klasse Object