Play Strawberry Docs
Scripts

Menus and screens

Build inventory menus and screen menus with the UI script, within its limits, and see what Bedrock players get.

Two kinds of menu

The UI script (user_interface) shows a player a menu in two ways. Choose per menu: both read the same texts, live values and buttons, and both are made in the UI manager of your server's panel or as files in the script's data folder.

Inventory menu

Screen menu

What it is

A chest window drawn as your own picture, with its buttons on the window's slots

A page that fills the screen and is clickable anywhere

File

screens/<name>.json with "kind": "menu"

pages/<name>.json

Who draws it

The server, through the window's title and your server's resource pack

The Strawberry Core mod, as a real screen; on any other client it is drawn in the world in front of the player

Java clients

Every vanilla client, nothing to install

Best with the Strawberry Core mod, and it works without it

Pointer

The player's own mouse; a click is a click on a slot

The real mouse with the mod; without it the player turns to move a pointer

Bedrock players

The same chest window with the same slots

The form of its buttons

When to use which

  • An inventory menu when every player must see the same window, with or without a mod: shops, a phone, a notebook, a menu of tabs. It is as large as most of the screen, and its buttons are the chest's slots.
  • A screen menu when the layout needs the whole screen and free placement: a main menu, a map, a page of large buttons and text boxes. Players with the Strawberry Core mod get it as a real screen with their own mouse.

An inventory menu

screens/notebook.json
{"id": "notebook", "kind": "menu", "title": "Notebook", "rows": 6, "open_command": "notebook",
 "buttons": [{"id": "bank", "label": "Bank", "slot": 3, "item": "minecraft:paper",
              "model": "minecraft:air", "command": "bank"}],
 "look": {"panel": "notebook", "panel_x": -22, "panel_y": -9}}

Here images/notebook.png is 220 × 240 pixels, centred on the chest window of six rows. "model": "minecraft:air" draws nothing in the slot, so your picture shows, and the button's name still shows under the pointer.

A menu with a look shows no title text unless you draw one as a label. Its title is what Bedrock players see.

A button's name, count and lines

A button of an inventory menu, and of a dialog, can show more than one line of text:

screens/smith.json
{"id": "smith", "kind": "menu", "title": "Smith", "rows": 3,
 "buttons": [{"id": "planks", "label": {"translate": "block.minecraft.oak_planks", "color": "gold"},
              "item": "minecraft:oak_planks", "count": 16, "slot": 13,
              "tooltip": ["16 for 4 emeralds", {"text": "Restocked every morning", "color": "gray"}],
              "command": "buy planks"}]}
  • count is the number on the item, from 1 to 99. Any other value refuses the menu; it is never cut to fit. In a dialog the game writes it after the button's name, like Buy x4.
  • A label of the form {"translate": ...} is Minecraft's own name of an item or a block, so every player reads it in their own language. A menu in the data folder names item.minecraft.* and block.minecraft.* names only. text is shown where the game has no such name; color and font work as for any text.
  • tooltip is one text, or a list of up to 24 lines. In an inventory menu they are the item's lore lines. In a dialog Java players see them under the pointer; Bedrock players see no tooltip.

A scroll list

An inventory menu can hold one scroll list: an area of the chest that shows part of a longer list of buttons, with an up and a down control and a scroll bar between them.

screens/market.json
{"id": "market", "kind": "menu", "title": "Market", "rows": 6,
 "buttons": [{"id": "close", "label": "Close", "item": "minecraft:barrier", "slot": 49, "close": true}],
 "list": {"top": 0, "left": 0, "rows": 5, "columns": 8,
          "buttons": [{"id": "gem1", "label": "Gem", "item": "minecraft:emerald", "command": "buy gem1"},
                      {"id": "gem2", "label": "Big gem", "item": "minecraft:emerald", "count": 4, "command": "buy gem2"}],
          "up": {"label": "Up"}, "bar": {"thumb": "minecraft:lime_stained_glass_pane"}}}
  • top, left, rows and columns place the area: rows count from 0 at the top, columns from 0 at the left. Left out, the area starts at the top left and takes every row and the first eight columns.
  • buttons holds up to 1024 buttons, each like any button of the menu but without slot or slots: a button stands where the list shows it.
  • up and down may name a slot, an item (an arrow when left out) and a label. Without a slot they stand right of the area, in its top and bottom row.
  • bar is true (also when left out), false, or the items of its track and thumb. It fills the slots between up and down when they stand in one column.
  • A click on up or down moves the list one row, a Shift-click a whole area, and a click on the bar jumps to that place. Up and down show only when there is somewhere to go.
  • A menu with a list needs no other button, and without rows it is a whole chest.

A screen menu

pages/menu.json
{"id": "menu", "elements": [
  {"type": "block", "id": "bg", "x": 0, "y": 0, "w": 1920, "h": 1080, "color": "#101318"},
  {"type": "button", "id": "shop", "x": 710, "y": 400, "w": 500, "h": 200, "label": "Shop", "open": "shop"}
]}

A screen menu is laid out on a 1920 × 1080 screen. Its buttons can open another menu, close it, run a command or run one of your Mini-scripts.

A button that is shown but off

Set "off": true on a page button to draw it dimmed, with no hover, no click and no page_click event. off_color and off_label_color set its look, and page.set_off turns it on or off while the page is open. On Bedrock an off button is a grey line in the form.

The look of an inventory menu

Pixels count from the chest window's top left corner. The window is 176 pixels wide and 114 + 18 a row high, and the item of slot n is at x = 8 + 18 × (n % 9), y = 18 + 18 × (n / 9).

Field

What it does

panel

Your window, drawn first. One image, or one per language for words painted into it

panel_x, panel_y

The panel's top left corner, from the chest window's corner. 0 when left out

pictures

Up to 16 further images at x, y

labels

Up to 16 texts drawn with the letters of a letter sheet at x, y, aligned left, center or right. {player} and {script:key} show live values

inventory_label

hidden or shown: the game's own word "Inventory" over the player's slots. Hidden by default when the look has a panel

The canvas

Everything may reach past the chest window, inside a canvas of 320 × 240 pixels centred on the window: every client shows that much at every interface scale. x (also panel_x) runs from -72 to 247, and y (also panel_y) from T to T + 239, where T = (114 + 18 × rows - 240) / 2: -9 for six rows, -54 for one. An image lies wholly inside the canvas, and so does a label's fixed text; a label with a live value is cut at the canvas's edge.

A 220 × 240 notebook sits at panel_x -22, panel_y -9 over six rows; a 300 × 180 window at -62, 21.

"Inventory" and the band

The game writes its own word "Inventory" over every chest window, after your picture, in dark grey (#404040) at x 8, 94 pixels above the window's bottom (y 128 with six rows). With "inventory_label": "hidden" the look draws a band of exactly that grey under the word, from x 8 to 167 and from 3 pixels above that line to 8 below it (y 125 to 136 with six rows). The word is still written, in the colour it lies on, so nobody sees it. Paint your panel #404040 there, as a divider bar, and the band does not show at all.

Only this menu changes. Every other chest, furnace and inventory of the server looks as the game draws it.

Keep the band free

Nothing but the panel may lie on the band, because the word would show on it. A picture, a label, or a label with a live value anywhere on those rows (it may grow across the canvas) is refused, and the reason names the place. Move it, or set inventory_label to shown.

Images and limits

  • An image is a 32-bit RGBA PNG, not interlaced, at most 512 pixels wide, 256 high and 256 KiB. Wider than 256 it is drawn as two strips side by side: its width is even, and neither half may be fully transparent.
  • A letter sheet is a PNG of at most 256 pixels a side and 512 letters, with a JSON file that names the letter of every box.
  • A menu holds 16 pictures and 16 labels; a label holds 96 characters.
  • A server holds 63 images and 8 letter sheets, 4 MiB together. The script keeps one image of its 64 for the band.
  • An image whose top is above y 13 must be at least 13 - y pixels high: the game draws a picture of the title at most its own height above the title's line.
  • A screen menu shows pictures of at most 256 × 256; wider images are for inventory menus.

The look is drawn once the server's resource pack holds its images (/ui status says so). Until then a menu is the plain chest with the same buttons.

Buttons on the player's own slots

A menu can put buttons on the player's inventory slots under the chest: give a button lower_slot, or lower_slots for several. Slots 0 to 26 are the three rows of the main inventory and 27 to 35 the hotbar.

  • The menu then hides the player's inventory under the window ("lower": "empty"); "real" with such a button refuses the menu.
  • Every click type on such a slot is the button, and nothing is moved.
  • A Bedrock player gets such a menu as a form of its buttons.

The server decides

A look is a picture. A click sends only its slot, and the server cancels every click and drag in the menu: shift-click, number keys, double click, drop and clicks outside the window included. Nothing can be taken out of the window or put into it. What a button costs or gives is decided by the command it runs, never by the menu.

What Bedrock players get

  • Inventory menu: the same chest window with the same slots and buttons, in the game's own container look, under the menu's title. The panel, pictures, labels, band and item models are drawn by the Java client and its pack, so a Bedrock player sees each button's item (paper when it names none) with its label as the item's name. A click is the slot's, as on Java.
  • Inventory menu with a scroll list: a form of the menu's buttons with the whole list in it, which the game scrolls by itself.
  • Screen menu: the form of its buttons, or of its text boxes and the button that sends them.

You write a menu once, for Java. Nothing in a file is for one edition only.

In the UI manager

Open the settings of the UI script on your server's page in the panel. The switch at the top holds Screen menus, Inventory menus, Dialogs and HUD, with one line on what the chosen kind is.

  • The inventory menu editor shows the whole 320 × 240 canvas with the chest window in it, faint under your panel. Pictures and labels are dragged or moved with the arrow keys, inside the canvas only.
  • The menu's settings hold the panel, its place (Panel x, Panel y) and "The word "Inventory"": Hidden or Shown. The preview draws the band, or the word in the language you look at.
  • Something that lies on the band gets a red frame before you save.
  • Images and letter sheets are added under Images and letters, within the limits above.
  • A button's "Name players see" is your own text or a Minecraft name. "Count" sits under the item, and "Lines under the name" is a list you add lines to. The preview draws the count on the button's slots and the selected button's name and lines the way the game shows them.
  • "Scroll list" adds a list in the menu's free rows. "This scroll list" sets its area, up, down and bar, and says before you save when up and down have no place. "Buttons in the list" holds its buttons. In the preview, up, down and the bar move the list as they do in the game.
  • Every save is checked the way the script checks the file, and a menu that does not fit is refused whole with the reason. A saved menu is live after the script reloads it, which the panel does for you.
  • A file written by hand with a field the UI manager does not know opens to look at only, with one line that names those fields. Edit that file by hand: a save from the panel would lose them, so the panel never saves over it.
  • Only the server's owner changes menus; staff who may look get the preview.

What a chest window cannot do

  • The mouse wheel. While a chest window is open the game tells the server nothing about the wheel, so a list moves only by clicks on up, down and the bar.
  • The slot highlight. The game's highlight under the pointer shows over a button. Only a resource pack sprite for every container changes it, never one menu.

Native screens from your own script

A script can open its own screen, which the Strawberry client draws as a real game screen:

  • player.ui_screen_capable() tells whether the player's client draws it.
  • player.open_ui_screen(screen) opens it and returns its id. A screen holds at most 200 elements and 32 KiB.
  • Clicks, the close and typed values come back as the extension event UI_SCREEN.

A plain text of a screen (an element's text, the title, the page, an input's id and placeholder, an animation look's text) must not contain a control character such as a line break or a tab. The page and an input's id are not empty and have at most 64 characters; the title, a text and a placeholder at most 512. open_ui_screen answers an invalid: error that names the field.

Screen animations

player.open_ui_screen_animated(screen, animations) opens a screen with a list of UiAnimation. The client plays them at its own frame rate, and nothing more is sent while they run. An animation names an element, a trigger and two looks, from and to. A look sets any of position, size, background colour, opacity and text.

  • Open glides the element in from from, after an optional delay. With repeat it moves back and forth to to while the screen is open.
  • Hover moves a button or an input to to while the pointer is over it.
  • Click moves a button to to and back right after, while the click itself is sent at once.

Clicks and hovers are always checked against the element's real box.

  • A screen has at most 32 animations, at most 8 of them repeating, and one for each element and trigger.
  • Each way takes 2 to 200 ticks (10 to 200 when repeating), and a delay is 0 to 200 ticks. There are 20 ticks a second.
  • A list that breaks a rule answers an error that names the rule, and nothing opens.
  • player.ui_screen_animations_capable() tells whether the client plays animations. When it does not, open_ui_screen_animated answers an unavailable: error: open the same screen with open_ui_screen.

The advancements key

A script can open its own menu on a Java player's advancements key:

  • Handle the extension event ADVANCEMENTS_OPENED. Register it blocking, and the window it opens reaches the player before the server reads their next packet.
  • The client reports the key only while the player has an advancements tab. Award minecraft:story/root (criterion crafting_table) to give one.
  • player.claim_advancements_key(true) stops the Strawberry client from opening the vanilla advancements screen first; false releases it. The claim ends when the script unloads or the player leaves. The call answers false for a player whose client cannot take it.

On this page