Repository navigation
API
OnTime exposes a programmatic API that allows other mods to interact with the timer system. The API surface is identical across all loaders (Fabric, NeoForge, Forge). What differs is how you register your entrypoint, documented per-loader below.
Obtain the singleton instance:
OnTimeAPI api = OnTimeAPI.getInstance();// Create a timer (returns false if name already exists or duration exceeds server limit)
boolean created = api.createTimer(String name, int hours, int minutes, int seconds, boolean countUp);
// Remove a timer by name
boolean removed = api.removeTimer(String name);
// Start a timer (returns false if not found or another timer is already active)
boolean started = api.startTimer(String name);
// Stop the active timer (resets it and clears active state)
boolean stopped = api.stopActiveTimer();
// Pause the active timer
boolean paused = api.pauseActiveTimer();// Override the current time of a timer
boolean ok = api.setTimerTime(String name, int hours, int minutes, int seconds);
// Add time to a timer
boolean ok = api.addTimerTime(String name, int hours, int minutes, int seconds);// Get a timer by name (returns Optional<TimerInfo>)
Optional<TimerInfo> t = api.getTimer(String name);
// Get the currently active timer
Optional<TimerInfo> active = api.getActiveTimer();
// Get all timers as a Map<String, TimerInfo>
Map<String, TimerInfo> all = api.getAllTimers();
// Check existence
boolean exists = api.hasTimer(String name);TimerInfo is a read-only record with the following accessors:
String name() // Timer name
long currentTicks() // Current tick count
long targetTicks() // Total duration in ticks (20 ticks = 1 second)
boolean countUp() // true = count-up, false = countdown
boolean running() // Whether the timer is actively ticking
boolean silent() // Whether the timer suppresses sounds globally
String command() // Command assigned to this timer
long getCurrentSeconds() // currentTicks / 20
long getTargetSeconds() // targetTicks / 20
String getFormattedTime() // "MM:SS" or "HH:MM:SS"
float getPercentage() // Progress percentage (100% = full, 0% = finished)You can register custom placeholders that are resolved when a timer's command executes:
api.registerTimerPlaceholder("mykey", timer -> timer.getName().toUpperCase());This registers {mykey} as a valid placeholder in any timer command. The resolver receives the Timer object at completion time.
| Placeholder | Value |
|---|---|
{name} |
Timer name |
{time} |
Formatted time string (MM:SS or HH:MM:SS) |
{ticks} |
Current tick count |
{target} |
Target tick count |
{seconds} |
Current seconds (currentTicks / 20) |
{mode} |
"count-up" or "countdown"
|
Use the entrypoint to receive the OnTimeAPI instance as soon as OnTime initializes.
Implement OnTimeEntrypoint:
public class MyModOnTimeIntegration implements OnTimeEntrypoint {
@Override
public void onOntimeInitialize(OnTimeAPI api) {
api.registerTimerPlaceholder("mykey", timer -> "value");
}
}Register it in fabric.mod.json:
"entrypoints": {
"ontime": [
"com.example.mymod.MyModOnTimeIntegration"
]
}Send an IMC message with method "register" and a supplier returning your OnTimeEntrypoint implementation:
InterModComms.sendTo("ontime", "register", () -> (OnTimeEntrypoint) api -> {
api.registerTimerPlaceholder("mykey", timer -> "value");
});Same as NeoForge — use InterModComms.sendTo during your mod's initialization:
InterModComms.sendTo("ontime", "register", () -> (OnTimeEntrypoint) api -> {
api.registerTimerPlaceholder("mykey", timer -> "value");
});"depends": {
"ontime": "*"
}[[dependencies.yourmodid]]
modId = "ontime"
type = "required"
versionRange = "[2.0.0,)"
ordering = "BEFORE"
side = "BOTH"