Class RegistryKey<T>

java.lang.Object
net.minecraft.util.registry.RegistryKey<T>
Type Parameters:
T - the type of the value

public class RegistryKey<T>
extends Object
Represents a key for a value in a registry in a context where a root registry is available.
See Also:
Registry.ROOT
  • Field Details

    • INSTANCES

      private static final Map<String,​RegistryKey<?>> INSTANCES
      A cache of all registry keys ever created.
    • registry

      private final Identifier registry
      The identifier of the registry in the root registry.
    • value

      private final Identifier value
      The identifier of the value in the registry specified by registry.
  • Constructor Details

  • Method Details

    • of

      public static <T> RegistryKey<T> of​(RegistryKey<? extends Registry<T>> registry, Identifier value)
      Creates a registry key for a value in a registry with a registry key for the value-holding registry in the root registry and an identifier of the value.

      You can call it like RegistryKey.of(Registry.ITEM_KEY, new Identifier("iron_ingot")) to create a registry key for iron ingot.

      Type Parameters:
      T - the type of the value
      Parameters:
      registry - the registry key of the registry in the root registry
      value - the identifier of the value
    • ofRegistry

      public static <T> RegistryKey<Registry<T>> ofRegistry​(Identifier registry)
      Creates a registry key for a registry in the root registry (registry of all registries) with an identifier for the registry.

      You can call it like RegistryKey.of(new Identifier("block")) to create a registry key for the block registry.

      Type Parameters:
      T - the element type of the registry
      Parameters:
      registry - the identifier of the registry
    • of

      private static <T> RegistryKey<T> of​(Identifier registry, Identifier value)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isOf

      public boolean isOf​(RegistryKey<? extends Registry<?>> registry)
      Returns whether this registry key belongs to the given registry (according to its type, not whether the registry actually contains this key).
      Parameters:
      registry - the key of the registry that this registry key should be inside
    • getValue

      public Identifier getValue()
    • createKeyFactory

      public static <T> Function<Identifier,​RegistryKey<T>> createKeyFactory​(RegistryKey<? extends Registry<T>> registry)
      Creates a function that converts an identifier to a registry key for the registry that registry refers to in the root registry.
      Parameters:
      registry - the reference to the value-holding registry in the root registry