Drawing item icons and counts dynamically on the HUD
A panel that floats the name and icon of the block you look at and the items and counts inside a chest over the screen (like Java's WAILA and Jade) is counted as a hard feature in JSON UI. Text is easy to send, but an item icon cannot be drawn directly from a string.
To state the conclusion first: a side that knows the numeric ID of items (a custom server that sends the item list directly to the client) can draw icons and counts without touching the player inventory. The key is two things.
- The server carries the item's runtime ID x 65536 in the subtitle as fixed-width text fields.
- The pack cuts that value out of the variable the title factory provides (
$subtitle_text) and puts it in#item_id_auxofproperty_bag. Taken out through a binding, the icon drew only with an#item_id_auxdefault inproperty_bagandbinding_condition: "always"(section 3.4).
A side that does not know numeric IDs, such as a Script API add-on, still uses the inventory mirror or the texture path (section 2).
1. Why it is hard
- An item icon is drawn by giving
#item_id_auxtoinventory_item_renderer("type": "custom","renderer": "inventory_item_renderer"). The value isnumeric item ID x 65536 (+ data value)(ANI-06). A block item is drawn in 3D in the inventory, so it is hard to substitute with a single texture. - The only routes for data into the HUD are strings: title, subtitle and actionbar (HUD and titles). A number has to be taken out of that string and fed to the renderer, and this path is blocked in many places (section 4).
- Numeric IDs can differ per world because some shift when custom items are registered (ANI-06). The community's conclusion is that the Script API has no way to get an item's numeric ID directly (community report).
- Conversely, engine collections such as
container_itemsandhotbar_itemsgive#item_id_auxand#inventory_stack_countper slot (the engine collection table in the COL chapter). So public add-ons chose the route of "putting the item to show into a real inventory slot".
2. Three methods
| Method | Principle | Where it can be used | Cost |
|---|---|---|---|
| Inventory mirror | A script puts the item to show into a player inventory slot, and the pack reads that slot with a collection binding | Script API add-ons | It moves the player's real items. Backup and restore are needed |
| Carry the numeric ID in the title | The server carries runtime ID x 65536 in the subtitle as text, and the pack cuts it out of the title factory variable and puts it in the renderer | Custom servers that send the item list directly (Dragonfly, etc.) | A fixed expression must be made per cell. The format must be matched byte by byte |
| Texture path | Give the item texture path to image | Anywhere | Only a flat picture. The 3D icon of block items does not work |
2.1 Inventory mirror (the public WAILA add-on)
The script of the public WAILA add-on (r4isen1920/WAILA, MIT) serializes the items in slots 9~26 of the player inventory and backs them up to a dynamic property (split into several pieces because of the size limit), puts the item to display into those slots, and restores them later (Source: waila-r4isen1920 InventoryMirror.ts). The pack reads fixed slots of an inventory collection such as hotbar_items with collection_index and collection bindings and moves #item_id_aux and #inventory_stack_count to the renderer.
- It does not need to know numeric IDs and works with the Script API alone.
- In exchange it actually moves the player's items. If backup and restore go out of sync, items can be lost, so backup storage, handling disconnects and conflicts with other add-ons must be handled separately.
- An older version of this add-on used a renderer that read the number from the title and put it in
property_bag, and it has since been replaced by a renderer that reads the inventory (the pack'sitem_aux_rendererdefinition has a "Deprecated" comment).
2.2 Texture path
If you give an item texture path (textures/items/...) as the texture of an image, you can draw a picture similar to an icon. The community recommends it as a way to avoid the problem of aux ids shifting with version and add-ons (community report). It is a flat picture, so the shapes the renderer draws, such as block items and dyed items, do not appear.
2.3 The binding route
Putting a numeric ID taken from text into #item_id_aux through a binding expression also works.
- Server form buttons: carrying a value like
aux:65536in the button image string#form_button_textureand binding(#texture - 'aux:')to#item_id_auxworks in the Chest-UI family (PAT-11, community report). - HUD title: a row that filled the icon's
#item_id_auxand the count label's#textwith one view binding expression reading the global#hud_subtitle_text_stringdrew the same icons and counts as the title factory variable row (measured, mobile, 2026-11-16, section 3.4). The icon had#item_id_aux: 0inproperty_bagandbinding_condition: "always". Why the binding in the first setup stayed empty in every format (section 4) was not found{unverified}. A binding passes the expression result to the renderer as is, so an integer result should draw (code).
On either route, the item renderer reads #item_id_aux only when it is a JSON integer, and draws air for text or a real number (code, EXP-47). So end the expression with (... - 0) so that the final result is read back as an integer. If an intermediate result starts with a digit, a space, +, - or ., only the leading number is kept as an integer at that point and the rest of the text is dropped. This is the likely reason why zero padding in section 3.1 was not read while x padding worked (an intermediate result that starts with x stays text). Put number fields after a letter marker.
Some bindings do not exist on the HUD. #bundle_item_renderer_data, which fills bundle content slots, exists only on container screens, not on the HUD, so a bundle content slot on the HUD is never filled. This matches the measurement where that slot was empty on the HUD (code).
3. How to carry a numeric ID in the title
This is a setup built by measurement on a Dragonfly-based server (Source: private research). The server finds the block the player looks at with a ray check and sends the panel contents as title and subtitle. The pack hides the vanilla title and draws the panel in its place.
3.1 Data format
The title carries a marker prefix for the panel and the name and info lines. The pack uses the prefix to tell whether it is a panel title, and hides the vanilla title label.
The subtitle carries icons and cells at fixed widths.
| Position (bytes) | Length | Contents | Example |
|---|---|---|---|
| 0 | 1 | String marker i | i |
| 1 | 11 | Item of cell 0: runtime ID x 65536 padded with x on the left. An empty cell is xxxxxxxxxx0 | xxxxx327680 (runtime ID 5) |
| 12 | 8 | Count of cell 0: §f + number padded with ~. For 1 item, only ~ | §f12~~~ |
| 20 | 11 | Item of cell 1 | xxxxxxxxxx0 |
| 31 | 8 | Count of cell 1 | ~~~~~~~~ |
- One cell is 19 bytes (item 11 + count 8). The item of cell
nstarts at byte1 + 19nand the count at byte12 + 19n. - The pack's truncation
'%.Ns'is in bytes.§is 2 bytes, so§f12is 4 bytes. Keep the leading cells that are cut by position in ASCII, and put multibyte characters such as Hangul only at the very end. - Padding with 0 or sending a value with something added was not read as an item. Removing the padding characters (
x,~) in the pack worked. - The leading
iof the subtitle keeps the subtitle a string. Sending only a number broke the vanilla check that treats the subtitle as a string, giving gray cells and an "expected a string" warning. - A circular progress gauge in an info line is drawn with custom font glyphs: the second row of
glyph_E1(U+E110 to U+E11A) holds 11 progress frames, and the server puts the frame for the current progress into the line. The glyph is drawn at about 10 px, about 60% of an item cell, so it fits next to the icon and count{unverified}(the setup is recorded without measurement conditions).
An example of building cells on the server side (Go):
func itemField(runtimeID int32) string {
if runtimeID == 0 {
return "xxxxxxxxxx0"
}
n := strconv.Itoa(int(runtimeID) * 65536)
return strings.Repeat("x", 11-len(n)) + n
}
func countField(count int) string {
s := ""
if count > 1 {
s = "§f" + strconv.Itoa(count)
}
return s + strings.Repeat("~", 8-len(s))
}
The runtime ID is the number in the item list the server sent to the client. Dragonfly gets it with world.ItemRuntimeID(item).
3.2 Attaching to the vanilla title (ui/hud_screen.json)
The vanilla title label is hidden when it is a panel title, and the engine factory hud_title_text_factory of the same name is declared once more in root_panel (COL-14). The control this factory creates receives the title and subtitle as the variables $title_text and $subtitle_text (COL-17).
{
"namespace": "hud",
"hud_title_text": {
"modifications": [
{
"array_name": "bindings",
"operation": "insert_front",
"value": [
{ "binding_type": "global", "binding_name": "#hud_title_text_string", "binding_name_override": "#text" }
]
},
{
"array_name": "bindings",
"operation": "insert_back",
"value": [
{ "binding_type": "view", "source_property_name": "(not ('%.6s' * #text = 'panel:'))", "target_property_name": "#visible" }
]
}
]
},
"root_panel": {
"modifications": [
{
"array_name": "controls",
"operation": "insert_front",
"value": [
{
"item_hud_host": {
"type": "panel",
"size": [ "100%", "100%" ],
"factory": {
"name": "hud_title_text_factory",
"control_ids": { "hud_title_text": "panel@item_hud.panel" }
}
}
}
]
}
]
}
}
3.3 Icon and count cells (ui/item_hud.json)
The example below is a two-cell rewrite of the measured setup. The expressions and structure are the same as the measured setup, but this exact form was not tested in game.
{
"namespace": "item_hud",
"panel": {
"type": "stack_panel",
"orientation": "horizontal",
"size": [ "100%c", 18 ],
"anchor_from": "top_middle",
"anchor_to": "top_middle",
"offset": [ 0, 26 ],
"ignored": "(not ('%.6s' * $title_text = 'panel:'))",
"controls": [
{ "slot0@item_hud.slot": { "$index": 0 } },
{ "slot1@item_hud.slot": { "$index": 1 } }
]
},
"slot": {
"type": "panel",
"size": [ 18, 18 ],
"$index|default": 0,
"$aux|default": "0",
"variables": [
{
"requires": "($index = 0)",
"$aux": "((((('%.11s' * ($subtitle_text - ('%.1s' * $subtitle_text))) - 'xxxxxxxx') - 'xxxx') - 'xx') - 'x')"
},
{
"requires": "($index = 1)",
"$aux": "((((('%.11s' * ($subtitle_text - ('%.20s' * $subtitle_text))) - 'xxxxxxxx') - 'xxxx') - 'xx') - 'x')"
}
],
"controls": [
{
"icon": {
"type": "custom",
"renderer": "inventory_item_renderer",
"size": [ 16, 16 ],
"property_bag": { "#item_id_aux": "$aux" }
}
},
{
"count": {
"type": "label",
"anchor_from": "bottom_right",
"anchor_to": "bottom_right",
"font_scale_factor": 0.75,
"shadow": true,
"localize": false,
"$count|default": "",
"variables": [
{
"requires": "($index = 0)",
"$count": "((((('%.8s' * ($subtitle_text - ('%.12s' * $subtitle_text))) - '~~~~~~~~') - '~~~~') - '~~') - '~')"
},
{
"requires": "($index = 1)",
"$count": "((((('%.8s' * ($subtitle_text - ('%.31s' * $subtitle_text))) - '~~~~~~~~') - '~~~~') - '~~') - '~')"
}
],
"text": "$count"
}
}
]
}
}
Register ui/item_hud.json in _ui_defs.json (FILE-01).
How to read the expressions:
($subtitle_text - ('%.20s' * $subtitle_text))is the remainder after removing the first 20 bytes. Cutting 11 bytes from it with'%.11s' *gives the item field of cell 1 (truncation in the EXP chapter).- 'xxxxxxxx' - 'xxxx' - 'xx' - 'x'erases the padding characters. This expression, which subtracts groups of 8, 4, 2 and 1 in turn, worked in measurement.- If you put the remaining digit characters into
#item_id_auxofproperty_bag, the renderer draws that item. An empty cell becomes0(air) and draws nothing. - The count starts with
§f, so it is not converted to a number and shows as text.
3.4 When there are many cells
- This setup makes a fixed expression per cell number in advance and picks it in with
requiresofvariables. When it was built, it followed the record from a server form on the same server that variables inside a binding expression did not work (the quoted marker in BND-33), and a variable holding an expression was not computed when put inside another expression. With unquoted values, one expression that receives only the cell position works and is faster (right below, measured). With 28 cells that is 28 item expressions and 28 count expressions. Do not write them by hand: build them with a generator, and check with a test that the server's cell width constants and the pack's expressions are the same. - In a chest screen test,
$variables inside a binding expression were substituted. Using('#' + $v)(with$vset tohover_text) assource_property_nameread#hover_text. An expression with no#property at all (('§r' + $v), or a variable holding an expression used as is) left "Must define a source property name in the binding!" in the content log and that control's bindings did not work (measured, mobile, 2026-11-16). How this differs from the expressions that failed in the HUD setup above was not checked{unverified}. - The HUD did not need a fixed expression per cell either. A 6-cell subtitle read through four cell definitions drew the same icons and counts in all four rows (measured, mobile, 2026-11-16).
| Cell definition | Passed per cell | Expression |
|---|---|---|
| Section 3.3 method | $index | Per-cell fixed expressions picked with requires |
| Format string variable | "$skip_item": "%.20s" | One expression that cuts with ($skip_item * $subtitle_text) |
| Number variable | "$skip_item": 20 | One expression that cuts with (('%.' + $skip_item + 's') * $subtitle_text) |
| Binding expression | "$skip_item": "%.20s" | Reads the global #hud_subtitle_text_string and binds the same single expression through view bindings to the icon's #item_id_aux and the count label's #text |
- The single expression also goes in a variable block (
requiresis a condition that is always true). A cell instance passes only the cell position, as in{ "slot3@ns.slot": { "$skip_item": "%.58s", "$skip_count": "%.69s" } }. With N cells, the fixed expression method puts Nrequiresblocks in each cell definition, while this method has one. - In the binding expression row, the icon had
#item_id_aux: 0inproperty_bagand was bound withbinding_condition: "always". How this differs from the record in section 4 that icons were empty when taken out through a binding was not checked{unverified}. - With many cells the single expression is faster. In a HUD whose title changes every tick, 256 cells gave a screen frame rate of about 4 to 5 with fixed expressions and about 22 with one expression, and 512 cells about 1 to 2 and about 14. At 64 cells no difference could be seen (measured, mobile, 2026-11-16). The setup and method are in Binding expression caching.
- When cells of a row are empty, do not make that whole row
ignored(for example, not creating the second row when its first cell is empty).ignoredis evaluated once at creation, but when the title changes the factory recreates the controls, so it is judged again for each new title (FILE-17, COL-17).
3.5 Rules for the sending side
- Send the subtitle before the title. A subtitle that holds icons had to arrive paired with its title.
- Send the fade-in and fade-out times as 0 and the stay time long (for example 60 seconds), and resend only when the content changed. Even if unchanged, resend before the stay time ends (for example every 30 seconds).
- Only one title is visible at a time. When sending an ordinary title such as a level-up, do not send the panel until that title ends. Move text that must always be up to another channel such as a sidebar scoreboard (section 6 of HUD and titles).
- Do the gaze tracking when moving or turning (at most once per 0.1 s) and at a short interval (0.2 s), up to 6 blocks from the eyes, skipping air and liquids. A crop is judged as a box (stage+1)/8 of a block high, so a gaze passing over the empty space above a short crop reaches the block behind it. Other blocks without a collision box (flowers and so on) are judged as the whole cell. This judgment was taken to match the client crosshair but was not compared in game
{unverified}.
4. Pitfalls
| Symptom | Cause and fix |
|---|---|
| The icon is empty | The earlier #hud_subtitle_text_string binding setup left the icon empty in every form: truncation, fixed width, adding and subtracting, erasing padding characters. Taking the cell out of the title factory variable $subtitle_text and putting it into property_bag draws it. To read it through a binding, put #item_id_aux: 0 in property_bag and bind with binding_condition: "always". That setup drew the icon (section 3.4) |
| Gray cells and "expected a string" | The subtitle was sent as only a number. Put a character (i) at the front |
| Counts or digit characters do not show | Values converted to numbers did not show in the label (" 219", "1,532/4,096"). Send them in a cell that starts with §f, and to make them text in an expression use '§r' + value |
| The count expression is not computed | Put the count expression in the label's own variables. An expression put on the parent panel or ('§r' + $variable) inside text was not computed |
| A one-character flag comparison does not match | A single-digit character was converted to a number and the text comparison went wrong. Write flags as letters such as a~k, and in a variable block pick by a fixed character, not an expression |
| "Must define a source property name" | There is a view binding expression that uses no #binding at all. Keep a calculation that uses only variables as a variable, not a binding |
| Cell positions shift by one | Multibyte characters were mixed into the leading cells. Cells cut by position use only ASCII |
5. If you are a Script API add-on
- There is no public API to get the numeric ID, so using the method of section 3 needs a table connecting item names to numeric IDs. There are reports that such tables (
typeIds, etc.) shift vanilla IDs when custom items are added and go stale with every release (community report). There was also a proposal to build the table at runtime withItemTypes.getAll(), but whether that order equals the client's numeric IDs was not confirmed{unverified}. - So Script API add-ons still find the inventory mirror (section 2.1) or the texture path (section 2.2) realistic. If you use the inventory mirror, design the backup and restore of the player's items first.
Related documents
| Document | Contents |
|---|---|
| HUD and titles | Title and actionbar data channels, value preservation, the sidebar scoreboard channel |
| Images and animation | ANI-06 the item renderer and #item_id_aux |
| Collections and factories | COL-14 engine factory redeclaration, COL-17 factory variables |
| Files and definitions | FILE-17 ignored and factory variables |
| JSON UI optimization | Creation cost of panels with many cells |
| id | Source | License | Commit | Accessed |
|---|---|---|---|---|
repo-guide | JSON UI comprehensive guide (this repository) (guide/) | This project's material | 2026-11-13 | |
private-research | Private research (-) | - | 2026-11-13 | |
waila-r4isen1920 | WAILA (r4isen1920) | MIT (confirmed in the repository LICENSE, Copyright 2024 r4isen1920) | 719278f | 2026-11-14 |
bedrock-samples | Mojang bedrock-samples | Minecraft EULA applies, (c) Mojang AB. All rights reserved | 15701fa9 (guide baseline 46ba6ea) | 2026-11-13 |