InventoryApi

Services.get("InventoryApi")

Overview

API Reference

createItem()

Creates an ItemStack from a JavaScript object.

const item = inventoryApi.createItem({
    id: "minecraft:diamond",
    name: "§b§lExample Item",
    lore: [
        "§7This is an example",
        "§7Created via InventoryApi"
    ],
    amount: 1
})

Parameters:

  • data (Object) Item configuration object:

Key
Type
Description

id

String

Minecraft item ID

name

String

Display name (supports color codes)

lore

String[]

Item lore

amount

Number (optional)

Item amount (default: 1)

Returns:


constructInventory()

Creates an interactive inventory UI.

Parameters:

  • type (String) "single" ⇒ Standard single chest inventory "double" ⇒ Standard double chest inventory

  • title (String) Inventory title (supports color codes)

Returns:

  • InventoryUI ⇒ Managed inventory interface


InventoryUI API

The object returned by constructInventory() exposes the following methods.


setSlot()

Sets an item in a specific slot.

Parameters:

  • slot (Number)

  • item (ItemStack)


copy()

Creates a deep copy of the inventory UI.

Returns:

  • InventoryUI


show()

Opens the inventory for a player.

Parameters:

  • player (Player)


hide()

Closes the inventory for a player.

Parameters:

  • player (Player)


destroy()

Destroys the inventory and unregisters all listeners.


onLeftClick()

Registers a left-click handler.

Returns: (function handler)


onRightClick()

Registers a right-click handler.

Returns: (function handler)


onItemPlaced()

Called when an item is placed into the inventory.

Returns: (function handler)


onClosed()

Called when the inventory is closed.


Example:

Last updated

Was this helpful?