Pattern recipes
Concept: how to read recipes
A recipe is an example that combines the earlier rules (files, modification, bindings, expressions, collections, hosts) for one purpose. Names such as myui and myui:v1 are examples, and the code was newly written for this guide or is a reduction of MIT-licensed bedrock-core and AdvancementPack samples. The code of this chapter itself was not run again in game. Examples confirmed in game are in Design docs and example add-ons. Each recipe is written in the order one-line summary rule (PAT-nn), basis rules, code, cautions, and by following the basis rule IDs to those rules' verification levels you can gauge reliability.
Common premise: a new UI file is read only if its path (relative to the resource pack root, usually starting with ui/) is registered in the ui_defs array of ui/_ui_defs.json. Files at the same path as vanilla (ui/server_form.json, ui/hud_screen.json) are modified without registration, and in that case modifications is used to add and remove controls and bindings in vanilla definitions. A registration example is as follows (the same format as the MS Learn ui_defs document, Source: ms-learn).
{ "ui_defs": [ "ui/myui/screen.json", "ui/myhud/toast.json" ] }
Recipe 1. Showing your own screen with a server form (minimal setup)
- [PAT-01] The minimal setup of an action form custom screen is (1) hide vanilla
long_formandcustom_formby a title prefix, (2) put a second factory that usesserver_form_factoryintomain_screen_content, and (3) make your own screen.{code (source), working pack}(Source: BC 4.1-(1), BA chapter 2, VN server_form.json)
Basis: MOD-02, MOD-08, HOST-02~05, COL-14
// RP/ui/server_form.json: the same path as vanilla. Mostly modifications (only the size line overrides a property)
{
"namespace": "server_form",
"long_form": { "modifications": [ { "array_name": "bindings", "operation": "insert_back", "value": [
{ "binding_name": "#title_text" },
{ "binding_type": "view",
"source_property_name": "(not (('%.7s' * #title_text) = 'myui:v1'))",
"target_property_name": "#visible" } ] } ] },
"custom_form": { "modifications": [ { "array_name": "bindings", "operation": "insert_back", "value": [
{ "binding_name": "#title_text" },
{ "binding_type": "view",
"source_property_name": "(not (('%.7s' * #title_text) = 'myui:v1'))",
"target_property_name": "#visible" } ] } ] },
"main_screen_content": {
"size": [ "100%", "100%" ], // Vanilla is [0, 0]. So that my screen receives a size
"modifications": [ { "array_name": "controls", "operation": "insert_back", "value": [
{ "myui_bridge": { "type": "panel", "size": [ "100%", "100%" ],
"factory": { "name": "server_form_factory",
"control_ids": { "long_form": "@myui.root" } } } } ] } ]
}
}
// RP/ui/myui/screen.json (registered in _ui_defs.json)
{
"namespace": "myui",
"root": {
"type": "panel", "size": [ 260, 180 ],
"bindings": [
{ "binding_name": "#title_text" },
{ "binding_type": "view",
"source_property_name": "(('%.7s' * #title_text) = 'myui:v1')",
"target_property_name": "#visible" } ],
"controls": [
{ "bg@common.common_panel": {} },
{ "buttons": { "type": "stack_panel", "size": [ "100% - 16px", "100%c" ], "offset": [ 0, 24 ],
"anchor_from": "top_middle", "anchor_to": "top_middle",
"collection_name": "form_buttons",
"controls": [
{ "b0@myui.press_cell": { "collection_index": 0 } },
{ "b1@myui.press_cell": { "collection_index": 1 } } ] } } ]
}
}
Cautions
- The base of
long_form(common_dialogs.main_panel_no_buttons) has nobindings, so putting intobindingsdoes not hide an inherited array (MOD-04, VN ui_template_dialogs.json:205). main_screen_content.sizeis a property override, so unless other packs also use the same value, the later pack's value remains. Most write100%equally.- If it will often be used with UI packs, consider the wrapping approach (HOST-04 (b)).
- Script:
new ActionFormData().title('myui:v1').button('a').button('b').
Complete files and the order of execution
Two files and one script line make one set. The press_cell used in the screen.json above is defined in recipe 2, so to experiment with this recipe alone, add the definition below to the myui namespace of screen.json.
// Add to RP/ui/myui/screen.json (the cell b0 and b1 use)
"press_cell@common_buttons.light_text_button": {
"size": [ "100%", 24 ],
"$pressed_button_name": "button.form_button_click",
"$button_text": "#form_button_text",
"$button_text_binding_type": "collection",
"$button_text_grid_collection_name": "form_buttons",
"bindings": [ { "binding_type": "collection_details", "binding_collection_name": "form_buttons" } ]
}
// RP/ui/_ui_defs.json (register my screen file. server_form.json is a vanilla path so it is not registered)
{ "ui_defs": [ "ui/myui/screen.json" ] }
// BP/scripts/main.js
import { world } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";
world.afterEvents.playerSpawn.subscribe(({ player, initialSpawn }) => {
if (!initialSpawn) return;
new ActionFormData().title("myui:v1").button("a").button("b").show(player)
.then((r) => { if (!r.canceled) player.sendMessage(`Pressed index: ${r.selection}`); });
});
Step explanation
- The script opens an action form with the title
myui:v1. The 7-byte prefix is the front of the title. - The engine opens vanilla
third_party_server_screen, andserver_form_factorycreateslong_form. With the pack's addedbindings, when the prefix ismyui:v1,long_formhas#visiblefalse and hides (HOST-04 a). - The second factory put into
main_screen_contentcreates@myui.rootfrom the same form data (HOST-05).rootshows only when the prefix matches. - The
stack_panelinsiderootdeclarescollection_name: form_buttons, and the childrenb0andb1take buttons 0 and 1 withcollection_index. - When pressed, the
button.form_button_clickmapping sends the form response and the script receivesselection. Withoutcollection_details,canceledarrives (COL-04).
Recipe 2. A pressable cell and a cell that reads a value
- [PAT-02] For a pressable cell, put
collection_details+ theform_button_clickmapping on the button itself, and for a cell that draws a value, put acollectionbinding on the label itself.{measured, vanilla, code (source)}(Source: BC-S1, BC-S7, BC 4.1-(3) and (4), VN server_form.json:211-246)
Basis: COL-04, BND-04, INP-04, TXT-01
"press_cell@common_buttons.light_text_button": {
"size": [ "100%", 24 ],
"$pressed_button_name": "button.form_button_click",
"$button_text": "#form_button_text",
"$button_text_binding_type": "collection",
"$button_text_grid_collection_name": "form_buttons",
"bindings": [ { "binding_type": "collection_details", "binding_collection_name": "form_buttons" } ]
},
"value_cell": {
"type": "label", "size": [ "100%", 10 ], "text": "#entry_value", "localize": false,
"bindings": [
{ "binding_type": "collection_details", "binding_collection_name": "form_buttons" },
{ "binding_name": "#form_button_text", "binding_name_override": "#entry_value",
"binding_type": "collection", "binding_collection_name": "form_buttons" } ]
}
- The value cell also has
collection_detailsbut no mapping, so it cannot be pressed (the same form as the BC text carrier). Alabelreference readscollection_indexgiven directly (COL-02), but this example wraps the value cell in a panel and gives the index to the panel reference. - Even when you use a value cell, the script sends that entry with
button()(COL-19). A value cell has no mapping so it is not pressed. - The template variable names (
$button_text_binding_type, etc.) can differ by vanilla button template version, so check them in VNui_template_buttons.json.
Complete files and the order of execution
// RP/ui/myui/cells.json (register "ui/myui/cells.json" in _ui_defs.json)
{
"namespace": "myui",
"press_cell@common_buttons.light_text_button": {
"size": [ "100%", 24 ],
"$pressed_button_name": "button.form_button_click",
"$button_text": "#form_button_text",
"$button_text_binding_type": "collection",
"$button_text_grid_collection_name": "form_buttons",
"bindings": [ { "binding_type": "collection_details", "binding_collection_name": "form_buttons" } ]
},
// Value cell: wrap it in a panel and give collection_index to the panel reference
"value_cell": {
"type": "panel", "size": [ "100%", 10 ],
"controls": [ { "value_label": {
"type": "label", "size": [ "100%", 10 ], "text": "#entry_value", "localize": false,
"bindings": [
{ "binding_type": "collection_details", "binding_collection_name": "form_buttons" },
{ "binding_name": "#form_button_text", "binding_name_override": "#entry_value",
"binding_type": "collection", "binding_collection_name": "form_buttons" } ] } } ]
},
"panel_with_cells": {
"type": "stack_panel", "size": [ "100%", "100%c" ], "collection_name": "form_buttons",
"controls": [
{ "press0@myui.press_cell": { "collection_index": 0 } }, // Pressable cell (button 0)
{ "value1@myui.value_cell": { "collection_index": 1 } } ] // Value cell (only reads the text of button 1)
}
}
new ActionFormData().title("myui:v1").button("Open menu").button("Current score 120").show(player);
Step explanation
- The script sends the value with
button()too. So each entry takes up one number (COL-19). Nothing happens when a value entry is pressed. press_cellhascollection_detailsand theform_button_clickmapping on itself, so the press returns asselection(COL-04, INP-04).value_cellhascollection_detailsbut no mapping, so it is not pressed. It only renames#form_button_textto#entry_valueand the label draws it.- If you put the two cells in the same
form_buttonsstack, the numbers are kept as they are. If the pressable cell is put first, the button number does not change even when the number of value characters changes (HOST-07).
Recipe 3. Reading one value in several places (data source)
- [PAT-03] Put one size-0 data source control at the screen root, and have the gates read that value with a
source_control_nameview binding.{code (source)}(Source: BC 4.1-(5), BC-samples home.document.json)
"flag_source_host": { "type": "stack_panel", "size": [ 0, 0 ], "collection_name": "form_buttons",
"controls": [ { "flag_source": { "type": "panel", "size": [ 0, 0 ], "collection_index": 3,
"property_bag": { "#entry_value": "f" },
"bindings": [ { "binding_name": "#form_button_text", "binding_name_override": "#entry_value",
"binding_type": "collection", "binding_collection_name": "form_buttons" } ] } } ] },
"gated_panel": { "type": "panel", "visible": "#visible", "property_bag": { "#visible": false },
"bindings": [ { "binding_type": "view", "source_control_name": "flag_source",
"source_property_name": "(not (('%.2s' * #entry_value) = 'f'))",
"target_property_name": "#visible" } ] }
Complete files and the order of execution
// RP/ui/myui/datasource.json (registered in _ui_defs.json, root is mounted by recipe 1's server_form.json)
{
"namespace": "myui",
"root": {
"type": "panel", "size": [ 260, 180 ],
"controls": [
// 1) Data source: size 0, directly under the screen root
{ "flag_source_host": { "type": "stack_panel", "size": [ 0, 0 ], "collection_name": "form_buttons",
"controls": [ { "flag_source": { "type": "panel", "size": [ 0, 0 ], "collection_index": 3,
"property_bag": { "#entry_value": "f" },
"bindings": [ { "binding_name": "#form_button_text", "binding_name_override": "#entry_value",
"binding_type": "collection", "binding_collection_name": "form_buttons" } ] } } ] } },
// 2) Gate: read the data source by name to decide #visible
{ "gated_panel": { "type": "panel", "visible": "#visible", "property_bag": { "#visible": false },
"controls": [ { "msg": { "type": "label", "text": "The flag is not f", "localize": false } } ],
"bindings": [ { "binding_type": "view", "source_control_name": "flag_source",
"source_property_name": "(not (('%.2s' * #entry_value) = 'f'))",
"target_property_name": "#visible" } ] } } ]
}
}
// Buttons 0~2 are for the screen, and the 3rd (index 3) is the flag 't' or 'f'
new ActionFormData().title("myui:v1").button("a").button("b").button("c").button("t").show(player);
Step explanation
- The script sends the flag as the text of the last button (
torf). flag_sourcereceives the text of entry 3 as#entry_value. It is size 0 so it is invisible.- The gates read that value with
source_control_name: flag_sourceand decide#visiblewith one expression. Even if several gates read the same value, the entry binding is in one place. - A one-character value is compared with
%.2s(length+1) (EXP-08, EXP-15). The expression above shows when the flag is notf.
Recipe 4. Creating only the chosen screen (computed length factory)
- [PAT-04] Instead of
visible, gate with a factory that computes#collection_lengthand creates nothing when it is 0.{measured}(Source: BC-S11, BC-S8)
Basis: COL-10, COL-11, BND-07, EXP-19
"settings_gate": {
"type": "collection_panel", "size": [ "100%", "100%" ],
"factory": { "name": "settings_cell", "control_name": "myui.settings_screen" },
"bindings": [
{ "binding_name": "#title_text", "binding_condition": "always" },
{ "binding_type": "view", "binding_condition": "always",
"source_property_name": "((#title_text = 'myui:v1:settings') * 1)",
"target_property_name": "#collection_length" } ]
}
- Give
binding_condition: "always"to the bindings that read entries inside a cell (BND-07). - When there are many screens, you can route with one
property_bagdictionary lookup as in BC (HOST-06, measurement needed).
Complete files and the order of execution
// RP/ui/myui/gate.json (registered in _ui_defs.json)
{
"namespace": "myui",
"settings_screen": {
"type": "panel", "size": [ 260, 180 ],
"controls": [ { "title": { "type": "label", "text": "Settings screen", "localize": false } } ]
},
"settings_cell": { // The cell the factory creates 0 or 1 of
"type": "panel", "size": [ "100%", "100%" ],
"controls": [ { "screen@myui.settings_screen": {} } ]
},
"settings_gate": {
"type": "collection_panel", "size": [ "100%", "100%" ],
"factory": { "name": "settings_cell", "control_name": "myui.settings_cell" },
"bindings": [
{ "binding_name": "#title_text", "binding_condition": "always" },
{ "binding_type": "view", "binding_condition": "always",
"source_property_name": "((#title_text = 'myui:v1:settings') * 1)",
"target_property_name": "#collection_length" } ]
}
}
The main_screen_content factory of recipe 1 mounts @myui.settings_gate (point long_form in control_ids at this gate). The script opens it with new ActionFormData().title("myui:v1:settings").
Step explanation
- If the title is exactly
myui:v1:settings, the expression((#title_text = '…') * 1)is 1 (true). Otherwise it is 0. - This value goes into
#collection_lengthand the factory creates 1 or 0 cells. If 0, the screen's controls are not created at all, so it is lighter thanvisible: false(COL-10, COL-11). - Give
binding_condition: "always"to bindings that read entries inside a cell to avoid the timing problem of factory cell bindings (BND-07). - If there are several screens, place several gates or pick from one with the dictionary lookup of HOST-06.
Recipe 5. Taking fields out of a fixed-width record
- [PAT-05] Carry byte-width-fixed fields like
[kind 5][number 4][title …]in one entry string, and take them out by cutting, subtracting, cutting again, then removing padding.{working pack}(Source: BA chapter 3, AP 4.5)
Basis: EXP-09, EXP-11, EXP-12, EXP-15
The value the script sends (padding '$', the number field has a letter prefix)
ITEM|N007Title$$$$$$$$$$$$$$$$$
0 5 9 (byte offsets)
"bindings": [
{ "binding_name": "#form_button_text", "binding_name_override": "#raw",
"binding_type": "collection", "binding_collection_name": "form_buttons" },
{ "binding_type": "view", "source_property_name": "(('%.5s' * #raw) = 'ITEM|')", "target_property_name": "#is_item" },
{ "binding_type": "view", "source_property_name": "('%.9s' * #raw)", "target_property_name": "#head9" },
{ "binding_type": "view", "source_property_name": "('%.5s' * #raw)", "target_property_name": "#head5" },
{ "binding_type": "view", "source_property_name": "('%.4s' * (#raw - #head5))", "target_property_name": "#num" },
{ "binding_type": "view", "source_property_name": "((#raw - #head9) - '$')", "target_property_name": "#title" },
{ "binding_type": "view", "source_property_name": "('myui.item.' + #num)", "target_property_name": "#title_key" }
]
- Do not strip the letter prefix of the number and attach it to the key as is (
myui.item.N007). If you strip the prefix,007could be interpreted as a number (EXP-15). - A Hangul title is 3 bytes per character, so the encoder pads with UTF-8 bytes.
#raw - #head9removes every string equal to#head9, so design it so that the head part does not appear again in the body.
Complete files and the order of execution
// RP/ui/myui/record.json (registered in _ui_defs.json)
{
"namespace": "myui",
"record_cell": {
"type": "panel", "size": [ "100%", 14 ],
"controls": [ { "title_label": { "type": "label", "text": "#title", "localize": true, "size": [ "100%", 10 ] } } ],
"bindings": [
{ "binding_type": "collection_details", "binding_collection_name": "form_buttons" },
{ "binding_name": "#form_button_text", "binding_name_override": "#raw",
"binding_type": "collection", "binding_collection_name": "form_buttons" },
{ "binding_type": "view", "source_property_name": "(('%.5s' * #raw) = 'ITEM|')", "target_property_name": "#is_item" },
{ "binding_type": "view", "source_property_name": "('%.9s' * #raw)", "target_property_name": "#head9" },
{ "binding_type": "view", "source_property_name": "('%.5s' * #raw)", "target_property_name": "#head5" },
{ "binding_type": "view", "source_property_name": "('%.4s' * (#raw - #head5))", "target_property_name": "#num" },
{ "binding_type": "view", "source_property_name": "((#raw - #head9) - '$')", "target_property_name": "#title" },
{ "binding_type": "view", "source_property_name": "('myui.item.' + #num)", "target_property_name": "#title_key" },
{ "binding_type": "view", "source_property_name": "#is_item", "target_property_name": "#visible" } ]
}
}
// BP/scripts/encode.js : an encoder that pads in bytes (Hangul is 3 bytes)
const enc = new TextEncoder();
export function pad(str, bytes) { // Fill the missing bytes with '$'
const n = bytes - enc.encode(str).length;
return str + "$".repeat(Math.max(0, n));
}
export function itemRecord(num, title) { // [kind 5][number 4][title …]
return "ITEM|" + "N" + String(num).padStart(3, "0") + pad(title.replace(/[$|]/g, ""), 20);
}
// new ActionFormData().title("myui:v1").button(itemRecord(7, "Title")).show(player);
Step explanation
- In the record
ITEM|N007Title$$$…, the first 5 bytes are the kind, the next 4 bytes are the number (N007, a letter prefix avoids number conversion, EXP-15), and the rest is the body. - The UI cuts the first 5 bytes with
'%.5s' * #raw, erases that part with#raw - #head5, and cuts 4 bytes again with'%.4s'to get the number. For the title it erases the first 9 bytes#head9and erases the padding$. - Attach the number to
#title_keyto make the lang keymyui.item.N007(assembling lang keys in the TXT rules). - The script removes
$and|from the body in advance, so padding and delimiters do not mix with the body (HOST-08).
Recipe 6. Numbers to pixel positions (bit spacers)
- [PAT-06] Stack power-of-two size spacers in a vertical stack and turn each on and off with a bit token, and the sum of the sizes of the spacers that are on becomes the y coordinate. The number of controls grows by the bit count, so page when there are many items.
{working pack}(Source: BA chapter 4)
Basis: LAY-04, LAY-05, HOST-09, COL-18
"pos_y": { "type": "stack_panel", "orientation": "vertical", "size": [ 1, "100%c" ],
"controls": [
{ "y2": { "type": "panel", "size": [ 1, 4 ], "bindings": [ /* #visible if it contains '~Yc' */ ] } },
{ "y1": { "type": "panel", "size": [ 1, 2 ], "bindings": [ /* '~Yb' */ ] } },
{ "y0": { "type": "panel", "size": [ 1, 1 ], "bindings": [ /* '~Ya' */ ] } },
{ "node@myui.node": {} } ] }
// Each spacer: { "binding_type": "view",
// "source_property_name": "(not ((#raw - '~Yc') = #raw))", "target_property_name": "#visible" }
- If dynamic position is not strictly needed, pre-drawn images or hand-written row and column stacks are much cheaper (AP 4.6).
- If the value is a single number, the method of binding the size of one spacer (LAY-05, LAY-10) is simpler.
Complete files and the order of execution
// RP/ui/myui/bitpos.json (registered in _ui_defs.json). Pushes a label node 0~7 pixels down in y.
{
"namespace": "myui",
"bit_spacer": { // A spacer that receives $bit_token and turns on and off
"type": "panel",
"bindings": [ { "binding_type": "view",
"source_property_name": "(not ((#raw - $bit_token) = #raw))", "target_property_name": "#visible" } ]
},
"pos_y": {
"type": "stack_panel", "orientation": "vertical", "size": [ 1, "100%c" ],
"controls": [
{ "y2@myui.bit_spacer": { "size": [ 1, 4 ], "$bit_token": "~Yc" } },
{ "y1@myui.bit_spacer": { "size": [ 1, 2 ], "$bit_token": "~Yb" } },
{ "y0@myui.bit_spacer": { "size": [ 1, 1 ], "$bit_token": "~Ya" } },
{ "node": { "type": "label", "text": "Node", "localize": false } } ]
}
}
#raw is the string this control or its parent received (for example the value of the form entry #form_button_text bound as #raw). For y = 5 (bits a and c), the script puts ~Ya~Yc in the string.
function yTokens(y) { return [0,1,2].filter(i => y & (1 << i)).map(i => "~Y" + "abc"[i]).join(""); }
// new ActionFormData().title("myui:v1").button("Title" + yTokens(5)).show(player);
Step explanation
- Stack spacers of height 1, 2 and 4 in a vertical stack. Each spacer shows only when its own bit token is contained in the string (HOST-09, EXP-07).
- The sum of the heights of the spacers that are on becomes the y coordinate of the
nodebelow them (5 = 4 + 1). - Controls grow by the bit count. Page when there are many items. If the value is a single number, the method of binding the spacer size (LAY-05, LAY-10) is simpler.
| id | Source | License | Commit | Accessed |
|---|---|---|---|---|
repo-guide | JSON UI comprehensive guide (this repository) (guide/) | This project's material | 2026-11-13 | |
repo-bedrock-core | bedrock-core UI analysis (this repository) (bedrock-core/) | This project's material | 2026-11-13 | |
private-research | Private research (-) | - | 2026-11-13 | |
advancementpack | AdvancementPack (r4isen1920) | MIT (confirmed in the repository LICENSE, Copyright 2024 r4isen1920) | 0a79929 (analyzed v4.2, researched 2026-10-20) | 2026-11-13 |
bedrock-samples | Mojang bedrock-samples | Minecraft EULA applies, (c) Mojang AB. All rights reserved | 15701fa9 (guide baseline 46ba6ea) | 2026-11-13 |
repo-multiselect | Modal form multiselect research (this repository) (server-form-multiselect/) | This project's material | 2026-11-13 | |
ms-learn | Minecraft Creator documentation (Microsoft Learn) | CC BY 4.0 (documentation), MIT (code) | a9fd1c0 | 2026-11-13 |
repo-survey | JSON UI material survey (this repository) (survey/) | This project's material | 2026-11-13 |