WorldUnloadEvent .java

net.minecraft.client.telemetry.events.WorldUnloadEvent (class): members: NOT_TRACKING_TIME, worldLoadedTime, lastGameTime, onPlayerInfoReceived, setTime.

net.minecraft.client.telemetry.eventsclass46 linesclient1.5 KB

API Surface (3)

void onPlayerInfoReceived()
void setTime(final long gameTime)
void send(final TelemetryEventSender eventSender)

Fields & Constants (4)

NOT_TRACKING_TIME
worldLoadedTime
totalTicks
lastGameTime

Code Graph: Dependencies (3)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

WorldUnloadEvent.java46 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.telemetry.events;
2
3
import java.time.Duration;
4
import java.time.Instant;
5
import java.util.Optional;
6
import net.fabricmc.api.EnvType;
7
import net.fabricmc.api.Environment;
8
import net.minecraft.client.telemetry.TelemetryEventSender;
9
import net.minecraft.client.telemetry.TelemetryEventType;
10
import net.minecraft.client.telemetry.TelemetryProperty;
11
12
@Environment(EnvType.CLIENT)
13
public class WorldUnloadEvent {
14
	private static final int NOT_TRACKING_TIME = -1;
15
	private Optional<Instant> worldLoadedTime = Optional.empty();
16
	private long totalTicks;
17
	private long lastGameTime;
18
19
	public void onPlayerInfoReceived() {
20
		this.lastGameTime = -1L;
21
		if (this.worldLoadedTime.isEmpty()) {
22
			this.worldLoadedTime = Optional.of(Instant.now());
23
		}
24
	}
25
26
	public void setTime(final long gameTime) {
27
		if (this.lastGameTime != -1L) {
28
			this.totalTicks = this.totalTicks + Math.max(0L, gameTime - this.lastGameTime);
29
		}
30
31
		this.lastGameTime = gameTime;
32
	}
33
34
	private int getTimeInSecondsSinceLoad(final Instant loadedTime) {
35
		Duration timeBetween = Duration.between(loadedTime, Instant.now());
36
		return (int)timeBetween.toSeconds();
37
	}
38
39
	public void send(final TelemetryEventSender eventSender) {
40
		this.worldLoadedTime.ifPresent(loadedTime -> eventSender.send(TelemetryEventType.WORLD_UNLOADED, properties -> {
41
			properties.put(TelemetryProperty.SECONDS_SINCE_LOAD, this.getTimeInSecondsSinceLoad(loadedTime));
42
			properties.put(TelemetryProperty.TICKS_SINCE_LOAD, (int)this.totalTicks);
43
		}));
44
	}
45
}
46

Decompiled Minecraft 26.3 source of WorldUnloadEvent (net/minecraft/client/telemetry/events/WorldUnloadEvent.java) with Mojang official mappings, stored verbatim on the site.