Skip to main content

Building chest UIs and inventory menus

"Chest UI" means two methods. The form method draws a script ActionFormData as a chest through a resource pack; no items move and the slots are only buttons. The real container method opens the chest window of an invisible entity, and the engine draws the real items in its slots. This page gathers only the facts needed to choose one and build it.

When to use it​

GoalMethodWhen it does not fit, and the alternative
A screen with nothing put in or taken out, such as a shop or a choice menu, opened directly by the scriptForm method (ActionFormData reskin)If icons of custom items from other packs are needed, the entity inventory menu
Real items move, as in storage or tradingReal container (entity chest)None. A form cannot move items
Draw any item icon (custom, other packs, 3D, glint) and change content without closingEntity inventory menu (InvUI): an entity chest screen redrawn by a resource pack as a menuIf it must open with no player action, the form method
A script forces a chest window open for a playerNot possible on the release {code}The form method, or the virtual container of the 26.70 preview (version conditions)
Show item icons on the HUDOutside this guideShowing server data on the HUD

The two methods differ as follows.

TopicForm methodEntity inventory menu
OpeningThe script opens it directlyOne player action, pressing the entity, is needed
IconsTexture path or numeric item IDThe engine draws the slot items. No numbers are needed
Changing contentClose and reopen the formSlot changes by the script show at once in the open screen
Input that reaches the scriptButton indexSlot actions only. Buttons are imitated with slot moves
Text, conditions, barsPassed as form textPassed as slot item names, lore and durability

Minimal example​

A menu with nine hotbar swap buttons on one entity chest slot. A player whose 36 inventory slots are all full can still press them. It comes from the example add-on hotbar-swap-buttons v1.0.0 (measured in a Windows 1.26.65.1 local world). The entity and UI files are the add-on's as they are, without the comparison drop button and the launcher item, and main.js keeps only the swap button part of the add-on script. Use the add-on's manifests (the behavior pack depends on the resource pack uuid and @minecraft/server 2.0.0, and scripts/main.js is the entry).

Download: [bedrock-research]hotbar-swap-buttons_v1.0.0.mcaddon
[bedrock-research]hotbar-swap-buttons v1.0.0 · 6.4 KB · Test item bwiki:hotbar_swap_buttons

bp/entities/hotbar_swap_buttons_box.json:

{
"format_version": "1.21.90",
"minecraft:entity": {
"description": {
"identifier": "bwiki:hotbar_swap_buttons_box",
"is_spawnable": false,
"is_summonable": true
},
"components": {
"minecraft:inventory": {
"container_type": "container",
"inventory_size": 27,
"private": false,
"can_be_siphoned_from": false
},
"minecraft:collision_box": { "width": 1.2, "height": 1.2 },
"minecraft:physics": { "has_gravity": false, "has_collision": false },
"minecraft:pushable": { "is_pushable": false, "is_pushable_by_piston": false },
"minecraft:damage_sensor": { "triggers": { "cause": "all", "deals_damage": "no" } },
"minecraft:health": { "value": 1, "max": 1 }
}
}
}

bp/scripts/main.js:

import { world, system, ItemStack } from "@minecraft/server";

const BOX = "bwiki:hotbar_swap_buttons_box";
const TITLE = "Hotbar Swap Buttons";
const SWAP_MARK = "Swap button";
const SWAP_SLOT = 0;

const sessions = new Map();

const inventory = (entity) => entity.getComponent("inventory")?.container;
const say = (player, text) => player.sendMessage(`[HSB] ${text}`);

function marked(typeId, mark, line) {
const item = new ItemStack(typeId, 1);
item.nameTag = `${mark}: ${line}`;
return item;
}

const isMark = (item, mark) => item?.nameTag?.startsWith(`${mark}: `) ?? false;

function spotInFront(player) {
const view = player.getViewDirection();
const loc = player.location;
return { x: loc.x + view.x * 2, y: loc.y + 0.2, z: loc.z + view.z * 2 };
}

function startSession(player) {
const old = sessions.get(player.id);
if (old?.box.isValid) old.box.remove();
const box = player.dimension.spawnEntity(BOX, spotInFront(player));
box.nameTag = TITLE;
inventory(box).setItem(SWAP_SLOT, marked("minecraft:paper", SWAP_MARK, "not pressed"));
sessions.set(player.id, { box, swaps: 0 });
say(player, "Box spawned in front of you. Use it to open the screen.");
}

function watchSwap(player, session) {
const storage = inventory(session.box);
if (isMark(storage.getItem(SWAP_SLOT), SWAP_MARK)) return;
const bag = inventory(player);
for (let k = 0; k < 9; k++) {
if (!isMark(bag.getItem(k), SWAP_MARK)) continue;
const other = storage.getItem(SWAP_SLOT);
session.swaps += 1;
bag.setItem(k, other);
storage.setItem(SWAP_SLOT, marked("minecraft:paper", SWAP_MARK, `slot_${k + 1} pressed, total ${session.swaps}`));
say(player, `button.slot_${k + 1} pressed.`);
return;
}
storage.setItem(SWAP_SLOT, marked("minecraft:paper", SWAP_MARK, "lost and restored"));
}

system.runInterval(() => {
for (const player of world.getAllPlayers()) {
const session = sessions.get(player.id);
if (!session) continue;
if (!session.box.isValid) {
sessions.delete(player.id);
continue;
}
watchSwap(player, session);
}
}, 1);

system.afterEvents.scriptEventReceive.subscribe((event) => {
const player = event.sourceEntity;
if (player?.typeId !== "minecraft:player") return;
if (event.id === "bwiki:hotbar_swap_buttons") system.run(() => startSession(player));
});

rp/entity/hotbar_swap_buttons_box.entity.json:

{
"format_version": "1.10.0",
"minecraft:client_entity": {
"description": {
"identifier": "bwiki:hotbar_swap_buttons_box",
"materials": { "default": "entity_alphatest" },
"textures": { "default": "textures/entity/minecart" },
"geometry": { "default": "geometry.bwiki.hotbar_swap_buttons_empty" },
"render_controllers": [ "controller.render.default" ]
}
}
}

rp/models/entity/hotbar_swap_buttons_box.geo.json:

{
"format_version": "1.12.0",
"minecraft:geometry": [
{
"description": {
"identifier": "geometry.bwiki.hotbar_swap_buttons_empty",
"texture_width": 16,
"texture_height": 16,
"visible_bounds_width": 1,
"visible_bounds_height": 1,
"visible_bounds_offset": [ 0, 0.5, 0 ]
},
"bones": [ { "name": "root", "pivot": [ 0, 0, 0 ] } ]
}
]
}

rp/ui/_ui_defs.json:

{
"ui_defs": [
"ui/hsb_box.json"
]
}

rp/ui/chest_screen.json:

{
"namespace": "chest",

"small_chest_panel": {
"modifications": [
{
"array_name": "controls",
"operation": "insert_back",
"value": [ { "hsb_box_overlay@hsb_box.overlay": {} } ]
}
]
}
}

rp/ui/hsb_box.json:

{
"namespace": "hsb_box",

"face": {
"type": "image", "texture": "textures/ui/White", "size": [ "100%", "100%" ], "layer": 40, "color": "$face_color", "alpha": 0.85,
"controls": [
{ "n": { "type": "label", "layer": 41, "localize": false, "color": [ 1, 1, 1 ], "text": "$n", "font_scale_factor": 0.8 } }
]
},

"slot_button": {
"type": "button", "size": [ 18, 18 ], "anchor_from": "top_left", "anchor_to": "top_left", "focus_enabled": false,
"default_control": "default", "hover_control": "hover", "pressed_control": "pressed",
"bindings": [ { "binding_type": "collection_details", "binding_collection_name": "container_items" } ],
"button_mappings": [
{ "from_button_id": "button.menu_select", "to_button_id": "$to", "mapping_type": "pressed", "consume_event": false },
{ "to_button_id": "button.container_slot_hovered", "mapping_type": "pressed" }
],
"controls": [
{ "default@hsb_box.face": { "$face_color": [ 0.2, 0.25, 0.55 ] } },
{ "hover@hsb_box.face": { "$face_color": [ 0.3, 0.45, 0.85 ] } },
{ "pressed@hsb_box.face": { "$face_color": [ 0.2, 0.7, 0.3 ] } }
]
},

"slot_name": {
"type": "label", "size": [ 160, 10 ], "layer": 40, "localize": false, "color": [ 0.1, 0.1, 0.1 ], "text": "#text",
"anchor_from": "top_left", "anchor_to": "top_left",
"bindings": [
{ "binding_type": "collection", "binding_collection_name": "container_items", "binding_name": "#hover_text", "binding_condition": "always" },
{ "binding_type": "view", "source_property_name": "('slot: ' + #hover_text)", "target_property_name": "#text" }
]
},

"cell": {
"type": "stack_panel", "collection_name": "container_items", "size": [ 18, 18 ], "anchor_from": "top_left", "anchor_to": "top_left",
"controls": [ { "b@hsb_box.slot_button": { "collection_index": "$i" } } ]
},

"name_cell": {
"type": "stack_panel", "collection_name": "container_items", "size": [ 170, 10 ], "anchor_from": "top_left", "anchor_to": "top_left",
"controls": [ { "t@hsb_box.slot_name": { "collection_index": "$i" } } ]
},

"buttons": {
"type": "panel", "size": [ 280, 66 ],
"anchor_from": "top_left", "anchor_to": "top_left", "offset": [ 7, 100 ],
"controls": [
{ "s1@hsb_box.cell": { "offset": [ 0, 0 ], "$i": 0, "$to": "button.slot_1", "$n": "1" } },
{ "s2@hsb_box.cell": { "offset": [ 24, 0 ], "$i": 0, "$to": "button.slot_2", "$n": "2" } },
{ "s3@hsb_box.cell": { "offset": [ 48, 0 ], "$i": 0, "$to": "button.slot_3", "$n": "3" } },
{ "s4@hsb_box.cell": { "offset": [ 0, 24 ], "$i": 0, "$to": "button.slot_4", "$n": "4" } },
{ "s5@hsb_box.cell": { "offset": [ 24, 24 ], "$i": 0, "$to": "button.slot_5", "$n": "5" } },
{ "s6@hsb_box.cell": { "offset": [ 48, 24 ], "$i": 0, "$to": "button.slot_6", "$n": "6" } },
{ "s7@hsb_box.cell": { "offset": [ 0, 48 ], "$i": 0, "$to": "button.slot_7", "$n": "7" } },
{ "s8@hsb_box.cell": { "offset": [ 24, 48 ], "$i": 0, "$to": "button.slot_8", "$n": "8" } },
{ "s9@hsb_box.cell": { "offset": [ 48, 48 ], "$i": 0, "$to": "button.slot_9", "$n": "9" } },
{ "name0@hsb_box.name_cell": { "offset": [ 80, 4 ], "$i": 0 } }
]
},

"gate": {
"type": "panel", "size": [ "100%", "100%" ],
"ignored": "(not ($t = 'Hotbar Swap Buttons'))",
"controls": [ { "buttons@hsb_box.buttons": {} } ]
},

"overlay": {
"type": "panel", "size": [ "100%", "100%" ], "layer": 30,
"$t": "$container_title",
"controls": [ { "gate@hsb_box.gate": {} } ]
}
}

Run /scriptevent bwiki:hotbar_swap_buttons to spawn an invisible chest entity in front of you, and press that spot to open it. Pressing buttons 1 to 9 prints the pressed button in chat, changes the slot name label, and the hotbar returns to its place. This example inserts the window only into the PC screen (chest.small_chest_panel), because the hotbar swap sends no request on touch (INP-45).

Must match​

Entity chest screen​

  • The entity minecraft:inventory has container_type: "container" and private: false. Only then does it open through chest_screen.json. With inventory_size above 27 only 27 cells are drawn, but the other slots are still read by bindings (the examples use up to 243) (HOST-16).
  • Do not redeclare small_chest_screen; insert the window into the controls of chest.small_chest_panel (PC) and pocket_containers.panel (touch) with a modifications insert_back. The file paths are the vanilla ones, ui/chest_screen.json and ui/pocket_containers.json (HOST-49, MOD-02).
  • The window title $container_title is the entity nameTag. A direct comparison in a binding expression is always false (HOST-19).
  • To pick a window by name, put a copy variable "$t": "$container_title" on the parent control and compare it in the child's ignored. ignored is evaluated in the parent scope (HOST-48, FILE-34).
  • A control that reads a slot is a direct child of a stack_panel with collection_name: "container_items" and has collection_index. On a deeper child it gives Unknown property [collection_index] (COL-06).
  • Keep the sum of the pack's ancestor layer values at 94 or less for a window holding item renderers. From 99 only the icons stopped drawing (ANI-38).
  • To hide the vanilla cells, add to the bindings of each vanilla control to hide a view binding that reads #entity_ui_vanilla_visible from the marker control entity_ui_hide_vanilla, and put the marker inside the window picked with ignored. Keep these names to coexist with packs outside the wiki (MOD-08, BND-25).

Receiving presses in the script​

  • A hotbar swap button has all of: a collection_details binding, a pressed mapping from button.menu_select to button.slot_N (N is 1 to 9), and a mapping { "to_button_id": "button.container_slot_hovered", "mapping_type": "pressed" } without a source. button.slot_0 sends no request (INP-42, INP-45).
  • For several buttons on one slot, wrap each button in its own stack_panel with collection_name, and leave a 6 GUI pixel gap between buttons (INP-43).
  • A quick move button sends button.menu_select to button.container_auto_place with consume_event: false. The script counts a press when the marker item in the slot is gone.
  • With a drop button (button.drop_one), do not set the #visible of that button or its ancestors by binding. Hide its look with the #visible of a sibling, block it with #enabled or #alpha, and pick pages with ignored (INP-46).

Reading values from slots​

  • A data item that carries a value is paper with only a name, not locked (paper has no vanilla description line). Read the name with (#hover_text - '§o' - '§f' - '§r') (HOST-17).
  • A value read from a slot name that became an integer shows as text only with 'v' or '§r' in front. Durability values never show as text, so put them in the name or lore as text {measured}.
  • A real literal starts with a dot (.1). 0.1 is 0 (EXP-27). Give #clip_ratio through a binding that reads a slot value. Fixed values left the bar empty.
  • #hover_text empties for about 50 to 100 ms on every slot press, so read data slots shown on screen through a BND-18 latch and test empty slots with (#item_id_aux < 1) (HOST-50).

Item icons (form method)​

  • The #item_id_aux value is numeric ID * 65536 + data value, and the enchantment glint adds 32768 (ANI-06, ANI-23 {unverified}).
  • Convert the button icon string to a number with (#form_button_texture - 0). * 1 gives an empty string and % is not an operator (EXP-16, EXP-31, EXP-02).
{ "binding_type": "view", "source_property_name": "(#form_button_texture - 0)", "target_property_name": "#item_id_aux" }
  • Per slot, build an image when the first 8 bytes of the icon string are textures, and an inventory_item_renderer otherwise (PAT-11, PAT-14).
  • Pick the screen size with a marker at the very start of the title that puts § before every character (§c§h§e§s§t§2§7§r and so on), and do not build unused size templates, using ignored. The cells are grid + collection_name: form_buttons (PAT-14).
  • For an icon fixed in the resource pack, put #item_name (the identifier written literally) together with #item_id_aux in the property_bag. A numeric constant alone of 257 or more is read as an old numeric ID and draws a different item (ANI-51).

Slot decoration (badges over vanilla slots)​

  • Put an invisible marker starting with §k§r inside the item name and find it in the slot's #hover_text with a contains test. Example: (not ((#hover_text - '§k§l§r§1§r') = #hover_text)) * 1 {record}.
  • Insert into both slot templates with insert_front: container_item (ui_common.json) and inventory_container_item (inventory_screen.json). The slot background is layer 1 and the item 7, so a back decoration goes at 6 and a front one at 9 {record}.

Common mistakes​

SymptomCauseFix
Form slot icons are empty* 1 on the icon string. String * number is an empty string(#form_button_texture - 0) (EXP-16, EXP-31)
An Invalid expression assert when the screen opens, or a condition is ignored% was usedMake remainders with (a - ((a / b) * b)) (EXP-02, EXP-38)
A different item is drawnA numeric ID table from another version, or a number shifted by the custom item countRebuild the table for the target version and add C. Draw custom and other-pack items with texture paths or entity slots (HOST-17, C-33)
A numeric icon written in property_bag is wrongA numeric constant of 257 or more is read as an old numeric IDWrite the identifier literally in #item_name (ANI-51)
With another server form pack on, only one showsBoth redeclare long_form at the same pathSwitch to wrapping or modifications only (MOD-21)
The chest screen does not opencontainer_type is not container, or private: trueThe values of HOST-16
The vanilla chest screen opens instead of my windowAnother pack redeclared small_chest_screen, or the name was compared in a binding expressionInsert with modifications and pick with a copy variable and ignored (HOST-49, HOST-48)
Names and counts show in the window but icons do notThe ancestor layer sum is highKeep the sum at 94 or less (ANI-38)
Buttons do nothing for a player with a full inventoryQuick move sends no request when the inventory is fullHotbar swap (INP-41, INP-42)
A hotbar swap button sends no request even on PCNo collection_details or no sourceless container_slot_hovered mapping, or the target is slot_0Set all three (INP-45)
Buttons do not react on a phoneOn touch a button.slot_N target sends no requestTake touch presses with quick move or drop (INP-45)
Every slot label disappears after a dropThe #visible of the drop button or an ancestor is set by bindingUse #enabled, #alpha and ignored (INP-46)
Labels or figures flicker on every press#hover_text empties briefly on every pressBND-18 latch, empty slots by (#item_id_aux < 1) (HOST-50)
A grey grid flickers when a slot item changesThe vanilla cells were hidden with visible: falsePut a container_items grid of 27 empty panel cells behind the window (HOST-50)
A bar is always empty or always fullA decimal with a leading digit such as 0.1 or 1.0 is an integerStart with a dot such as .1 (EXP-27)
Some presses of the nine buttons get lostThe buttons touch each otherA 6 pixel gap (INP-43)
Esc or back does not close the windowbutton.menu_cancel is mapped globallyMap only the keys needed and keep a separate close button
Items come out of entity slots despite lockModeLocks work only in the player inventoryCover the slot with a toggle, or have the script restore it every tick (HOST-20)
Badges do not show on bag slotsinventory_container_item has its own controlsInsert into both templates

Version conditions​

  • Numeric item IDs (measured on 1.26.63): custom items are inserted at 853. Vanilla items at 853 and above shift by C, the custom item count of all packs; custom items start at 853, and custom blocks go down from -9745. The vanilla numbers of 1.26.6x match vanilla_items.nbt of gophertunnel 1.63.0. The boundary on other versions differs by source (C-33 is open), and the numbers themselves change (apple is 883 on 1.26.65.1 and 887 on Preview 26.70.26). A script cannot read the game version, so fit a numeric table to one target version.
  • The numeric constants in vanilla beacon_screen.json (diamond 264 and so on) are old numeric IDs. A number of 257 or more written in a property_bag is read as an old ID on world entry and rewritten to the current number, so vanilla draws them right (ANI-51). Values put in through bindings are current numbers. So do not copy these constants into bound values.
  • Opening a container screen from a script: there is no way on the release up to 1.26.63 {code}. Betas from @minecraft/server 2.13.0-beta.1.26.70-preview.24 in the 26.70 preview have world.virtualContainerManager (1 to 54 slots, needs the "Beta APIs" experiment), and its screen file is ui/virtual_container_screen.json. The changelog says this file will change and should not be edited. This wiki has not tested it in game {unverified}.
  • Custom block containers: on Windows 1.26.65 with the experiment "Upcoming Creator Features" on, a block with container: { "slot_count": 3 } in minecraft:block_entity opened a three-slot chest UI when used {measured}. It was not tested as a block menu.

How to check​

  1. Turn on the Content Log GUI in the Creator item of settings and enter the world. Check that there is no Unknown property [collection_index], UI control reference not found or Expected variable not found in ancestor tree. The Windows release client does not log Invalid expression for % expressions, so check expressions separately even when the log is clean.
  2. Newly added files and files newly registered in _ui_defs.json are read only after entering the world again. Edits to files already read apply on a UI reload. The #item_name icon conversion runs only once when entering the world (ANI-51). If the UI does not change, restart the game.
  3. Open the menu entity and check that your window appears, then open an unnamed ordinary chest and check that the vanilla screen is unchanged.
  4. Press the buttons one by one and check that the script chat or the slot name label changes. Press with a full inventory and with free slots, and on PC and on a phone, separately.
  5. After many presses, check that every slot label is still there. If they disappear, see INP-46.
  6. Compare a numeric ID icon with the same item drawn next to it through a texture path or an entity slot. To see a number range directly, draw a range such as 840 to 903 with the item-aux-probe add-on (turn other add-ons off).

Further reading​

Sources
idSourceLicenseCommitAccessed
repo-guideJSON UI comprehensive guide (this repository) (guide/)This project's material2026-11-13
private-researchPrivate research (-)-2026-11-13
repo-chest-uiChest-UI analysis (this repository) (chest-ui/)This project's material2026-11-13
chest-uiChest-UICC BY 4.0 (confirmed in the repository License file)115d95c2026-11-13
bedrock-wikiBedrock WikiCC BY 4.0 (docs/licenses/CC-BY-4.0.md in the repository)0930b392026-11-13
bedrock-samplesMojang bedrock-samplesMinecraft EULA applies, (c) Mojang AB. All rights reserved15701fa9 (guide baseline 46ba6ea)2026-11-13
repo-ore-ui-loadingOre UI loading research (this repository) (ore-ui-loading/)This project's material2026-11-13