Skip to content

@nextvm/inventory

First-party inventory module. Slot-based inventory with weight + stack limits, item registry, server-authoritative add/use/move/drop.

Install

bash
pnpm add @nextvm/inventory
typescript
modules: ['@nextvm/inventory']

Dependencies

typescript
dependencies: ['player']

Config

FieldTypeDefaultDescription
maxSlotsint (1–200)40Maximum slots per character
maxWeightKgnumber (1–500)50Maximum carry weight in kg

ItemRegistry

Defines available items at module init:

typescript
import { ItemRegistry, defineItem } from '@nextvm/inventory'

const registry = new ItemRegistry()
registry.define(defineItem({
  id: 'water_bottle',
  labelKey: 'inventory.items.water_bottle',
  weight: 0.5,
  stackable: true,
  maxStack: 10,
  category: 'consumable',
}))

The module ships seed items on startup: water_bottle, bread, phone.

State

inventoryState:

FieldTypeDefault
slotsArray<{ slot: number, stack: { itemId, count } }>[]

RPC procedures

ProcedureTypeInputDescription
getMyInventoryqueryReturns the calling player's slots
useItemmutation{ slot }Decrements the stack at the given slot
dropItemmutation{ slot, count }Removes count items from a slot
moveItemmutation{ fromSlot, toSlot }Moves or swaps stacks between slots
addItemmutation{ itemId, count }Server: adds items respecting weight + stack limits

Server-side validation

addItem enforces:

  • Item exists in the registry → otherwise VALIDATION_ERROR
  • Total weight <= maxWeightKg → otherwise VALIDATION_ERROR
  • No more than maxSlots → otherwise VALIDATION_ERROR
  • Stacks respect maxStack

PLA note

This module manages in-game items only. It does NOT process payments. Modules built on top that sell items to players for real money must integrate via @nextvm/tebex and ship a MONETIZATION.md).

See also

Released under the LGPL-3.0 License.