ClassTreeIdRegistry .java

net.minecraft.util.ClassTreeIdRegistry (class, 39 lines): members: classToLastIdCache, getLastIdFor, NO_ID_VALUE, define, getCount. imports: Object2IntMap.

net.minecraft.utilclass39 linescommon996 B

API Surface (3)

int getLastIdFor(final Class<?> clazz)
int getCount(final Class<?> clazz)
int define(final Class<?> clazz)

Fields & Constants (2)

NO_ID_VALUE
classToLastIdCache

Full Source

ClassTreeIdRegistry.java39 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util;
2
3
import it.unimi.dsi.fastutil.objects.Object2IntMap;
4
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
5
6
public class ClassTreeIdRegistry {
7
	public static final int NO_ID_VALUE = -1;
8
	private final Object2IntMap<Class<?>> classToLastIdCache = Util.make(new Object2IntOpenHashMap<>(), map -> map.defaultReturnValue(-1));
9
10
	public int getLastIdFor(final Class<?> clazz) {
11
		int id = this.classToLastIdCache.getInt(clazz);
12
		if (id != -1) {
13
			return id;
14
		}
15
16
		Class<?> superclass = clazz;
17
18
		while ((superclass = superclass.getSuperclass()) != Object.class) {
19
			int newId = this.classToLastIdCache.getInt(superclass);
20
			if (newId != -1) {
21
				return newId;
22
			}
23
		}
24
25
		return -1;
26
	}
27
28
	public int getCount(final Class<?> clazz) {
29
		return this.getLastIdFor(clazz) + 1;
30
	}
31
32
	public int define(final Class<?> clazz) {
33
		int id = this.getLastIdFor(clazz);
34
		int nextId = id == -1 ? 0 : id + 1;
35
		this.classToLastIdCache.put(clazz, nextId);
36
		return nextId;
37
	}
38
}
39

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