Skip to content

API reference / @jsprismarine/prismarine / modules/ticker

modules/ticker ​

Classes ​

Interfaces ​

TickControl ​

Defined in: packages/prismarine/src/modules/ticker.ts:231

What /tick can do to the loop: the rate it aims for, whether the world advances, and bursts of ticks.

Methods ​

getTickRate() ​

getTickRate(): number

Defined in: packages/prismarine/src/modules/ticker.ts:233

The ticks per second the loop aims for.

Returns ​

number

isFrozen() ​

isFrozen(): boolean

Defined in: packages/prismarine/src/modules/ticker.ts:237

Whether the world and functions are held still. Tick events and chunk sends carry on.

Returns ​

boolean

setFrozen() ​

setFrozen(frozen): void

Defined in: packages/prismarine/src/modules/ticker.ts:238

Parameters ​
frozen ​

boolean

Returns ​

void

setTickRate() ​

setTickRate(rate): void

Defined in: packages/prismarine/src/modules/ticker.ts:235

Sets the target ticks per second; a loop that is sprinting keeps sprinting.

Parameters ​
rate ​

number

Returns ​

void

sprint() ​

sprint(ticks): void

Defined in: packages/prismarine/src/modules/ticker.ts:248

Runs ticks ticks back to back, then returns to the target rate.

Parameters ​
ticks ​

number

Returns ​

void

step() ​

step(ticks): boolean

Defined in: packages/prismarine/src/modules/ticker.ts:244

Runs ticks ticks of a frozen world, then freezes it again.

Parameters ​
ticks ​

number

Returns ​

boolean

False when the world is not frozen, so there is nothing to step.

stopSprint() ​

stopSprint(): boolean

Defined in: packages/prismarine/src/modules/ticker.ts:250

Ends a sprint early.

Returns ​

boolean

False when no sprint was running.

stopStep() ​

stopStep(): boolean

Defined in: packages/prismarine/src/modules/ticker.ts:246

Ends a step early.

Returns ​

boolean

False when no step was running.


Ticker ​

Defined in: packages/prismarine/src/modules/ticker.ts:206

What the prismarine:ticker token resolves to: the running tick counters. Tick work itself is observed through the server's typed tick event, which the loop emits in every tick, after the input step.

Methods ​

getLastTickMs() ​

getLastTickMs(): number

Defined in: packages/prismarine/src/modules/ticker.ts:227

How long the last tick's work took, in milliseconds, without the sleep before the next tick. Zero until the first tick completes.

Returns ​

number

getTick() ​

getTick(): number

Defined in: packages/prismarine/src/modules/ticker.ts:208

The current tick number.

Returns ​

number

getTickMs() ​

getTickMs(): number

Defined in: packages/prismarine/src/modules/ticker.ts:222

How long a tick's work has been taking, in milliseconds, as a moving average over the most recent ticks. It leaves out the sleep between ticks, so a healthy server reads well under the 50 ms period. Zero until the first tick completes.

Returns ​

number

getTPS() ​

getTPS(): number

Defined in: packages/prismarine/src/modules/ticker.ts:210

The current TPS, measured over a sliding one-second window.

Returns ​

number

getTPSAverages() ​

getTPSAverages(): number[]

Defined in: packages/prismarine/src/modules/ticker.ts:216

The TPS averaged over the last 1, 5 and 15 minutes (TPS_AVERAGE_MINUTES), as exponential moving averages of one sample every 100 ticks, the way Spigot's /tps measures them. Each starts at the default 20 and moves toward the measured rate as samples arrive.

Returns ​

number[]


TickerServer ​

Defined in: packages/prismarine/src/modules/ticker.ts:151

The slice of the server the tick loop drives. Everything here is a collaborator that is not a kernel module yet; as each one converts, its accessor should be replaced by a service token the ticker module declares as a dependency:

  • getWorlds belongs to a future worlds token (the world manager).
  • tickFunctions belongs to a future commands token (the command manager).
  • getChunkScheduler belongs to a future chunk-scheduler token.
  • getChunkSendBudgetMs, isTickingEnabled, and isProcessTitleEnabled belong to a future config token (or the ticker module's config slice).

Properties ​

events ​

readonly events: Pick<ServerEventBus, "post">

Defined in: packages/prismarine/src/modules/ticker.ts:156

The kernel's event bus, which the ticker posts the server tick event on inside the tick, waiting for no listener.

Methods ​

admitInputs() ​

admitInputs(): number

Defined in: packages/prismarine/src/modules/ticker.ts:162

The input step: applies the inputs held since the last tick, in arrival order, up to a count, then the chunk completions it admits. The ticker runs it before anything else in the tick, and before any world updates.

Returns ​

number

getChunkCompletionQueue() ​

getChunkCompletionQueue(): Pick<ChunkCompletionQueue, "activate" | "deactivate" | "drain">

Defined in: packages/prismarine/src/modules/ticker.ts:180

Deferred worker translations and background lighting, budgeted separately from packet sends.

Returns ​

Pick<ChunkCompletionQueue, "activate" | "deactivate" | "drain">

getChunkScheduler() ​

getChunkScheduler(): object

Defined in: packages/prismarine/src/modules/ticker.ts:174

The server-wide chunk scheduler the tick hands a time slice to.

Returns ​
setBudget() ​

setBudget(budgetMs): void

Parameters ​
budgetMs ​

number

Returns ​

void

tick() ​

tick(): unknown

Starts the deliveries that fit in this tick's slice; the tick does not wait for them.

Returns ​

unknown

getChunkSendBudgetMs() ​

getChunkSendBudgetMs(): number

Defined in: packages/prismarine/src/modules/ticker.ts:182

This tick's chunk-send budget, read fresh each tick so config reloads apply.

Returns ​

number

getLogger() ​

getLogger(): object

Defined in: packages/prismarine/src/modules/ticker.ts:194

Where the catch-up skip warns and the lag profile prints.

Returns ​

object

error() ​

error(error): void

Parameters ​
error ​

unknown

Returns ​

void

verbose() ​

verbose(message, scope?): void

Parameters ​
message ​

string

scope? ​

string

Returns ​

void

warn() ​

warn(message, scope?): void

Parameters ​
message ​

string

scope? ​

string

Returns ​

void

getProfileOwner() ​

getProfileOwner(): object

Defined in: packages/prismarine/src/modules/ticker.ts:192

The object the opt-in profiler was attached to (the server).

Returns ​

object

getWorlds() ​

getWorlds(): TickerWorld[]

Defined in: packages/prismarine/src/modules/ticker.ts:166

The worlds to update this tick, in the order the ticker updates them, one after another.

Returns ​

TickerWorld[]

isHeadless() ​

isHeadless(): boolean

Defined in: packages/prismarine/src/modules/ticker.ts:188

Headless servers do not own the terminal, so they leave the title alone.

Returns ​

boolean

isProcessTitleEnabled() ​

isProcessTitleEnabled(): boolean

Defined in: packages/prismarine/src/modules/ticker.ts:186

Whether to write TPS and tick into the process title.

Returns ​

boolean

isStopping() ​

isStopping(): boolean

Defined in: packages/prismarine/src/modules/ticker.ts:190

Whether a server shutdown has begun; a tick in flight then stops rescheduling.

Returns ​

boolean

isTickingEnabled() ​

isTickingEnabled(): boolean

Defined in: packages/prismarine/src/modules/ticker.ts:184

Whether the loop should run at all. Read once per start().

Returns ​

boolean

pollNetwork() ​

pollNetwork(): number

Defined in: packages/prismarine/src/modules/ticker.ts:164

Delivers pending network records at this tick's fixed game-thread boundary.

Returns ​

number

tickFunctions() ​

tickFunctions(): number

Defined in: packages/prismarine/src/modules/ticker.ts:172

Runs #minecraft:tick and whatever /schedule put on this tick, as the input step's last input, and returns how many command lines ran. The ticker does not wait for it, so an asynchronous one does not satisfy this.

Returns ​

number


TickerWorld ​

Defined in: packages/prismarine/src/modules/ticker.ts:122

One world as the tick loop sees it: a name for the lag profile, and an update that runs to its end.

Methods ​

beginChangeTick()? ​

optional beginChangeTick(): void

Defined in: packages/prismarine/src/modules/ticker.ts:131

Opens the world's change log tick before the input step, so the inputs land in it.

Returns ​

void

closeTick()? ​

optional closeTick(tick): undefined

Defined in: packages/prismarine/src/modules/ticker.ts:137

Closes a tick the world did not update, such as a frozen one: seals the change log tick opened before the input step and sends what the inputs did in it. It returns undefined for the reason update does.

Parameters ​
tick ​

number

Returns ​

undefined

getName() ​

getName(): string

Defined in: packages/prismarine/src/modules/ticker.ts:123

Returns ​

string

update() ​

update(tick): undefined

Defined in: packages/prismarine/src/modules/ticker.ts:129

Runs the world's tick to its end. The ticker does not wait for it, so it returns undefined and not void: an asynchronous method satisfies void, and its rejection would go unhandled.

Parameters ​
tick ​

number

Returns ​

undefined

Variables ​

DEFAULT_TICK_RATE ​

const DEFAULT_TICK_RATE: 20 = 20

Defined in: packages/prismarine/src/modules/ticker.ts:48

The tick rate a server runs at until /tick rate changes it.


TPS_AVERAGE_MINUTES ​

const TPS_AVERAGE_MINUTES: readonly [1, 5, 15]

Defined in: packages/prismarine/src/modules/ticker.ts:69

The windows of the long TPS averages, in minutes, as Spigot's /tps reports them.

Functions ​

tickerModule() ​

tickerModule(ticker): Module

Defined in: packages/prismarine/src/modules/ticker.ts:806

Runs the ServerTicker as prismarine:ticker, providing it under tickerToken. The loop starts when the module starts and stops when it stops; the server also stops it directly at the top of a shutdown, before any teardown awaits, so no tick lands in a world mid-teardown.

Parameters ​

ticker ​

ServerTicker

The ticker the server constructed, so its counters are readable before the kernel starts.

Returns ​

Module

The module to register on the kernel.