Init
This commit is contained in:
57
content/world/entities/inventory/_index.en.md
Normal file
57
content/world/entities/inventory/_index.en.md
Normal file
@@ -0,0 +1,57 @@
|
||||
---
|
||||
title: Inventory
|
||||
type: docs
|
||||
weight: 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
|
||||
|
||||
```java
|
||||
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 >}}
|
||||
|
||||
```java
|
||||
// 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
|
||||
```
|
||||
Reference in New Issue
Block a user