Interface GameBridge


public interface GameBridge
The running game's options file, for menus that save or restore it (TODO.md §3.5): e.g. a mod that keeps settings profiles copies options.txt on Save and writes it back on Load. Implemented per backend; a menu gets it from UiHost.game(). Most menus don't need it.
// Save: make sure options.txt has the newest values, then copy it.
host.game().flushOptions();
host.runAsync(() -> store.copyFrom(optionsFile), (ok, error) -> …);

// Load: write options.txt, then apply it in the running game.
host.runAsync(() -> store.copyTo(optionsFile), (ok, error) -> {
    if (error == null) {
        ReloadResult r = host.game().reloadOptions();
        if (r.needsRestart()) {
            status.show(StatusLine.Kind.WARNING, Text.translatable("mymod.restart", "Restart to apply: %s",
                    String.join(", ", r.restartOptions())));
        }
    }
});

On a registered menu's host, each call is guarded by Failsafe: if the backend fails, the call falls back as described on each method instead of throwing.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Makes the game write its in-memory options to options.txt now, so that a copy of the file made afterwards has the newest values.
    boolean
    Whether a world (single- or multiplayer) is loaded, e.g.
    Re-reads options.txt after the mod changed it, and applies what can be applied in the running game (graphics, sound, controls, language…).
  • Method Details

    • flushOptions

      void flushOptions()
      Makes the game write its in-memory options to options.txt now, so that a copy of the file made afterwards has the newest values. Main thread. If the backend fails, the file stays as the game last wrote it.
    • reloadOptions

      ReloadResult reloadOptions()
      Re-reads options.txt after the mod changed it, and applies what can be applied in the running game (graphics, sound, controls, language…). Main thread only.
      Returns:
      which options only take effect after a restart; if the backend fails, a result saying the whole file (options.txt) needs a restart
    • isInWorld

      boolean isInWorld()
      Whether a world (single- or multiplayer) is loaded, e.g. to warn that loading options now changes the running session. false if the backend fails.
      Returns:
      true if a world is loaded, false also when the backend fails