RegistryNamespacedDefaultedByKey .java

net.minecraft.util.RegistryNamespacedDefaultedByKey (class): members: defaultValueKey, validateKey, getObjectById, defaultValue, register, getObject.

net.minecraft.utilclass53 linescommonextends RegistryNamespaced<K1.2 KB

API Surface (4)

void register(int id, K key, V value)
void validateKey()
V getObject(K name)
V getObjectById(int id)

Fields & Constants (2)

defaultValueKey
defaultValue

Code Graph: Dependencies (1)

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

Full Source

RegistryNamespacedDefaultedByKey.java53 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.util;
2
3
import org.apache.commons.lang3.Validate;
4
5
public class RegistryNamespacedDefaultedByKey<K, V> extends RegistryNamespaced<K, V>
6
{
7
    /** The key of the default value. */
8
    private final K defaultValueKey;
9
10
    /**
11
     * The default value for this registry, retrurned in the place of a null value.
12
     */
13
    private V defaultValue;
14
15
    public RegistryNamespacedDefaultedByKey(K defaultValueKeyIn)
16
    {
17
        this.defaultValueKey = defaultValueKeyIn;
18
    }
19
20
    public void register(int id, K key, V value)
21
    {
22
        if (this.defaultValueKey.equals(key))
23
        {
24
            this.defaultValue = value;
25
        }
26
27
        super.register(id, key, value);
28
    }
29
30
    /**
31
     * validates that this registry's key is non-null
32
     */
33
    public void validateKey()
34
    {
35
        Validate.notNull(this.defaultValueKey);
36
    }
37
38
    public V getObject(K name)
39
    {
40
        V v = super.getObject(name);
41
        return (V)(v == null ? this.defaultValue : v);
42
    }
43
44
    /**
45
     * Gets the object identified by the given ID.
46
     */
47
    public V getObjectById(int id)
48
    {
49
        V v = super.getObjectById(id);
50
        return (V)(v == null ? this.defaultValue : v);
51
    }
52
}
53

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