InventoryState
Pure data container for player inventory state (V1.2)
Instantiated per-player. Holds all inventory state including items, slots, equipped status,
and per-player settings. Uses ItemsByID for O(1) stack
lookups.
export type ItemInstance = {
UUID: string,
Id: string,
Amount: number,
Metadata: { [string]: any }?
}
export type PlayerSettings = {
Limit: number, - Weight limit (0 = infinite)
CanStack: boolean, - Enable/disable stacking
MaxStackSize: number, - Max items per stack
MaxHotbarSlots: number, - Hotbar slot count
UiType: string, - Interface version to load
}
export type InventoryStateType = {
Player: Player,
Items: { [string]: ItemInstance }, -- UUID -> Item
ItemsByID: { [string]: {string} }, -- ItemId -> UUIDs (O(1) lookup)
Hotbar: { [number]: string? }, -- Static: nil holes allowed
Storage: { string }, -- Dynamic: packed array
EquippedItemUUID: string?, -- UUID of equipped item
Weight: number, -- Total item amounts
Settings: PlayerSettings, -- Per-player settings!
}
V1.2 Changes
Key improvements from V1
| Feature | V1 | V1.2 |
|---|---|---|
| Equipped Tracking | Slot-based | UUID-based |
| Storage | Static array | Dynamic (packed) |
| Settings | Global only | Per-player |
| Weight Tracking | Not tracked | state.Weight |
Hotbar vs Storage
Static vs Dynamic slot management
Hotbar (Static)
Fixed slots with nil holes preserved
Hotbar maintains fixed 1-9 slots. When an item is removed, the slot becomes nil
(hole preserved). Slots don't shift.
Storage (Dynamic)
Packed array that shifts on removal
Storage is a packed array. When an item is removed via table.remove,
items shift up to fill the gap. No holes.
Getters
Data access methods (no logic)
| Method | Returns | Description |
|---|---|---|
| GetItem(uuid) | ItemInstance? | Get item by UUID |
| GetHotbarUUID(slot) | string? | Get UUID in hotbar slot |
| GetStorageUUID(index) | string? | Get UUID in storage index |
| IsEquipped(uuid) | boolean | Check if item is equipped |