Skip to content
MateoF24 edited this page Mar 5, 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

// 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();

Time Control

// 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);

Querying

// 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

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)

Placeholder System

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.

Built-in placeholders

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"

Entrypoint Registration

Use the entrypoint to receive the OnTimeAPI instance as soon as OnTime initializes.

Fabric

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"
    ]
}

NeoForge

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");
});

Forge (1.20.1)

Same as NeoForge — use InterModComms.sendTo during your mod's initialization:

InterModComms.sendTo("ontime", "register", () -> (OnTimeEntrypoint) api -> {
    api.registerTimerPlaceholder("mykey", timer -> "value");
});

Dependency Declaration

Fabric (fabric.mod.json)

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

NeoForge / Forge (mods.toml / neoforge.mods.toml)

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

Clone this wiki locally