Class RegistryHelper

java.lang.Object
com.pixelmonmod.pixelmon.api.util.helpers.RegistryHelper

public class RegistryHelper extends Object
Utility class for registry related operations.
To access the registries for a specific side you can use ClientRegistryHelper.getRegistryAccess() or ServerRegistryHelper.getRegistryAccess(). However, if you want to obtain registry access and cannot be certain which side you are on then you should always use registryAccess().
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    compareKeys(net.minecraft.resources.ResourceKey<?> a, net.minecraft.resources.ResourceKey<?> b)
    Compares two ResourceKeys to check if they are equal.
    static <T> T
    get(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registryKey, net.minecraft.resources.ResourceKey<T> location)
    Gets the element for the given ResourceKey in the given registry.
    static <T> T
    get(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registryKey, net.minecraft.resources.ResourceLocation location)
    Gets the element for the given ResourceLocation in the given registry.
    static <T> Collection<T>
    getAll(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registry)
    Gets all elements for the registry defined by the given ResourceKey.
    static <T> net.minecraft.core.Holder<T>
    getHolder(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registryKey, net.minecraft.resources.ResourceKey<T> location)
    Gets the ResourceKey for the given element in the given registry.
    static <T> net.minecraft.core.Holder<T>
    getHolder(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registryKey, net.minecraft.resources.ResourceLocation location)
    Gets the ResourceLocation for the given element in the given registry.
    static <T> net.minecraft.core.Holder<T>
    getHolder(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registryKey, T element)
    Gets the Holder for the given element in the given registry.
    static <T> net.minecraft.resources.ResourceKey<T>
    getKey(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registry, String resourceLocation)
    Gets the ResourceKey for the given element at the resource location in the given registry
    static <T> net.minecraft.resources.ResourceKey<T>
    getKey(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registry, net.minecraft.resources.ResourceLocation resourceLocation)
    Gets the ResourceKey for the given element at the resource location in the given registry
    static <T> net.minecraft.resources.ResourceLocation
    getKey(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registry, T element)
    Gets the ResourceLocation for the given element in the given registry.
    static <T> net.minecraft.core.HolderSet<T>
    getTag(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registryKey, net.minecraft.tags.TagKey<T> location)
    Converts a TagKey to a HolderSet of the elements in the tag.
    static <T> net.minecraft.network.chat.MutableComponent
    getTranslated(net.minecraft.core.Holder<T> holder)
    Converts the given Holder to a MutableComponent with the translation key of the holder.
    static <T> net.minecraft.network.chat.MutableComponent
    getTranslated(net.minecraft.resources.ResourceKey<T> resourceKey)
    Converts the given ResourceKey to a MutableComponent with the translation key of the key.
    static <T> String
    getTranslationKey(net.minecraft.core.Holder<T> holder)
    Converts the given Holder to a String of the translation key of the holder.
    static <T> String
    getTranslationKey(net.minecraft.resources.ResourceKey<T> resourceKey)
    Converts the given ResourceKey to a String of the translation key of the key.
    static net.minecraft.core.RegistryAccess.Frozen
    Gets the correct RegistryAccess for the current side

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RegistryHelper

      public RegistryHelper()
  • Method Details

    • compareKeys

      public static boolean compareKeys(net.minecraft.resources.ResourceKey<?> a, net.minecraft.resources.ResourceKey<?> b)
      Compares two ResourceKeys to check if they are equal.
      Parameters:
      a - The first key
      b - The second key
      Returns:
      True if the keys are equal, false otherwise
    • getAll

      public static <T> Collection<T> getAll(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registry)
      Gets all elements for the registry defined by the given ResourceKey.
      Type Parameters:
      T - The type of the registry
      Parameters:
      registry - The registry key
      Returns:
      A collection of all elements in the registry
    • getKey

      public static <T> net.minecraft.resources.ResourceLocation getKey(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registry, T element)
      Gets the ResourceLocation for the given element in the given registry.
      Type Parameters:
      T - The type of the registry
      Parameters:
      registry - The registry key of the registry
      element - The element
      Returns:
      The ResourceLocation of the element
    • getKey

      public static <T> net.minecraft.resources.ResourceKey<T> getKey(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registry, String resourceLocation)
      Gets the ResourceKey for the given element at the resource location in the given registry
      Type Parameters:
      T - The type of the registry
      Parameters:
      registry - The registry key of the registry
      resourceLocation - The resource location of the element
      Returns:
      The ResourceKey of the element
    • getKey

      public static <T> net.minecraft.resources.ResourceKey<T> getKey(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registry, net.minecraft.resources.ResourceLocation resourceLocation)
      Gets the ResourceKey for the given element at the resource location in the given registry
      Type Parameters:
      T - The type of the registry
      Parameters:
      registry - The registry key of the registry
      resourceLocation - The resource location of the element
      Returns:
      The ResourceKey of the element
    • getTranslated

      public static <T> net.minecraft.network.chat.MutableComponent getTranslated(net.minecraft.core.Holder<T> holder)
      Converts the given Holder to a MutableComponent with the translation key of the holder.
      Type Parameters:
      T - The type of the holder
      Parameters:
      holder - The holder to translate
      Returns:
      The translated component
    • getTranslated

      public static <T> net.minecraft.network.chat.MutableComponent getTranslated(net.minecraft.resources.ResourceKey<T> resourceKey)
      Converts the given ResourceKey to a MutableComponent with the translation key of the key.
      Type Parameters:
      T - The type of the holder
      Parameters:
      resourceKey - The key to translate
      Returns:
      The translated component
    • getTranslationKey

      public static <T> String getTranslationKey(net.minecraft.core.Holder<T> holder)
      Converts the given Holder to a String of the translation key of the holder.
      Type Parameters:
      T - The type of the holder
      Parameters:
      holder - The holder to translate
      Returns:
      The translation key
    • getTranslationKey

      public static <T> String getTranslationKey(net.minecraft.resources.ResourceKey<T> resourceKey)
      Converts the given ResourceKey to a String of the translation key of the key.
      Type Parameters:
      T - The type of the holder
      Parameters:
      resourceKey - The key to translate
      Returns:
      The translation key
    • get

      public static <T> T get(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registryKey, net.minecraft.resources.ResourceLocation location)
      Gets the element for the given ResourceLocation in the given registry.
      Note: Can return null if no element is found.
      Type Parameters:
      T - The type of the registry
      Parameters:
      registryKey - The registry key of the registry
      location - The resource location of the element
      Returns:
      The element
    • get

      public static <T> T get(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registryKey, net.minecraft.resources.ResourceKey<T> location)
      Gets the element for the given ResourceKey in the given registry.
      Note: Can return null if no element is found.
      Type Parameters:
      T - The type of the registry
      Parameters:
      registryKey - The registry key of the registry
      location - The resource location of the element
      Returns:
      The element
    • getHolder

      public static <T> net.minecraft.core.Holder<T> getHolder(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registryKey, T element)
      Gets the Holder for the given element in the given registry.
      Note: Can return null if no element is found.
      Type Parameters:
      T - The type of the registry
      Parameters:
      registryKey - The registry key of the registry
      element - The element
      Returns:
      The holder
    • getHolder

      public static <T> net.minecraft.core.Holder<T> getHolder(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registryKey, net.minecraft.resources.ResourceLocation location)
      Gets the ResourceLocation for the given element in the given registry.
      Note: Can return null if no element is found.
      Type Parameters:
      T - The type of the registry
      Parameters:
      registryKey - The registry key of the registry
      location - The location of the element
      Returns:
      The holder
    • getHolder

      public static <T> net.minecraft.core.Holder<T> getHolder(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registryKey, net.minecraft.resources.ResourceKey<T> location)
      Gets the ResourceKey for the given element in the given registry.
      Note: Can return null if no element is found.
      Type Parameters:
      T - The type of the registry
      Parameters:
      registryKey - The registry key of the registry
      location - The location of the element
      Returns:
      The holder
    • getTag

      public static <T> net.minecraft.core.HolderSet<T> getTag(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registryKey, net.minecraft.tags.TagKey<T> location)
      Converts a TagKey to a HolderSet of the elements in the tag.
      Type Parameters:
      T - The type of the registry
      Parameters:
      registryKey - The registry key of the registry
      location - The tag key
      Returns:
      The holder set
    • registryAccess

      public static net.minecraft.core.RegistryAccess.Frozen registryAccess()
      Gets the correct RegistryAccess for the current side
      Returns:
      The registry access