Class InputBoosterCompat

java.lang.Object
dev.inputbooster.api.util.InputBoosterCompat

public final class InputBoosterCompat extends Object
Compatibility utilities for mods that list InputBooster as an optional dependency.

Pattern for optional dependency

In fabric.mod.json use "suggests" instead of "depends":

 "suggests": {
     "inputbooster": "*"
 }
 

Then guard all API calls with the helpers here:


 // In your mod init:
 InputBoosterCompat.ifLoaded(api -> {
     api.registerListener(myListener);
     api.setMaxCps(15);
 });

 // For quick reads:
 int hz = InputBoosterCompat.getPollRateOrDefault(200);
 
  • Method Details

    • ifLoaded

      public static void ifLoaded(Consumer<InputBoosterAPI> action)
      Runs action with the API instance if InputBooster is loaded. Does nothing (no exception) if the mod is absent.
    • getOptional

      public static Optional<InputBoosterAPI> getOptional()
      Returns the API instance when it is available.
    • mapOrDefault

      public static <T> T mapOrDefault(Function<InputBoosterAPI,T> mapper, T fallback)
      Maps the API instance to a value, or returns fallback when absent.
    • getPollRateOrDefault

      public static int getPollRateOrDefault(int defaultHz)
      Returns the poll rate if InputBooster is loaded, or defaultHz otherwise.
    • tryRegisterListener

      public static boolean tryRegisterListener(InputBoosterEventListener listener)
      Registers a listener only if InputBooster is loaded. Returns true if the listener was registered, false if InputBooster is absent.
    • registerForTypes

      public static boolean registerForTypes(InputBoosterEventListener listener, InputBoosterEvent.Type... types)
      Registers a listener only for specific event types. All other event types are silently ignored.
      
       InputBoosterCompat.registerForTypes(
           event -> doSomething(event.intValue()),
           InputBoosterEvent.Type.POLL_RATE_CHANGED,
           InputBoosterEvent.Type.MODE_CHANGED
       );
       
    • getVersion

      public static String getVersion()
      Returns the API version string (same as the mod version). Returns "not loaded" if InputBooster is absent.