File size: 1,191 Bytes
d46f4a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package net.minecraft.util;

import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import net.minecraft.Util;

public class ClassTreeIdRegistry {
    public static final int NO_ID_VALUE = -1;
    private final Object2IntMap<Class<?>> classToLastIdCache = Util.make(new Object2IntOpenHashMap<>(), p_327761_ -> p_327761_.defaultReturnValue(-1));

    public int getLastIdFor(Class<?> p_330417_) {
        int i = this.classToLastIdCache.getInt(p_330417_);
        if (i != -1) {
            return i;
        } else {
            Class<?> oclass = p_330417_;

            while ((oclass = oclass.getSuperclass()) != Object.class) {
                int j = this.classToLastIdCache.getInt(oclass);
                if (j != -1) {
                    return j;
                }
            }

            return -1;
        }
    }

    public int getCount(Class<?> p_335504_) {
        return this.getLastIdFor(p_335504_) + 1;
    }

    public int define(Class<?> p_334105_) {
        int i = this.getLastIdFor(p_334105_);
        int j = i == -1 ? 0 : i + 1;
        this.classToLastIdCache.put(p_334105_, j);
        return j;
    }
}