Skip to content

Custom GUI

Warning

Not available for LabyMod 4! Only available for LabyMod 3 users with version greater than 3.8.25

Overview

With this feature it is possible to create a custom user interface. We provide a collection of GUI components you can use.

Requirements

Example GUI

input_prompt

Open the GUI

public void openGUI( Player player ) {
    // Create new screen
    WidgetScreen screen = new WidgetScreen(42); // The client will send this id back on an interaction

    // Centered anchor
    Anchor anchor = new Anchor(50, 50); // X: 50%   Y: 50%

    // Button
    ButtonWidget button = new ButtonWidget(1337, anchor, -50, 20, "Apply", 100, 20);
    button.setCloseScreenOnClick(true);
    screen.addWidget(button);

    // Text field
    screen.addWidget(new TextFieldWidget(1, anchor, -100, -5, "", 200, 20, "Name...", 16, true));

    // Label
    screen.addWidget(new LabelWidget(2, anchor, -100, -20, "Name of your pet", 0, 1));

    // Color picker
    ColorPickerWidget colorPicker = new ColorPickerWidget(3, anchor, 110, -5, 20, 20, "Pet color", Color.RED);
    colorPicker.setRgb(true);
    screen.addWidget(colorPicker);

    // Image banner
    screen.addWidget(new ImageWidget(4, anchor, -50, -80, 100, 20, "https://www.labymod.net/page/tpl/assets/images/logo.png"));

    // Serialize widgets
    JsonObject object = screen.toJsonObject(EnumScreenAction.OPEN); // OPEN = Open the screen

    // Send the json object to LabyMod
    LabyModProtocol.sendLabyModMessage( player, "screen", object );
}

All possible screen action ids:

public enum EnumScreenAction {
    OPEN, // Action id 0 - Open a new screen
    UPDATE, // Action id 1 - Update the current screen
    CLOSE, // Action id 2 - Force close the current screen and display the previous screen of the user
    WRAP_INVENTORY; // Action id 3 - Wrap a Minecraft Inventory
}

Interaction response

The client will send the following response with the screen key after closing the GUI:

{
    "id": 42,
    "type": 0,
    "states": {
        "1": {
            "value": "Content of the text field..."
        },
        "3": {
            "color": "#ff0000"
        }
    }
}

Widget interaction response (Example shows an interaction with the button):

{
    "id": 32,
    "type": 1,
    "widget_id": 1337,
    "states": {}
}
The widget_id is the id of the interacted widget. The states object contains all values of the widget like color, text field value..

Response types: ("type")

public enum EnumResponse {
    CLOSE, // Type id 0 - Sent when the player closes the GUI
    INTERACT // Type id 1 - Sent when the players interact with a widget
}

Anchor Explanation

input_prompt