TelemetryProperty .java

net.minecraft.client.telemetry.TelemetryProperty (record, 185 lines): members: exportKey, exporter, BACKEND_FAILURE_MISSING_CAPABILITIES, bool, OPT_IN.

net.minecraft.client.telemetryrecord185 linesclient9.1 KB

API Surface (14)

<T> TelemetryProperty<T> create(final String id, final String exportKey, final Codec<T> codec, final TelemetryProperty.Exporter<T> exporter)
TelemetryProperty<Boolean> bool(final String id, final String exportKey)
TelemetryProperty<String> string(final String id, final String exportKey)
TelemetryProperty<Integer> integer(final String id, final String exportKey)
TelemetryProperty<Long> makeLong(final String id, final String exportKey)
TelemetryProperty<UUID> uuid(final String id, final String exportKey)
TelemetryProperty<GameLoadTimesEvent.Measurement> gameLoadMeasurement(final String id, final String exportKey)
TelemetryProperty<LongList> longSamples(final String id, final String exportKey)
void export(final TelemetryPropertyMap input, final TelemetryPropertyContainer output)
MutableComponent title()
String toString()
int id()
String getSerializedName()
String getSerializedName()

Fields & Constants (37)

TIMESTAMP_FORMATTER
USER_ID
CLIENT_ID
MINECRAFT_SESSION_ID
GAME_VERSION
OPERATING_SYSTEM
PLATFORM
CLIENT_MODDED
LAUNCHER_NAME
BACKEND_NAME
BACKEND_FAILURE_MESSAGE
BACKEND_FAILURE_REASON
BACKEND_FAILURE_MISSING_CAPABILITIES
WORLD_SESSION_ID
SERVER_SESSION_ID
SERVER_MODDED
SERVER_TYPE
OPT_IN
EVENT_TIMESTAMP_UTC
GAME_MODE
REALMS_MAP_CONTENT
SECONDS_SINCE_LOAD
TICKS_SINCE_LOAD
FRAME_RATE_SAMPLES
RENDER_TIME_SAMPLES
USED_MEMORY_SAMPLES
NUMBER_OF_SAMPLES
RENDER_DISTANCE
DEDICATED_MEMORY_KB
WORLD_LOAD_TIME_MS
NEW_WORLD
LOAD_TIME_TOTAL_TIME_MS
LOAD_TIME_PRE_WINDOW_MS
LOAD_TIME_BOOTSTRAP_MS
LOAD_TIME_LOADING_OVERLAY_MS
ADVANCEMENT_ID
ADVANCEMENT_GAME_TIME

String literals (82)

"user_id"
"userId"
"client_id"
"clientId"
"minecraft_session_id"
"deviceSessionId"
"game_version"
"buildDisplayName"
"operating_system"
"buildPlatform"
"platform"
"client_modded"
"clientModded"
"launcher_name"
"launcherName"
"backend_name"
"backendName"
"backend_failure_message"
"backendFailureMessage"
"backend_failure_reason"
"backendFailureReason"
"backend_failure_missing_capabilities"
"backendFailureMissingCapabilities"
"world_session_id"

Full Source

TelemetryProperty.java185 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.telemetry;
2
3
import com.mojang.authlib.minecraft.TelemetryPropertyContainer;
4
import com.mojang.serialization.Codec;
5
import it.unimi.dsi.fastutil.longs.LongArrayList;
6
import it.unimi.dsi.fastutil.longs.LongList;
7
import java.time.Instant;
8
import java.time.ZoneId;
9
import java.time.ZoneOffset;
10
import java.time.format.DateTimeFormatter;
11
import java.util.UUID;
12
import java.util.function.Function;
13
import java.util.stream.Collectors;
14
import net.fabricmc.api.EnvType;
15
import net.fabricmc.api.Environment;
16
import net.minecraft.client.telemetry.events.GameLoadTimesEvent;
17
import net.minecraft.core.UUIDUtil;
18
import net.minecraft.network.chat.Component;
19
import net.minecraft.network.chat.MutableComponent;
20
import net.minecraft.util.ExtraCodecs;
21
import net.minecraft.util.StringRepresentable;
22
23
@Environment(EnvType.CLIENT)
24
public record TelemetryProperty<T>(String id, String exportKey, Codec<T> codec, TelemetryProperty.Exporter<T> exporter) {
25
	private static final DateTimeFormatter TIMESTAMP_FORMATTER = DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.from(ZoneOffset.UTC));
26
	public static final TelemetryProperty<String> USER_ID = string("user_id", "userId");
27
	public static final TelemetryProperty<String> CLIENT_ID = string("client_id", "clientId");
28
	public static final TelemetryProperty<UUID> MINECRAFT_SESSION_ID = uuid("minecraft_session_id", "deviceSessionId");
29
	public static final TelemetryProperty<String> GAME_VERSION = string("game_version", "buildDisplayName");
30
	public static final TelemetryProperty<String> OPERATING_SYSTEM = string("operating_system", "buildPlatform");
31
	public static final TelemetryProperty<String> PLATFORM = string("platform", "platform");
32
	public static final TelemetryProperty<Boolean> CLIENT_MODDED = bool("client_modded", "clientModded");
33
	public static final TelemetryProperty<String> LAUNCHER_NAME = string("launcher_name", "launcherName");
34
	public static final TelemetryProperty<String> BACKEND_NAME = string("backend_name", "backendName");
35
	public static final TelemetryProperty<String> BACKEND_FAILURE_MESSAGE = string("backend_failure_message", "backendFailureMessage");
36
	public static final TelemetryProperty<String> BACKEND_FAILURE_REASON = string("backend_failure_reason", "backendFailureReason");
37
	public static final TelemetryProperty<String> BACKEND_FAILURE_MISSING_CAPABILITIES = string(
38
		"backend_failure_missing_capabilities", "backendFailureMissingCapabilities"
39
	);
40
	public static final TelemetryProperty<UUID> WORLD_SESSION_ID = uuid("world_session_id", "worldSessionId");
41
	public static final TelemetryProperty<UUID> SERVER_SESSION_ID = uuid("server_session_id", "GlobalMultiplayerCorrelationId");
42
	public static final TelemetryProperty<Boolean> SERVER_MODDED = bool("server_modded", "serverModded");
43
	public static final TelemetryProperty<TelemetryProperty.ServerType> SERVER_TYPE = create(
44
		"server_type", "serverType", TelemetryProperty.ServerType.CODEC, (output, key, value) -> output.addProperty(key, value.getSerializedName())
45
	);
46
	public static final TelemetryProperty<Boolean> OPT_IN = bool("opt_in", "isOptional");
47
	public static final TelemetryProperty<Instant> EVENT_TIMESTAMP_UTC = create(
48
		"event_timestamp_utc", "eventTimestampUtc", ExtraCodecs.INSTANT_ISO8601, (output, key, value) -> output.addProperty(key, TIMESTAMP_FORMATTER.format(value))
49
	);
50
	public static final TelemetryProperty<TelemetryProperty.GameMode> GAME_MODE = create(
51
		"game_mode", "playerGameMode", TelemetryProperty.GameMode.CODEC, (output, key, value) -> output.addProperty(key, value.id())
52
	);
53
	public static final TelemetryProperty<String> REALMS_MAP_CONTENT = string("realms_map_content", "realmsMapContent");
54
	public static final TelemetryProperty<Integer> SECONDS_SINCE_LOAD = integer("seconds_since_load", "secondsSinceLoad");
55
	public static final TelemetryProperty<Integer> TICKS_SINCE_LOAD = integer("ticks_since_load", "ticksSinceLoad");
56
	public static final TelemetryProperty<LongList> FRAME_RATE_SAMPLES = longSamples("frame_rate_samples", "serializedFpsSamples");
57
	public static final TelemetryProperty<LongList> RENDER_TIME_SAMPLES = longSamples("render_time_samples", "serializedRenderTimeSamples");
58
	public static final TelemetryProperty<LongList> USED_MEMORY_SAMPLES = longSamples("used_memory_samples", "serializedUsedMemoryKbSamples");
59
	public static final TelemetryProperty<Integer> NUMBER_OF_SAMPLES = integer("number_of_samples", "numSamples");
60
	public static final TelemetryProperty<Integer> RENDER_DISTANCE = integer("render_distance", "renderDistance");
61
	public static final TelemetryProperty<Integer> DEDICATED_MEMORY_KB = integer("dedicated_memory_kb", "dedicatedMemoryKb");
62
	public static final TelemetryProperty<Integer> WORLD_LOAD_TIME_MS = integer("world_load_time_ms", "worldLoadTimeMs");
63
	public static final TelemetryProperty<Boolean> NEW_WORLD = bool("new_world", "newWorld");
64
	public static final TelemetryProperty<GameLoadTimesEvent.Measurement> LOAD_TIME_TOTAL_TIME_MS = gameLoadMeasurement(
65
		"load_time_total_time_ms", "loadTimeTotalTimeMs"
66
	);
67
	public static final TelemetryProperty<GameLoadTimesEvent.Measurement> LOAD_TIME_PRE_WINDOW_MS = gameLoadMeasurement(
68
		"load_time_pre_window_ms", "loadTimePreWindowMs"
69
	);
70
	public static final TelemetryProperty<GameLoadTimesEvent.Measurement> LOAD_TIME_BOOTSTRAP_MS = gameLoadMeasurement(
71
		"load_time_bootstrap_ms", "loadTimeBootstrapMs"
72
	);
73
	public static final TelemetryProperty<GameLoadTimesEvent.Measurement> LOAD_TIME_LOADING_OVERLAY_MS = gameLoadMeasurement(
74
		"load_time_loading_overlay_ms", "loadTimeLoadingOverlayMs"
75
	);
76
	public static final TelemetryProperty<String> ADVANCEMENT_ID = string("advancement_id", "advancementId");
77
	public static final TelemetryProperty<Long> ADVANCEMENT_GAME_TIME = makeLong("advancement_game_time", "advancementGameTime");
78
79
	public static <T> TelemetryProperty<T> create(final String id, final String exportKey, final Codec<T> codec, final TelemetryProperty.Exporter<T> exporter) {
80
		return new TelemetryProperty<>(id, exportKey, codec, exporter);
81
	}
82
83
	public static TelemetryProperty<Boolean> bool(final String id, final String exportKey) {
84
		return create(id, exportKey, Codec.BOOL, TelemetryPropertyContainer::addProperty);
85
	}
86
87
	public static TelemetryProperty<String> string(final String id, final String exportKey) {
88
		return create(id, exportKey, Codec.STRING, TelemetryPropertyContainer::addProperty);
89
	}
90
91
	public static TelemetryProperty<Integer> integer(final String id, final String exportKey) {
92
		return create(id, exportKey, Codec.INT, TelemetryPropertyContainer::addProperty);
93
	}
94
95
	public static TelemetryProperty<Long> makeLong(final String id, final String exportKey) {
96
		return create(id, exportKey, Codec.LONG, TelemetryPropertyContainer::addProperty);
97
	}
98
99
	public static TelemetryProperty<UUID> uuid(final String id, final String exportKey) {
100
		return create(id, exportKey, UUIDUtil.STRING_CODEC, (output, key, value) -> output.addProperty(key, value.toString()));
101
	}
102
103
	public static TelemetryProperty<GameLoadTimesEvent.Measurement> gameLoadMeasurement(final String id, final String exportKey) {
104
		return create(id, exportKey, GameLoadTimesEvent.Measurement.CODEC, (output, key, value) -> output.addProperty(key, value.millis()));
105
	}
106
107
	public static TelemetryProperty<LongList> longSamples(final String id, final String exportKey) {
108
		return create(
109
			id,
110
			exportKey,
111
			Codec.LONG.listOf().xmap(LongArrayList::new, Function.identity()),
112
			(output, key, value) -> output.addProperty(key, value.longStream().mapToObj(String::valueOf).collect(Collectors.joining(";")))
113
		);
114
	}
115
116
	public void export(final TelemetryPropertyMap input, final TelemetryPropertyContainer output) {
117
		T value = input.get(this);
118
		if (value != null) {
119
			this.exporter.apply(output, this.exportKey, value);
120
		} else {
121
			output.addNullProperty(this.exportKey);
122
		}
123
	}
124
125
	public MutableComponent title() {
126
		return Component.translatable("telemetry.property." + this.id + ".title");
127
	}
128
129
	@Override
130
	public String toString() {
131
		return "TelemetryProperty[" + this.id + "]";
132
	}
133
134
	@Environment(EnvType.CLIENT)
135
	public interface Exporter<T> {
136
		void apply(TelemetryPropertyContainer output, String key, T value);
137
	}
138
139
	@Environment(EnvType.CLIENT)
140
	public enum GameMode implements StringRepresentable {
141
		SURVIVAL("survival", 0),
142
		CREATIVE("creative", 1),
143
		ADVENTURE("adventure", 2),
144
		SPECTATOR("spectator", 6),
145
		HARDCORE("hardcore", 99);
146
147
		public static final Codec<TelemetryProperty.GameMode> CODEC = StringRepresentable.fromEnum(TelemetryProperty.GameMode::values);
148
		private final String key;
149
		private final int id;
150
151
		GameMode(final String key, final int id) {
152
			this.key = key;
153
			this.id = id;
154
		}
155
156
		public int id() {
157
			return this.id;
158
		}
159
160
		@Override
161
		public String getSerializedName() {
162
			return this.key;
163
		}
164
	}
165
166
	@Environment(EnvType.CLIENT)
167
	public enum ServerType implements StringRepresentable {
168
		REALM("realm"),
169
		LOCAL("local"),
170
		OTHER("server");
171
172
		public static final Codec<TelemetryProperty.ServerType> CODEC = StringRepresentable.fromEnum(TelemetryProperty.ServerType::values);
173
		private final String key;
174
175
		ServerType(final String key) {
176
			this.key = key;
177
		}
178
179
		@Override
180
		public String getSerializedName() {
181
			return this.key;
182
		}
183
	}
184
}
185

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