Virtual inventory
Experimental native API; the 2168 UI is not accepted yet.
On this page
Creation and ownership
plugin.Context.NewVirtualInventory(kind) creates a plugin-owned handle: VirtualChest (27), VirtualDoubleChest (54), VirtualFurnace (3). Limit: 128 per owner. Scope cleanup destroys it; explicit Destroy is idempotent.
Inventory handle
inv, err := ctx.NewVirtualInventory(plugin.VirtualChest)
if err != nil { return err }
if err := inv.Set(0, item.Stick().Count(2).Stack()); err != nil {
_ = inv.Destroy()
return err
}
if err := inv.OpenFor(playerUUID); err != nil {
_ = inv.Destroy()
return err
}
// Keep inv for later updates and destruction.Contract
- OpenFor/CloseFor:
uuid.UUID, not username or internal player.ID. - ID, Kind, Size, Snapshot, Slot, Set, Clear, OpenFor, CloseFor, CloseAll, Destroy.
- Snapshot returns nil on failure; Slot returns an inspectable error.
- Single-slot Set rejects malformed, negative and oversized stacks with
item.ErrInvalidStack. Zero count clears.
Events and errors
server.container.open.before can cancel; open/close events include SourceKind, VirtualID, UIKind, OwnerID. Use errors.Is with ErrVirtualInventoryInvalidSlot, PlayerOffline, Destroyed, UnsupportedKind, NotOwned, Limit (all prefixed ErrVirtualInventory).
Not live acceptance
Three furnace slots do not implement smelting by themselves. Do not defer Destroy after a successful OpenFor. Compiling example: api/testdata/externalplugin/virtual_inventory.go in the core.