Screens in the world
A screen is a page hung in the world: on a wall, over a spawn, flat on a table. Every player with WebGUI sees it, it is saved with the world, and players can point at it and click.
Available from WebGUI 2.7.0, on every Minecraft version the mod supports and on the Paper plugin.
Placing one
Look at a wall and run:
/webgui screen here lobby 3.2 1.8 webgui://screens/board.htmlThat puts a 3.2 by 1.8 block screen called lobby on the face you are looking at, facing out of it. Looking at nothing, it goes three blocks in front of you, facing you. On a floor or a ceiling it turns to read the right way up from where you stand.
To place one exactly:
/webgui screen add lobby 100.5 70 -20 north 3.2 1.8 https://example.com/boardThe position is the centre of the screen and takes ~ like any vanilla command. The facing is the way its face points: north, south, east, west, up or down.
The same id again replaces the screen, which is also how you move one. From the server console the position is in the main world, and ~ counts from its spawn.
| Command | What it does |
|---|---|
/webgui screen here <id> <width> <height> <url> | Place on the block you look at |
/webgui screen add <id> <pos> <facing> <width> <height> <url> | Place at a position |
/webgui screen remove <id> | Remove it |
/webgui screen list | Every screen, with where it is |
/webgui screen url <id> <url> | Show another page |
/webgui screen resolution <id> <pixels> | Page pixels per block, 16 to 512 (default 128) |
/webgui screen transparent <id> <true|false> | Let the page's own background show through |
/webgui screen interactive <id> <true|false> | Take the crosshair and clicks, or let them through (default true) (2.8.0+) |
/webgui screen emit <id> <event> [json] | Send the page an event |
Sizes go from 0.125 to 64 blocks a side. A server holds up to 256 screens.
Writing a page for a screen
A page on a screen is an ordinary page. Its size in CSS pixels is the screen's size times its resolution: a 3.2 by 1.8 screen at 320 is laid out at 1024 by 576. Use vw and vh, or a fixed layout for that size, and give it a background unless the screen is transparent.
The page can tell it is on a screen:
if (window.webgui.screen) {
// { id: "lobby", width: 3.2, height: 1.8 }
}With the client library, worldScreen() returns the same, or null on a GUI or the HUD.
Transparent screens
/webgui screen transparent <id> true makes a screen show only what its page draws. Leave the page's own background transparent:
html, body { background: transparent; }Half-transparent colours blend with whatever is behind the screen, other screens included. With no casing to show, a transparent screen shows its page from behind as well, the right way round rather than mirrored, and nothing at all while it has no page: out of range, past the player's limit, or still loading. Clicks only ever come from the front.
A player clicks a screen by pointing the crosshair at it, from up to 16 blocks away, and pressing either mouse button. The click goes to the page; the game does not swing or use an item. Hovering works too, so :hover styles show where the player is pointing.
Decorative screens
An ad, a banner or a sign in the sky should not get in the way of the world behind it. Make it decorative with:
/webgui screen interactive <id> falseThe crosshair then passes through the screen as if it were not there: its page gets no mouse movement and no clicks, and the player's attack, block breaking and item use act on the world behind it as usual. A decorative screen in front of a clickable one does not hide it either. Nothing changes in how it is drawn, and its page still receives events from the server. /webgui screen interactive <id> true makes it clickable again.
Screens are interactive unless told otherwise, so screens placed before 2.8.0 stay clickable. A player on an older client still sees a decorative screen, and can click it.
What a page on a screen may do
A screen is something the player walked past, not something they opened, so its page gets less than a GUI:
postToGameevents reach the server as usual, each with a"screen"field holding the screen's id. The client sets that field, so a page cannot pretend to be on another screen.playSoundplays only while the player is within 16 blocks of the screen.- Logging works.
- Closing the GUI, hiding the HUD, toasts, chat and commands are refused: they act on the player's own screen.
To talk back to one screen's page from the server, emit an event to it: /webgui screen emit, or WebviewApi.emitToScreen / WebGUI.emitToScreen from code. The page receives it with webgui.on(...) like any other event.
Each player gets the page's address with their own signed token, as with a GUI. A page is loaded only when the player comes near, which may be long after they joined, so the client asks the server for a fresh address first and the token is never stale.
What it costs, and the player's say in it
A page on a screen is a browser of its own, so the client keeps them few and cheap:
- only screens within 48 blocks get a page, nearest first, and at most 4 at once. Further away a screen is a dark panel;
- a page paints at up to 60 frames a second close up, 30 from 8 blocks, 15 from 24, and once a second while the player is not looking at it;
- a page is drawn with about as many pixels as it covers on the player's screen. Further away it is drawn smaller, down to a quarter of its size each way, at the same layout: the page sees no difference, and clicks land where the player points;
- all the pages in view together paint no more than the player's screen quality allows. Past that the furthest paint slower, but never below 5 frames a second;
- its picture is sent to the graphics card only while the player can see it.
Players change how many pages may run at once and their quality, or turn pages on screens off, under Mods → WebGUI → Config. On Fabric without Mod Menu the same settings are screenMaxActive (0 for off) and screenQuality (0 for Low to 3 for Full) in config/webgui/client.json.
| Screen quality | Page pixels per pixel on screen | All pages together, a second |
|---|---|---|
| Low | 0.75 | 60 frames, 10 megapixels |
| Medium (default) | 1 | 120 frames, 25 megapixels |
| High | 1.5 | 300 frames, 60 megapixels |
| Full | every page at its own size | no limit |
The budget counts what a page actually paints, so a board that changes once a second costs next to nothing at any quality and never holds the others back. Pages that animate every frame are what costs. Sixteen of them in view, 3.2 by 1.8 blocks at 320 pixels per block, measured on a Ryzen 5 5500 with the limit raised to 16 pages:
| Screen quality | Added to each game frame | Chromium |
|---|---|---|
| Medium | about 0.25 ms | under one CPU core |
| Full | about 6 ms | several cores |
The same sixteen screens showing a board that changes once a second add about 0.3 ms even on Full.
A screen is drawn lit by itself, like a display, so it reads the same in a dark room as in daylight. From behind it is a grey panel, unless it is transparent.
From code
On the mod:
import land.webgui.api.WebviewApi;
import land.webgui.protocol.Screens;
float[] facing = Screens.facing("north");
WebviewApi.putScreen(new Screens.Screen("lobby", "minecraft:overworld",
100.5, 70, -20, facing[0], facing[1], 3.2, 1.8,
"webgui://screens/board.html", 320, false));
// A banner the crosshair passes through: transparent, not interactive.
WebviewApi.putScreen(new Screens.Screen("banner", "minecraft:overworld",
100.5, 90, -20, facing[0], facing[1], 16, 4,
"webgui://screens/banner.html", 64, true, false));
WebviewApi.emitToScreen("lobby", "score", "{\"red\":3,\"blue\":2}");
WebviewApi.onPageEvent("board:click", (player, json) -> {
// json carries "screen": "lobby"
});On Paper:
WebGUI.putScreen(WebGUI.screen("lobby", location, "north", 3.2, 1.8, "webgui://screens/board.html"));
WebGUI.putScreen(WebGUI.screen("banner", above, "north", 16, 4, "webgui://screens/banner.html")
.withInteractive(false));
WebGUI.emitToScreen("lobby", "score", "{\"red\":3,\"blue\":2}");removeScreen, getScreen and screens complete the set on both. The last argument of the Screens.Screen constructor, interactive, may be left out and is then true; withInteractive(boolean) returns a copy with it changed. (2.8.0+)
Screens are saved in webgui-screens.json in the world folder on the mod, and in plugins/WebGUI/screens.json on Paper.