Skip to content

KubeJS Integration

Since 2.2.1

LDLib2 exposes its full UI system to KubeJS scripts — no Java or Kotlin required. You can open UIs, build element trees, apply stylesheets, and wire up data bindings entirely from .js files.


Opening a UI

The primary entry point is the LDLib2UI event group and the LDLib2UIFactory bindings. Three factory types cover the most common triggers:

Event Factory helper Use when
LDLib2UI.block(id, handler) LDLib2UIFactory.openBlockUI(player, pos, id) Right-clicking a block
LDLib2UI.item(id, handler) LDLib2UIFactory.openHeldItemUI(player, hand, id) Right-clicking with an item
LDLib2UI.player(id, handler) LDLib2UIFactory.openPlayerUI(player, id) Commands, keybinds, any trigger

Full usage, context fields, and script placement rules are documented on the UI Factory page.


Building UIs in KubeJS

Inside a LDLib2UI.* handler, all UI classes are available directly by name — no imports needed:

LDLib2UI.block("mymod:example", event => {
    event.modularUI = ModularUI.of(UI.of(
        new UIElement()
            .addClass("panel_bg")
            .addChildren(
                new Label().setText("Hello from KubeJS"),
                new Button().setText("Click me").setOnClick(e => {
                    // server-side logic here
                })
            )
    ), event.player);
});

Browse the available components, textures, and preliminary concepts:


Binding Availability

@KJSBindings marks which classes and methods are exposed. Classes annotated with modId (e.g. @KJSBindings(modId = "jei")) are only available when that mod is loaded. All core UI classes have no mod restriction.