Skip to content
MateoF24 edited this page Mar 10, 2026 · 5 revisions

OnTime 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.


OnTimeAPI

Obtain the singleton instance:

OnTimeAPI api = OnTimeAPI.getInstance();

Timer Management

boolean created  = api.createTimer(String name, int hours, int minutes, int seconds, boolean countUp);
boolean removed  = api.removeTimer(String name);
boolean started  = api.startTimer(String name);
boolean stopped  = api.stopActiveTimer();
boolean paused   = api.pauseActiveTimer();

Time Control

boolean ok = api.setTimerTime(String name, int hours, int minutes, int seconds);
boolean ok = api.addTimerTime(String name, int hours, int minutes, int seconds);

Command & Behavior Control

// Update the finish command of an existing timer
boolean ok = api.setTimerCommand(String name, String command);

// Set repeat mode (count = -1 for infinite)
boolean ok = api.setTimerRepeat(String name, boolean repeat, int count);

Querying

Optional<TimerInfo> t      = api.getTimer(String name);
Optional<TimerInfo> active = api.getActiveTimer();
Map<String, TimerInfo> all = api.getAllTimers();
boolean exists             = api.hasTimer(String name);
boolean active             = api.isTimerActive(String name);   // true if this timer is the active one
boolean anyActive          = api.isAnyTimerActive();

Scoreboard

// Name of the objective OnTime keeps in sync with the active timer
String objectiveName = api.getScoreboardObjectiveName(); // returns "ontime_active"

TimerInfo

TimerInfo is a read-only record:

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
boolean repeat()            // Whether repeat mode is enabled
int     repeatCount()       // Max repetitions (-1 = infinite)
int     repeatsDone()       // Completed repetitions so far

long    getCurrentSeconds()
long    getTargetSeconds()
String  getFormattedTime()  // "MM:SS" or "HH:MM:SS"
float   getPercentage()     // 100% = full, 0% = finished

Event Callbacks

Subscribe to timer lifecycle events. Callbacks receive a TimerInfo snapshot and are called on the server thread.

api.registerOnStart(TimerInfo  -> { });   // timer becomes active
api.registerOnFinish(TimerInfo -> { });   // timer reaches zero / condition met
api.registerOnPause(TimerInfo  -> { });   // timer paused
api.registerOnResume(TimerInfo -> { });   // timer resumed
api.registerOnTick(TimerInfo   -> { });   // called once per second while running

Example:

api.registerOnFinish(info -> {
    System.out.println("Timer " + info.name() + " finished!");
});

onTick fires at the same rate as the client sync interval (once per second), not every game tick.


External Finish Conditions

Register a Supplier<Boolean> evaluated every tick. When it returns true the timer finishes immediately, executing its command normally.

api.registerFinishCondition("speedrun", () -> someExternalCondition());
api.unregisterFinishCondition("speedrun");

This is independent from the built-in scoreboard condition (/timer condition). Both can coexist — whichever triggers first ends the timer.


Custom HUD Renderer

Replace the built-in timer overlay with your own renderer. Must be registered client-side.

Implement ITimerRenderer:

public class MyRenderer implements ITimerRenderer {
    @Override
    public void render(GuiGraphics graphics, float partialTick,
                       String formattedTime, float percentage,
                       int x, int y, float scale) {
        // your rendering logic
    }
}

Register it:

TimerRendererRegistry.register(new MyRenderer());
TimerRendererRegistry.unregister(); // restore default

ITimerRenderer and TimerRendererRegistry are client-side classes. Do not reference them from server or common code.


Placeholder System

Register custom placeholders resolved when a timer's finish command executes:

api.registerTimerPlaceholder("mykey", timer -> timer.getName().toUpperCase());

This registers {mykey} as a valid placeholder in any timer command.

Built-in placeholders

Placeholder Value
{name} Timer name
{time} Formatted time string
{ticks} Current tick count
{target} Target tick count
{seconds} Current seconds
{mode} "count-up" or "countdown"

Permissions (LuckPerms)

You can supply a custom permission provider to replace the default OP-level check:

api.setPermissionProvider((source, node, fallbackLevel) -> {
    // return true if source has permission for node
});

See LuckPerms Integration for the ready-made integration approach.


Entrypoint Registration

Fabric

public class MyModOnTimeIntegration implements OnTimeEntrypoint {
    @Override
    public void onOntimeInitialize(OnTimeAPI api) {
        api.registerOnFinish(info -> System.out.println(info.name() + " done"));
        api.registerTimerPlaceholder("mykey", timer -> "value");
    }
}

fabric.mod.json:

"entrypoints": {
    "ontime": ["com.example.mymod.MyModOnTimeIntegration"]
}

NeoForge / Forge (1.20.1)

InterModComms.sendTo("ontime", "register", () -> (OnTimeEntrypoint) api -> {
    api.registerOnFinish(info -> System.out.println(info.name() + " done"));
});

Dependency Declaration

Fabric

"depends": { "ontime": "*" }

NeoForge / Forge

[[dependencies.yourmodid]]
modId = "ontime"
type = "required"
versionRange = "[2.1.0,)"
ordering = "BEFORE"
side = "BOTH"

Clone this wiki locally