Files
Documentation/content/world/entities/inventory/_index.en.md
2026-01-20 20:33:59 +01:00

1.6 KiB

title, type, weight
title type weight
Inventory docs 7

The inventory system in Hytale handles items, containers, and player inventories.

{{< cards >}} {{< card link="itemstacks" title="ItemStacks" subtitle="Working with immutable item stacks" >}} {{< card link="containers" title="Containers" subtitle="Inventory and container types" >}} {{< card link="transactions" title="Transactions" subtitle="Safe item modifications" >}} {{< /cards >}}

Overview

The inventory system follows an immutable pattern:

  • ItemStack - Immutable representation of items
  • Inventory - Player's personal inventory
  • ItemContainer - Generic container for items
  • Transactions - Safe way to modify items

Quick Start

import com.hypixel.hytale.server.core.inventory.Inventory;
import com.hypixel.hytale.server.core.inventory.ItemStack;
import java.util.logging.Level;

// Get player inventory
Player player = ...;
Inventory inv = player.getInventory();

// Get item in hand (via Inventory, not directly on Player)
ItemStack hand = inv.getItemInHand();

// Check if item exists
if (hand != null && !hand.isEmpty()) {
    // Use getItemId() - Item.getName() doesn't exist
    getLogger().at(Level.INFO).log("Holding: " + hand.getItemId());
}

Key Concepts

{{< callout type="info" >}} ItemStack is immutable. Methods like withQuantity() return a new ItemStack rather than modifying the original. {{< /callout >}}

// Immutable pattern
ItemStack original = new ItemStack("iron_sword", 1);
ItemStack modified = original.withQuantity(5);  // New instance

// original still has quantity of 1
// modified has quantity of 5