Package dev.inputbooster.api.util
Class InputBoosterCompat
java.lang.Object
dev.inputbooster.api.util.InputBoosterCompat
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 Summary
Modifier and TypeMethodDescriptionstatic Optional<InputBoosterAPI> Returns the API instance when it is available.static intgetPollRateOrDefault(int defaultHz) Returns the poll rate if InputBooster is loaded, ordefaultHzotherwise.static StringReturns the API version string (same as the mod version).static voidifLoaded(Consumer<InputBoosterAPI> action) Runsactionwith the API instance if InputBooster is loaded.static <T> TmapOrDefault(Function<InputBoosterAPI, T> mapper, T fallback) Maps the API instance to a value, or returnsfallbackwhen absent.static booleanregisterForTypes(InputBoosterEventListener listener, InputBoosterEvent.Type... types) Registers a listener only for specific event types.static booleantryRegisterListener(InputBoosterEventListener listener) Registers a listener only if InputBooster is loaded.
-
Method Details
-
ifLoaded
Runsactionwith the API instance if InputBooster is loaded. Does nothing (no exception) if the mod is absent. -
getOptional
Returns the API instance when it is available. -
mapOrDefault
Maps the API instance to a value, or returnsfallbackwhen absent. -
getPollRateOrDefault
public static int getPollRateOrDefault(int defaultHz) Returns the poll rate if InputBooster is loaded, ordefaultHzotherwise. -
tryRegisterListener
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
Returns the API version string (same as the mod version). Returns "not loaded" if InputBooster is absent.
-