CUSTOM GUI SYSTEM DOCUMENTATION

Contents

1. Introduction

This custom GUI system allows datapack creators to build interactive interfaces using JSON definitions and Lua scripting. GUIs can range from simple chest-like containers to complex custom interfaces with buttons, sliders, text boxes, and more.

Key Features:

2. GUI Types

Container GUI

Traditional chest-like inventory interfaces (9-54 slots). Best for item selection menus, shop interfaces, and simple button grids.

Custom GUI

Pixel-perfect custom interfaces with unlimited flexibility. Best for complex dashboards, settings panels, interactive displays, and mini-games.

3. File Structure

data/
└── your_namespace/
    └── triggerapi/
        └── gui/
            ├── my_gui.json          # GUI definition
            └── scripts/
                └── my_script.lua    # Lua scripts

Opening a GUI from Lua:

mc.player.openGui("your_namespace:my_gui")

4. Container GUIs

Container GUIs use a traditional chest inventory layout.

Basic Structure

{
  "type": "container",
  "title": "My Container",
  "size": 27,
  "background": {
    "item": "minecraft:gray_stained_glass_pane",
    "fill_empty": true
  },
  "container_buttons": [
    {
      "slot": 13,
      "item": "minecraft:diamond",
      "name": "§bClick Me!",
      "lore": [
        "§7This is a button",
        "§7Click to execute script"
      ],
      "glow": true,
      "script": "mc.player.sendMessage('Button clicked!')",
      "close_on_click": false
    }
  ]
}

Container Properties

PropertyTypeDefaultDescription
typeString"custom"Set to "container" for chest GUIs
titleString"GUI"Title displayed at top of container
sizeInteger27Number of slots (multiple of 9, max 54)
backgroundObjectnullBackground item configuration
container_buttonsArray[]List of button definitions

Background Object

PropertyTypeDefaultDescription
itemStringnullItem ID to use as background
fill_emptyBooleanfalseFill all empty slots with background item

Container Button Definition

PropertyTypeDefaultDescription
slotIntegerRequiredSlot index (0-53)
itemStringRequiredItem ID to display
nameStringnullDisplay name (supports § codes)
loreArray[]Lore lines (supports § codes)
glowBooleanfalseAdd enchantment glint
scriptStringnullLua script or file reference
close_on_clickBooleanfalseClose GUI when clicked

Script References

Scripts can be inline or file references:

Inline:

"script": "mc.player.sendMessage('Hello!')"

File reference (ends with .lua):

"script": "your_namespace:button_handler.lua"

File location: data/your_namespace/triggerapi/gui/scripts/button_handler.lua

5. Custom GUIs

Custom GUIs provide pixel-perfect control over layout and appearance.

Basic Structure

{
  "type": "custom",
  "title": "My Custom GUI",
  "width": 176,
  "height": 166,
  "background_texture": "your_namespace:textures/gui/my_background.png",
  "elements": [
    {
      "type": "button",
      "id": "my_button",
      "x": 10,
      "y": 20,
      "width": 100,
      "height": 20,
      "texture": "minecraft:textures/gui/widgets.png",
      "texture_x": 0,
      "texture_y": 66,
      "hover_texture_y": 86,
      "script": "mc.player.sendMessage('Custom button clicked!')"
    }
  ]
}

Custom GUI Properties

PropertyTypeDefaultDescription
typeString"custom"Must be "custom"
titleString"GUI"Window title
widthInteger176GUI width in pixels
heightInteger166GUI height in pixels
background_textureStringnullBackground texture path
elementsArray[]List of GUI elements

6. GUI Elements

All custom elements share base properties like id, x, y, width, and height.

Common Element Properties

PropertyTypeDefaultDescription
typeStringRequiredElement type
idStringRequiredUnique identifier
xIntegerRequiredX position (pixels from left)
yIntegerRequiredY position (pixels from top)
widthIntegerRequiredElement width in pixels
heightIntegerRequiredElement height in pixels
tooltipArray[]Tooltip lines on hover

1. Button

Interactive clickable button.

PropertyTypeDefaultDescription
textureStringnullTexture resource location
texture_xInteger0X offset in texture
texture_yInteger0Y offset (normal state)
hover_texture_yInteger0Y offset (hover state)
image_widthInteger256Total texture width
image_heightInteger256Total texture height
scriptStringnullScript on click

Script Context Variables: guiId, button (0=left, 1=right, 2=middle)

2. Text

Static or dynamic text display.

PropertyTypeDefaultDescription
textStringRequiredText to display (supports § colors)
colorInteger (Hex)0x404040Text color (ARGB)
shadowBooleanfalseEnable text shadow
scaleFloat1.0Text scale multiplier

3. Image

Static image display.

PropertyTypeDefaultDescription
textureStringRequiredTexture resource location
texture_xInteger0X offset in texture
texture_yInteger0Y offset in texture
image_widthInteger256Total texture width
image_heightInteger256Total texture height

4. Item

Display a Minecraft item.

PropertyTypeDescription
itemStringItem resource location (Required)

5. Progress Bar

Displays progress as a fillable bar (updated via Lua every 50ms).

PropertyTypeDefaultDescription
bar_colorInteger (Hex)0xFF00FF00Fill color (ARGB)
background_colorInteger (Hex)0xFF808080Background color
border_colorInteger (Hex)0xFF000000Border color
show_percentageBooleanfalseDisplay percentage text
verticalBooleanfalseVertical orientation
progress_scriptStringnullScript returning 0.0-1.0

Progress Script Example:

-- Must return a value between 0.0 and 1.0
return mc.player.health / mc.player.maxHealth

6. Slider

Interactive slider for numeric input.

PropertyTypeDefaultDescription
min_valueFloat0.0Minimum value
max_valueFloat100.0Maximum value
default_valueFloat50.0Starting value
stepFloat1.0Value increment (0=continuous)
slider_colorInteger (Hex)0xFFFFFFFFTrack color
handle_colorInteger (Hex)0xFF8B8B8BHandle color
text_colorInteger (Hex)0xFFFFFFFFValue text color
show_valueBooleantrueDisplay current value
on_change_scriptStringnullScript on value change

Script Context: ctx.value (current slider value as string)

7. Entity

Display a 3D rendered entity.

PropertyTypeDefaultDescription
entity_typeStringRequiredEntity resource location
entity_scaleFloat30.0Render scale
rotate_entityBooleantrueAuto-rotate (360° every 3.6s)
entity_nbtStringnullNBT data (JSON format)

8. Text Box

Editable text input field.

PropertyTypeDefaultDescription
max_lengthInteger32Maximum character count
hint_textStringnullPlaceholder text
text_colorInteger (Hex)0xFFFFFFFFText color
hint_colorInteger (Hex)0xFF808080Hint text color
multilineBooleanfalseAllow multiple lines (4x max_length)
on_text_change_scriptStringnullScript on text change

Reading value: local username = ctx.username_input_value

9. Dropdown

Dropdown selection menu.

PropertyTypeDefaultDescription
optionsArrayRequiredList of selectable options
default_optionInteger0Default selected index
dropdown_colorInteger (Hex)0xFFFFFFFFDropdown background
selected_colorInteger (Hex)0xFF00FF00Selected option highlight
text_colorInteger (Hex)0xFF000000Text color
on_select_scriptStringnullScript on selection change

Script Context: ctx.value (selected option index as string)

10. Switch

Toggle switch (on/off).

PropertyTypeDefaultDescription
default_stateBooleanfalseStarting state (true=on)
on_colorInteger (Hex)0xFF00FF00Color when enabled
off_colorInteger (Hex)0xFFFF0000Color when disabled
on_toggle_scriptStringnullScript on toggle

Script Context: ctx.value ("true" or "false")

11. Checkbox

Checkbox with optional label.

PropertyTypeDefaultDescription
default_stateBooleanfalseStarting state (true=checked)
check_colorInteger (Hex)0xFF00FF00Checkmark color
labelStringnullText label next to checkbox
label_colorInteger (Hex)0xFF404040Label text color
checked_textureStringnullCustom checkmark texture
unchecked_textureStringnullCustom unchecked texture
on_toggle_scriptStringnullScript on toggle

Script Context: ctx.value ("true" or "false")

7. Lua Scripting

Available Lua Environment

When scripts execute, they have access to:

  1. Standard Lua libraries: Base, Package, String, Table, Math
  2. mc table: Minecraft game access (see Lua API documentation)
  3. ctx table: Persistent context storage (shared across script calls)
  4. util table: Utility functions

Context Variables

The ctx table persists data across button clicks and element interactions within the same GUI session.

Setting context values:

ctx.player_choice = "option_a"
ctx.counter = 5
ctx.has_completed = true

Reading context values:

if ctx.counter then
  ctx.counter = ctx.counter + 1
else
  ctx.counter = 1
end
mc.player.sendMessage("Count: " .. ctx.counter)

Pre-populated context variables:

Script Execution Flow

  1. Container buttons: Execute when slot is clicked
  2. Custom GUI buttons: Execute when clicked
  3. Sliders: Execute on_change_script when value changes
  4. Progress bars: Execute progress_script every 50ms to get current value
  5. Text boxes: Execute on_text_change_script when text changes
  6. Dropdowns: Execute on_select_script when selection changes
  7. Switches/Checkboxes: Execute on_toggle_script when toggled

Common Lua Patterns

Opening another GUI:

mc.player.openGui("your_namespace:next_gui")

Closing current GUI:

mc.player.closeGui()

Giving items:

mc.player.giveItem("minecraft:diamond", 64)

Teleporting:

mc.player.teleport(100, 64, 200)

Broadcasting messages:

mc.util.broadcast("§6Server Announcement!")

Executing commands:

mc.util.executeCommand("time set day")

Multi-step workflow:

-- First button
if not ctx.step then
  ctx.step = 1
  mc.player.sendMessage("Step 1: Complete task A")
end

-- Second button
if ctx.step == 1 then
  ctx.step = 2
  mc.player.sendMessage("Step 2: Complete task B")
  mc.player.giveItem("minecraft:diamond", 1)
end

-- Third button
if ctx.step == 2 then
  mc.player.sendMessage("All steps complete!")
  mc.player.closeGui()
end

8. Context Management

Server-Side Context

For container GUIs, context is managed entirely on the server and persists across button clicks automatically.

Client-Server Synchronization

For custom GUIs, context is synchronized between client and server:

  1. Server creates/retrieves context when GUI opens
  2. Server sends SyncContextPacket to client with current context
  3. Client updates element states and executes scripts
  4. Client sends GuiStateUpdatePacket when elements change
  5. Server executes scripts and updates shared context
  6. Context is cleaned up when GUI closes

Context Lifecycle

Creation: Automatically created when GUI opens
Cleanup: Automatically cleaned when player closes GUI or logs out

9. Complete Examples

Example 1: Simple Shop (Container)

File: data/myshop/triggerapi/gui/weapon_shop.json

{
  "type": "container",
  "title": "§6Weapon Shop",
  "size": 27,
  "background": {
    "item": "minecraft:black_stained_glass_pane",
    "fill_empty": true
  },
  "container_buttons": [
    {
      "slot": 11,
      "item": "minecraft:wooden_sword",
      "name": "§fWooden Sword",
      "lore": ["§7Price: §e10 Gold", "§aClick to purchase"],
      "script": "myshop:buy_item.lua",
      "close_on_click": false
    },
    {
      "slot": 13,
      "item": "minecraft:iron_sword",
      "name": "§fIron Sword",
      "lore": ["§7Price: §e50 Gold", "§aClick to purchase"],
      "glow": true,
      "script": "myshop:buy_item.lua",
      "close_on_click": false
    },
    {
      "slot": 15,
      "item": "minecraft:diamond_sword",
      "name": "§bDiamond Sword",
      "lore": ["§7Price: §e200 Gold", "§aClick to purchase"],
      "glow": true,
      "script": "myshop:buy_item.lua",
      "close_on_click": false
    }
  ]
}

File: data/myshop/triggerapi/gui/scripts/buy_item.lua

-- Get item name from clicked slot
local items = {
  [11] = {name = "wooden_sword", price = 10},
  [13] = {name = "iron_sword", price = 50},
  [15] = {name = "diamond_sword", price = 200}
}

local item_data = items[tonumber(ctx.slot)]

if item_data then
  mc.player.giveItem("minecraft:" .. item_data.name, 1)
  mc.player.sendMessage("§aPurchased " .. item_data.name .. " for " .. item_data.price .. " gold!")
  mc.player.playSound("minecraft:entity.experience_orb.pickup", 1.0)
else
  mc.player.sendMessage("§cInvalid item!")
end

Example 2: Settings Panel (Custom)

File: data/mymod/triggerapi/gui/settings.json

{
  "type": "custom",
  "title": "§6Game Settings",
  "width": 200,
  "height": 180,
  "background_texture": "minecraft:textures/gui/demo_background.png",
  "elements": [
    {
      "type": "text",
      "id": "title",
      "x": 50,
      "y": 10,
      "width": 100,
      "height": 10,
      "text": "§l§6Settings",
      "color": 0xFFFFFF,
      "shadow": true,
      "scale": 1.5
    },
    {
      "type": "slider",
      "id": "volume_slider",
      "x": 70,
      "y": 30,
      "width": 100,
      "height": 10,
      "min_value": 0.0,
      "max_value": 100.0,
      "default_value": 50.0,
      "step": 5.0,
      "show_value": true,
      "on_change_script": "ctx.volume = ctx.value"
    },
    {
      "type": "checkbox",
      "id": "particles",
      "x": 10,
      "y": 90,
      "width": 16,
      "height": 16,
      "default_state": true,
      "label": "Enable Particles",
      "label_color": 0x404040,
      "on_toggle_script": "ctx.particles_enabled = ctx.value"
    },
    {
      "type": "button",
      "id": "save_button",
      "x": 50,
      "y": 150,
      "width": 100,
      "height": 20,
      "texture": "minecraft:textures/gui/widgets.png",
      "texture_x": 0,
      "texture_y": 66,
      "hover_texture_y": 86,
      "script": "mymod:save_settings.lua"
    }
  ]
}

Example 3: Player Stats Dashboard

Complete dashboard with progress bars showing health, food, and XP with auto-updating values every 50ms.

{
  "type": "custom",
  "title": "§bPlayer Statistics",
  "width": 220,
  "height": 200,
  "elements": [
    {
      "type": "progress_bar",
      "id": "health_bar",
      "x": 70,
      "y": 15,
      "width": 130,
      "height": 15,
      "bar_color": 0xFFFF0000,
      "background_color": 0xFF404040,
      "show_percentage": true,
      "progress_script": "return mc.player.health / mc.player.maxHealth"
    },
    {
      "type": "entity",
      "id": "player_model",
      "x": 80,
      "y": 120,
      "width": 60,
      "height": 80,
      "entity_type": "minecraft:player",
      "entity_scale": 25.0,
      "rotate_entity": true
    }
  ]
}

10. Best Practices

1. GUI Design

2. Scripting

3. Performance

4. User Experience

5. Debugging

11. Color Reference (ARGB Hex)

Common colors in 0xAARRGGBB format:

ColorHex CodeDescriptionExample
White0xFFFFFFFFFully opaque whiteSample Text
Black0xFF000000Fully opaque blackSample Text
Red0xFFFF0000Fully opaque redSample Text
Green0xFF00FF00Fully opaque greenSample Text
Blue0xFF0000FFFully opaque blueSample Text
Yellow0xFFFFFF00Fully opaque yellowSample Text
Purple0xFF9900FFFully opaque purpleSample Text
Gold0xFFFFAA00Fully opaque orange/goldSample Text
Aqua0xFF55FFFFFully opaque aquaSample Text
Gray0xFF808080Fully opaque graySample Text
Dark Gray0xFF404040Fully opaque dark graySample Text
Light Gray0xFFCCCCCCFully opaque light graySample Text
Transparent0x00000000Fully transparentInvisible
Semi-Black0x8000000050% transparent black50% Transparent
Format breakdown:
AA = Alpha (transparency): 00 = invisible, FF = opaque
RR = Red component: 00 to FF
GG = Green component: 00 to FF
BB = Blue component: 00 to FF

12. Troubleshooting

GUI doesn't appear

Scripts don't execute

Progress bars don't update

Context not persisting

Elements misaligned

Additional Resources