Class Inventory

java.lang.Object
fr.hytale.loader.api.inventory.Inventory
Direct Known Subclasses:
InventoryPlayer

public class Inventory extends Object
HytaleLoader wrapper for the native Hytale Inventory class.

This class provides a simplified API for interacting with inventories.

Since:
1.0.1
Version:
1.0.4
Author:
HytaleLoader
  • Constructor Summary

    Constructors
    Constructor
    Description
    Inventory(com.hypixel.hytale.server.core.inventory.Inventory nativeInventory)
    Constructs a new Inventory wrapper.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addItem(Item item)
    Adds an item to the inventory.
    void
    Clears the inventory.
    getItem(int slot)
    Return the item at the slot given
    Gets the items in the inventory.
    com.hypixel.hytale.server.core.inventory.Inventory
    Gets the native Hytale inventory instance.
    void
    setItem(Item item, int slot)
    Sets the item at the specified slot in the inventory.

    Methods inherited from class Object

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

    • Inventory

      public Inventory(com.hypixel.hytale.server.core.inventory.Inventory nativeInventory)
      Constructs a new Inventory wrapper.
      Parameters:
      nativeInventory - the native Hytale inventory instance
  • Method Details

    • getNativeInventory

      public com.hypixel.hytale.server.core.inventory.Inventory getNativeInventory()
      Gets the native Hytale inventory instance.
      Returns:
      the wrapped native inventory
    • clear

      public void clear()
      Clears the inventory.

      Note: This method manually clears each slot to avoid issues with the native clear() method which may trigger events before the player is fully initialized in the world.

    • addItem

      public void addItem(Item item)
      Adds an item to the inventory.
      Parameters:
      item - the item to add
    • getItem

      public Item getItem(int slot)
      Return the item at the slot given
      Parameters:
      slot - the slot of the inventory
      Returns:
      item the item at the slot given
    • getItems

      public List<Item> getItems()
      Gets the items in the inventory.
      Returns:
      a list of items
    • setItem

      public void setItem(Item item, int slot)
      Sets the item at the specified slot in the inventory.

      This method automatically determines whether to place the item in the hotbar (slots 0-8) or the main storage (slots 9+) based on the slot index provided.

      Parameters:
      item - the item to place in the inventory
      slot - the target slot index (0-8 for hotbar, 9+ for storage)