Class WorldItem

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

public final class WorldItem extends Object
Represents an item that exists in the game world, for example an item that has been dropped by a player.
  • Method Details

    • getGlobalID

      public long getGlobalID()
      Gets the global ID if this item. This ID is unique, but it is only valid until the server restarts.
      Returns:
      the global ID of this item.
    • 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.
      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.
    • getCreationDate

      public long getCreationDate()
      Gets the creation/spawn date of this item (timestamp in seconds).
      Returns:
      a unix timestamp (seconds) representing the creation/spawn date of this item.
    • getStack

      public int getStack()
      Gets the current stack size of the item.
      Returns:
      the stack size of the item.
    • 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.
    • 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)
    • getModifier

      public Items.Modifier getModifier()
    • getDurability

      public int getDurability()
    • getRelatedPlayer

      public Player getRelatedPlayer()
      This function returns the player that is related to this item. Usually this is the player who has dropped the item.
      Returns:
      the related player of this item, or null if no player was found.
    • getWorldItemType

      public WorldItem.WorldItemType getWorldItemType()
    • setWorldItemType

      public void setWorldItemType(WorldItem.WorldItemType type)
    • getRelatedMetaObject

      public MetaObject getRelatedMetaObject()
      If this item belongs to a meta object (i.e if WorldItemType is WorldItemType.MetaObject), this method returns the meta object. Otherwise null is returned.
      Returns:
      the related meta object, or null if this item does not belong to a meta object.
    • getInfoDefinition

      public Items.ItemInfo getInfoDefinition()
      Only relevant if this item is processed by a meta object: Gets the item info definition of this item if it's processed by the meta object.
      Returns:
      the info definition of this item (only if item is bound to a meta object, else null is returned).
    • getProgress

      public float getProgress()
      Only relevant if this item is processed by a meta object: Gets the current item progression value (e.g smelting/cooking progress etc).
      Returns:
      the item progress value (if processed by a meta object).
    • setProgress

      public void setProgress(float progress)
      Only relevant if this item is processed by a meta object: Sets the current item progression value (e.g smelting/cooking progress etc). The max progression value is determined by the Items.ItemInfo definition.
      Parameters:
      progress - the new progress value.
      Example: Set full progression for item
      1//Check if item is a meta object item (otherwise progress is ignored)
      2if (item.getWorldItemType() == WorldItem.WorldItemType.MetaObject) {
      3 //Get related item info
      4 Items.ItemInfo info = item.getInfoDefinition();
      5
      6 //Set progress to "duration" (this is how long it takes until
      7 //the item is processed, i.e smelted/cooked etc)
      8 item.setProgress(info.duration);
      9}
    • setDespawnTimer

      public void setDespawnTimer(float despawnTime)
      Sets the despawn time (remaining seconds until item despawns). Only relevant for items that can despawn.
      Parameters:
      despawnTime - the remaining seconds until this item should despawn.
    • destroy

      public void destroy(boolean silent)
      Destroys (i.e despawns) this item.
      Parameters:
      silent - if true, the item simply despawns. Otherwise it breaks (spawns debris etc).
    • getPosition

      public Vector3f getPosition()
      Gets a Vector3f containing the current global x, y and z coordinate of this item.
      Returns:
      the global item position as a Vector3f (float).
      Example:
      1Vector3f position = item.getPosition();
      2System.out.println("Item position: " + position.x + " " + position.y + " " + position.z);
    • setPosition

      public void setPosition(Vector3f position)
      Sets the global position of the item.
      Parameters:
      position - a Vector3f (float) containing the global target position.
    • setPosition

      public void setPosition(float x, float y, float z)
      Sets the global position of the item.
      Parameters:
      x - global X coordinate to set (horizontally).
      y - global Y coordinate to set (vertically).
      z - global Z coordinate to set (horizontally).
    • getRotation

      public Quaternion getRotation()
      Gets a Quaternion containing the current rotation of this item.
      Returns:
      the item rotation as a Quaternion.
    • setRotation

      public void setRotation(Quaternion rotation)
      Sets the rotation of this item.
      Parameters:
      rotation - a Quaternion representing the rotation.
    • setPositionAndRotation

      public void setPositionAndRotation(Vector3f position, Quaternion rotation)
    • applyPhysicalImpulse

      public void applyPhysicalImpulse(Vector3f impulse)
      Applies a physical impulse to the item (applied to the center). Only works if this is a physical item.
      Parameters:
      impulse - the impulse you want to apply to the item.
    • applyPhysicalImpulse

      public void applyPhysicalImpulse(Vector3f offset, Vector3f impulse)
      Applies a physical impulse to the item (applied to the position defined by the local offset). Only works if this is a physical item.
      Parameters:
      offset - the local offset (relative to the item center) where the impulse should be applied.
      impulse - the impulse you want to apply to the item.