UI DOCUMENTATION Version: 1.10.0.3
This is documentation for a beta release of Minecraft. New features, components, and capabilities in this release are not final and might change without notice before the final release.
Be sure to check the documentation once the release is out of beta if your add-on isn't working properly. Resource and Behavior Packs created for the beta are not guaranteed to work on the final release.
Index#
Scripting System#
The custom UI for Minecraft is based on HTML 5.You can write JavaScript within the HTML file to listen and respond to events from the UI Engine. These events can be triggered by the UI Engine itself or you can trigger them from your scripts.In order to use custom UI, the resource pack containing the custom UI needs to have the custom UI capabilities enabled. To do this, simply add "experimental_custom_ui" to the capabilities array in the pack's manifest. You can check the Turn-Based RPG demo for an example of how to do this.
Getting The Script Engine#
In order to create a link between the UI Engine and the Script Engine you need to capture the instance of the Script Engine.The engine.on() function needs to listen for the event "scriptEngine:created" and you need to store the return value.
Example of how to capture the Script Engine:
let scriptInterface = undefined;
engine.on("scriptEngine:created", function(interface) {
scriptInterface = interface;
});
Engine Bindings#
on(EventIdentifier)#
This is used to get events from the UI Engine. These events can be originally sent from client scripts using `send_ui_event`, or created by the game and passed along by the UI Engine. The data sent from scripts to this function must be a string.
Parameters#
Name | Type | Description |
EventIdentifier |
String |
Specifies the event that function will react to |
Example of how to listen for events from a client script:
engine.on("exampleEventIdentifier", function (exampleData) {
}
Script Bindings#
triggerEvent(Data)#
This triggers the minecraft:ui_event on client scripts with the provided data.
Parameters#
Name | Type | Description |
Data |
String |
This string will be sent to "minecraft:ui_event" event in client scripts |
Example of how to send events to a client script:
scriptInterface.triggerEvent("SendThisDataToTheScript");