Interface ScreenFactory
public interface ScreenFactory
A mod's menu: builds the menu's first screen each time the player opens it. This is what a mod passes to
MultiversionUi.register(String, Text, ScreenFactory).
final class MyMenu implements ScreenFactory {
public Screen create(UiHost host) {
return MenuScreen.builder("main")
.title(Text.translatable("mymod.title", "My Mod"))
.add(Label.builder("hello").text(Text.literal("Hello!")).build())
.footer(Button.builder("done").label(UiTexts.DONE).onPress(host::back).build())
.build();
}
public Text buttonLabel() {
return Text.translatable("mymod.button", "My Mod...");
}
}
Implementations should be cheap and side-effect free apart from building the screen: create(UiHost) runs on
every opening (and buttonLabel() whenever the Options screen is built), always on the game's main thread.
If either throws, or create returns null, the mod's menu turns off for the rest of the session and
opens as a screen saying so (Failsafe); other mods' menus are unaffected.
-
Method Summary
Modifier and TypeMethodDescriptiondefault TextLabel of the button that opens the menu: the Options screen's button when this is the only registered menu (with several, that button readsUiTexts.MOD_MENUSand the "Mod menus" list uses thenamegiven toMultiversionUi.register(String, Text, ScreenFactory)instead).Builds the menu's first screen, usually aMenuScreen.
-
Method Details
-
create
Builds the menu's first screen, usually aMenuScreen. Called on the main thread each time the player opens the menu, from the Options screen, the mod list orMultiversionUi.menuScreen(String, Object); build a fresh screen every time rather than returning a cached one, so typed text and section states start over.Keep
host: the screen's actions use it to open further screens (UiHost.open(Screen)), to close (UiHost.back()), and to run work (UiHost.runAsync(Callable, BiConsumer)). The first screen'sUiHost.back()returns to the screen the menu was opened from.- Parameters:
host- the backend's host for this menu opening- Returns:
- the screen to show; never
null
-
buttonLabel
Label of the button that opens the menu: the Options screen's button when this is the only registered menu (with several, that button readsUiTexts.MOD_MENUSand the "Mod menus" list uses thenamegiven toMultiversionUi.register(String, Text, ScreenFactory)instead). Vanilla convention ends it with "..." because it opens a screen.- Returns:
- the label;
UiTexts.OPEN_MENU("Menu...") by default. Nevernull.
-