Open your menu
Every way a player reaches a registered menu - the Options screen button, the Mod menus list, the mod list's Config button and your own code.
Once registered, a menu can be opened in up to three ways. The first two need no code.
The Options screen#
The library adds one button to the game's Options screen:
| Registered menus | The button reads | It opens |
|---|---|---|
| Only yours | your ScreenFactory.buttonLabel() (default Menu...) |
your menu |
| Several | Mod menus... | a "Mod menus" list with one button per mod, labelled with the name passed to register |
Override buttonLabel() to name the button after your mod. Vanilla's convention ends labels that open a screen
with ...:
@Override
public Text buttonLabel() {
return Text.translatable("mymod.menu", "My Mod...");
}
When a mod's menu has turned off after an error, its button in the "Mod menus" list is greyed out (see Failure isolation).
The mod list's Config button#
| Loader | What you do |
|---|---|
| Forge 1.13.2 – 26.3, NeoForge | Nothing, as long as register runs in your @Mod constructor. |
| Fabric and Quilt with Mod Menu | Nothing: it works for every mod that depends on xis_mvui. |
| Forge 1.8 – 1.12.2 | guiFactory = MultiversionUi.LEGACY_FORGE_GUI_FACTORY in your @Mod. |
| Forge 1.7.10 | guiFactory = MultiversionUi.CPW_FORGE_GUI_FACTORY in your @Mod. |
If the library can't add a mod's menu to the mod list, it logs that and the Options screen button still works.
From your own code#
To open the menu from your own key binding or a button on another screen, ask for it as the running version's screen object:
Object screen = MultiversionUi.menuScreen("mymod", currentScreen);
parentis the vanilla screen to return to when the player closes the menu, ornullto return to the game.- The result is typed
Objectbecause the API has no Minecraft classes. Cast it to the version's screen class and show it with the game's own call, for exampleMinecraft.getInstance().setScreen((Screen) screen)on recent versions. The method and class names depend on the version and mappings, so this line belongs in your version-specific code (see Build one mod for every loader). - It returns
nullwhen your mod registered no menu, when there is no backend for the running game, or when every menu is off. Check before casting. - If only your menu is off, it returns a screen that tells the player so.
- Call it on the main thread. It never throws.
Next steps#
- Several screens and dialogs: what happens after the first screen.
- Key bindings: storing the key that opens your menu.