Pulcedocs

Inventory

Mutate player inventories and containers through server-owned inventory services.

On this page

Player Inventory

PlayerHandle.Inventory() returns an inventory handle whose mutations validate and sync through the server.

inventory.go
inv := playerHandle.Inventory()

_, err := inv.Give(item.New("diamond_sword").
	Enchant(item.Sharpness(5)).
	NameTag("Arena Blade").
	Lore("Bound to the arena").
	Stack())
_, err = inv.Move(0, 1, 1)
_, err = inv.Swap(1, 2)
err = inv.SetHeldSlot(1)
err = inv.Resync()

Block Containers

Use world container handles for block inventories. Open sessions are marked dirty and resynced when content changes.

containers.go
_, err := ctx.RegisterBlock(content.DefineBlock("practice:crate").
	Container(27).
	Drop(item.New("practice:crate").Stack()).
	Spec())

container := worldHandle.ContainerAt(pos, 27)
_, err := container.Give(item.New("diamond").Count(8).Stack())
err = container.OpenFor(playerHandle.ID())
err = container.Resync()