Skip to content
Flint
Dokumentation
Writing scripts

Menus and UI

Chest menus with buttons and pages, boss bars, sidebars, titles and effects.

The menus module makes chest menus whose slots call your functions. You do not need an on inventory.click handler, and players cannot take items out.

import menus, items

fn open_shop(p):
    m = menus.create("<dark_green>Shop", 4)        # title, rows (1 to 6)
    m.border("black_stained_glass_pane")
    m.button(menus.slot(2, 5), items.of("bread", 16, "<gold>Bread"), buy, "bread", 10)
    m.button(menus.slot(4, 9), items.of("barrier", 1, "<red>Close"), close)
    m.open(p)

fn buy(p, type, price, click):        # click is optional: "left", "right", "shift_left"...
    menus.confirm(p, "Buy for {price} coins?", pay, type, price)

fn pay(p, type, price):
    p.give(type)

fn close(p):
    p.close_inventory()

command shop:
    executor "player"
    open_shop(sender)
  • m.button(slot, item, handler, ...args) calls handler(player, ...args) when clicked, with the click type as an optional last argument.
  • menus.slot(row, column) turns a row and column (both from 1) into a slot number.
  • m.fill(item), m.border(item), m.row(n, item) and m.column(n, item) decorate. A bare item type used as decoration has no tooltip.
  • menus.confirm(player, title, on_yes, ...args) opens a ready-made yes/no dialog.
  • m.on_open(handler) and m.on_close(handler) run when the menu opens or closes.
  • m.locked = false lets players move items; m.click_sound = none makes buttons silent.

Build a menu per player when it shows something personal (a balance, settings). Redraw an open menu in place with menus.current(player).

Pages

fn open_players(p):
    online = players.all()
    heads = []
    for other in online:
        heads.add(items.head(other, "<yellow>{other.name}"))
    m = menus.create("<dark_aqua>Players", 6)
    m.pages(heads, visit, online)              # bottom row gets previous / next buttons
    m.open(p)

fn visit(p, index, online):
    p.teleport(online[index])

Items for menus

icon = items.of("diamond_sword", 1, "<aqua>Blade")
icon.lore = ["<gray>Sharp", "<yellow>Click to buy"]
icon.glow = true                 # enchanted shine
icon.enchant("sharpness", 3)
head = items.head(player)        # a player's head

Boss bars

import bossbars

bar = bossbars.create("<yellow>Event in 30s", 1, "yellow", 10)
bar.show(players.all())
bar.progress = 0.5
bar.title = "<red>Almost!"
bar.hide()

Colours: pink, blue, red, green, yellow, purple, white. Styles: solid, 6, 10, 12, 20.

import sidebar

sidebar.show(player, "<gold><bold>MY SERVER", [
    "",
    "<gray>Coins: <yellow>{coins}",
    "<gray>Online: <green>{players.count()}",
])

Call show again to update it, and sidebar.hide(player) to remove it. Not available on Folia.

Titles, action bar and sounds

player.title("<gold>Hello!", "<gray>Have fun")
player.action_bar("<green>+5 coins")
player.sound("entity.player.levelup")
player.effect("speed", 30 seconds, 2)

Effects in the world

w = player.world
w.particle("flame", player.location, 20, 0.5)
w.sound(player.location, "entity.firework_rocket.launch")
w.lightning(player.location)            # harmless by default
w.explode(player.location, 2)           # blocks are safe unless you say otherwise
w.drop(player.location, "diamond")

Menus, boss bars and sidebars created by scripts are closed on /flint reload.