Timer

Tick-loop clock: 20 ticks/sec, renderPartialTicks interpolation, timerSpeed for timer cheats to target.

net/minecraft/util/Timer.java

Updated 2026-09-12

Packets Referenced (0)

Related Vanilla Internals

Deep Analysis

Client tick-rate driver in net.minecraft.util. Owned by Minecraft game loop, called each frame via updateTimer. Converts wall-clock delta into elapsedTicks and renderPartialTicks. Matters for movement because it bounds ticks to 10 and scales by timerSpeed.

Key Methods (6)

Timer

Constructs timer with target ticks-per-second, default 20.

Stores ticksPerSecond. Seeds lastSyncSysClock via Minecraft.getSystemTime and lastSyncHRClock via nanoTime ms. Initializes timeSyncAdjustment to 1.0.

updateTimer

Advances tick counters from wall-clock delta each frame.

Computes sysClock delta j and hrClock seconds d0. If j outside 0-1000ms resets lastHRTime. Otherwise accumulates counter for drift correction.

updateTimer#sync-adjust

Calibrates hi-res clock against system clock once per second.

When counter exceeds 1000ms computes ratio counter/(k-lastSyncHRClock). Blends into timeSyncAdjustment with 0.2 factor. Resets counter and anchor.

updateTimer#accumulate

Converts seconds delta into fractional tick progress.

Formula d2=(d0-lastHRTime)*timeSyncAdjustment. Clamps d2 to 0-1 via MathHelper. Adds d2*timerSpeed*ticksPerSecond to elapsedPartialTicks.

updateTimer#cap-ticks

Extracts whole ticks and enforces spiral-of-death cap.

elapsedTicks=(int)elapsedPartialTicks then subtracts back fractional remainder. Caps elapsedTicks at 10. Prevents huge catch-up bursts after lag.

renderPartialTicks

Exposes interpolation factor for render and movement smoothing.

Public float field set equal to elapsedPartialTicks each update. Frozen when paused to avoid jitter. Read by entity rendering and camera code.

Internal State

ticksPerSecondTarget ticks per second, 20 in vanilla
elapsedTicksWhole ticks to run this frame, capped at 10
elapsedPartialTicksFractional tick carry-over between frames
renderPartialTicksInterpolation factor for rendering
timerSpeedSpeed multiplier, 0.5 is half speed
timeSyncAdjustmentDrift correction ratio for hi-res clock

Related Vanilla Internals

Full Source

Timer.java110 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.util;
2
3
import net.minecraft.client.Minecraft;
4
5
public class Timer
6
{
7
    /** The number of timer ticks per second of real time */
8
    float ticksPerSecond;
9
10
    /**
11
     * The time reported by the high-resolution clock at the last call of updateTimer(), in seconds
12
     */
13
    private double lastHRTime;
14
15
    /**
16
     * How many full ticks have turned over since the last call to updateTimer(), capped at 10.
17
     */
18
    public int elapsedTicks;
19
20
    /**
21
     * How much time has elapsed since the last tick, in ticks, for use by display rendering routines (range: 0.0 -
22
     * 1.0).  This field is frozen if the display is paused to eliminate jitter.
23
     */
24
    public float renderPartialTicks;
25
26
    /**
27
     * A multiplier to make the timer (and therefore the game) go faster or slower.  0.5 makes the game run at half-
28
     * speed.
29
     */
30
    public float timerSpeed = 1.0F;
31
32
    /**
33
     * How much time has elapsed since the last tick, in ticks (range: 0.0 - 1.0).
34
     */
35
    public float elapsedPartialTicks;
36
37
    /**
38
     * The time reported by the system clock at the last sync, in milliseconds
39
     */
40
    private long lastSyncSysClock;
41
42
    /**
43
     * The time reported by the high-resolution clock at the last sync, in milliseconds
44
     */
45
    private long lastSyncHRClock;
46
47
    /** Increase per 1 every tick, reset when reach 1000 */
48
    private long counter;
49
50
    /**
51
     * A ratio used to sync the high-resolution clock to the system clock, updated once per second
52
     */
53
    private double timeSyncAdjustment = 1.0D;
54
55
    public Timer(float tps)
56
    {
57
        this.ticksPerSecond = tps;
58
        this.lastSyncSysClock = Minecraft.getSystemTime();
59
        this.lastSyncHRClock = System.nanoTime() / 1000000L;
60
    }
61
62
    /**
63
     * Updates all fields of the Timer using the current time
64
     */
65
    public void updateTimer()
66
    {
67
        long i = Minecraft.getSystemTime();
68
        long j = i - this.lastSyncSysClock;
69
        long k = System.nanoTime() / 1000000L;
70
        double d0 = (double)k / 1000.0D;
71
72
        if (j <= 1000L && j >= 0L)
73
        {
74
            this.counter += j;
75
76
            if (this.counter > 1000L)
77
            {
78
                long l = k - this.lastSyncHRClock;
79
                double d1 = (double)this.counter / (double)l;
80
                this.timeSyncAdjustment += (d1 - this.timeSyncAdjustment) * 0.20000000298023224D;
81
                this.lastSyncHRClock = k;
82
                this.counter = 0L;
83
            }
84
85
            if (this.counter < 0L)
86
            {
87
                this.lastSyncHRClock = k;
88
            }
89
        }
90
        else
91
        {
92
            this.lastHRTime = d0;
93
        }
94
95
        this.lastSyncSysClock = i;
96
        double d2 = (d0 - this.lastHRTime) * this.timeSyncAdjustment;
97
        this.lastHRTime = d0;
98
        d2 = MathHelper.clamp_double(d2, 0.0D, 1.0D);
99
        this.elapsedPartialTicks = (float)((double)this.elapsedPartialTicks + d2 * (double)this.timerSpeed * (double)this.ticksPerSecond);
100
        this.elapsedTicks = (int)this.elapsedPartialTicks;
101
        this.elapsedPartialTicks -= (float)this.elapsedTicks;
102
103
        if (this.elapsedTicks > 10)
104
        {
105
            this.elapsedTicks = 10;
106
        }
107
108
        this.renderPartialTicks = this.elapsedPartialTicks;
109
    }
110
}

Deobfuscated MCP 1.8.9 source of Timer from Marcelektro/MavenMCP-1.8.9 (net/minecraft/util/Timer.java), stored verbatim.