Inventory Structure
server-go/shared/inventory.go
Fixed-size array of 24 inventory slots
The item type identifier (0 = empty slot)
Number of items in this stack (1-65535)
Flag indicating if the slot needs to be sent to the client
Adding Items
The inventory automatically handles stacking logic:server-go/shared/inventory.go
Stacking Behavior
- Existing stack: If the item already exists in inventory, increment its count
- New stack: If no existing stack found, place in the first empty slot
- Full inventory: If no empty slots, the item is silently dropped
Usage in Scripts
Add items to player inventory through the scripting API:server-go/scripts/context.go
server-go/content/berry_bush.go
An
InventoryUpdate packet is automatically sent to the client when items are added.Persistence
Encoding to Database
Inventories are serialized to binary format for database storage:server-go/shared/inventory.go
Decoding from Database
server-go/shared/inventory.go
Player Save/Load
Inventories are automatically saved and loaded with player data:server-go/shared/player.go
Dirty Tracking
TheDirty flag optimizes network synchronization:
- Set to true: When an item is added or modified
- Set to true on load: For all non-empty slots (to send initial state)
- Used by client: To determine which slots need UI updates
Limitations
Fixed 24-slot capacity
Fixed 24-slot capacity
The inventory has a hard limit of 24 slots. This is a fixed-size array that cannot be expanded at runtime.
No item removal API
No item removal API
Currently, the inventory system only supports adding items. Removing items must be implemented separately.
Silent overflow
Silent overflow
If the inventory is full,
AddItem() silently does nothing. The item is lost.No stack size limits
No stack size limits
Items can stack up to 65,535 (uint16 max). There’s no per-item stack limit configuration.
Client Synchronization
Inventory updates are sent to the client via theInventoryUpdate packet:
- All 24 slots with their current ItemId and Count
- Dirty flags to determine which slots changed
- Updates the UI to reflect new inventory state
The entire inventory is sent in each update packet, not just changed slots. The dirty flag is for client-side optimization.
Next Steps
Content Scripting
Learn how to give items to players through scripts
Skills
Explore the skill system for character progression