Menus
A menu is a titled grid of up to 54 items. A menu is not an inventory: the player cannot take or put items. A click only picks an item.
v0.1.0
commands.add("kit", function(player)
local m = player.ui.menu{
title = "Trains",
items = {
{ item = "coal", name = "Steam locomotive", lore = { "right click a rail holding it" } },
{ item = "redstone", name = "High-speed electric" },
"iron_ingot", -- a bare name works, as everywhere
},
on_pick = function(p, n) -- n is the item picked, 1 up
p:give(({ "coal", "redstone", "iron_ingot" })[n])
end,
on_close = function(p) end, -- put away without picking
}
-- m:destroy() takes it down again; m:update(items) redraws it in place
end)
The rules:
- Every client draws a menu. Java (1.7 to 26.3) shows a chest. Bedrock shows a form with one button per item, labelled with
nameor the item’s name. Noplayer:supportscheck is needed. - An item is an item (see “items”) with
name,lore,color,dye,glint,skinandcount. The count shows on the stack, for a price or a quantity. on_pickmaytask.wait.- On Java the menu stays open. Destroy it in
on_pickif one pick is enough. - A Bedrock form closes on the press. Open it again for another pick.
- On Java the menu stays open. Destroy it in
menu:destroy()and a Bedrock pick do not fireon_close.menu:updatereturnsfalseafter the player closes the menu. Picks still answer by position. A Bedrock form keeps its first items.- A new menu replaces the old one.
- Only the pack that opened a menu gets its picks. The menu ends when the script ends, the player leaves, or the pack calls
destroy. - Under a Java menu, the player’s inventory shows. Clicks in it change nothing.