Class ResourceLocation

java.lang.Object
net.minecraft.resources.ResourceLocation
All Implemented Interfaces:
Comparable<ResourceLocation>

public final class ResourceLocation extends Object implements Comparable<ResourceLocation>
An immutable location of a resource, in terms of a path and namespace.

This is used as an identifier for a resource, usually for those housed in a Registry, such as blocks and items.

minecraft is always taken as the default namespace for a resource location when none is explicitly stated. When using this for registering objects, this namespace should only be used for resources added by Minecraft itself.

Generally, and by the implementation of toString(), the string representation of this class is expressed in the form namespace:path. The colon is also used as the default separator for parsing strings as a ResourceLocation.

See Also:
  • Field Details

    • CODEC

      public static final com.mojang.serialization.Codec<ResourceLocation> CODEC
    • STREAM_CODEC

      public static final StreamCodec<io.netty.buffer.ByteBuf,ResourceLocation> STREAM_CODEC
    • ERROR_INVALID

      public static final com.mojang.brigadier.exceptions.SimpleCommandExceptionType ERROR_INVALID
    • NAMESPACE_SEPARATOR

      public static final char NAMESPACE_SEPARATOR
      See Also:
    • DEFAULT_NAMESPACE

      public static final String DEFAULT_NAMESPACE
      See Also:
    • REALMS_NAMESPACE

      public static final String REALMS_NAMESPACE
      See Also:
    • namespace

      private final String namespace
    • path

      private final String path
  • Constructor Details

    • ResourceLocation

      private ResourceLocation(String pNamespace, String pPath)
  • Method Details

    • createUntrusted

      private static ResourceLocation createUntrusted(String pNamespace, String pPath)
    • fromNamespaceAndPath

      public static ResourceLocation fromNamespaceAndPath(String pNamespace, String pPath)
    • parse

      public static ResourceLocation parse(String p_350801_)
    • withDefaultNamespace

      public static ResourceLocation withDefaultNamespace(String pLocation)
    • tryParse

      @Nullable public static ResourceLocation tryParse(String pLocation)
      Attempts to parse the specified location as a ResourceLocation by splitting it into a namespace and path by a colon.

      If no colon is present in the location, the namespace defaults to minecraft, taking the location as the path.

      Parameters:
      pLocation - the location string to try to parse as a ResourceLocation
      Returns:
      the parsed resource location; otherwise null if there is a non [a-z0-9_.-] character in the decomposed namespace or a non [a-z0-9/._-] character in the decomposed path
      See Also:
      • invalid reference
        #of(String, char)
    • tryBuild

      @Nullable public static ResourceLocation tryBuild(String pNamespace, String pPath)
    • bySeparator

      public static ResourceLocation bySeparator(String pLocation, char pSeperator)
    • tryBySeparator

      @Nullable public static ResourceLocation tryBySeparator(String pLocation, char pSeperator)
    • read

      public static com.mojang.serialization.DataResult<ResourceLocation> read(String p_135838_)
    • getPath

      public String getPath()
    • getNamespace

      public String getNamespace()
    • withPath

      public ResourceLocation withPath(String pPath)
    • withPath

      public ResourceLocation withPath(UnaryOperator<String> pPathOperator)
    • withPrefix

      public ResourceLocation withPrefix(String pPathPrefix)
    • withSuffix

      public ResourceLocation withSuffix(String pPathSuffix)
    • toString

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

      public boolean equals(Object pOther)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(ResourceLocation pOther)
      Specified by:
      compareTo in interface Comparable<ResourceLocation>
    • compareNamespaced

      public int compareNamespaced(ResourceLocation o)
    • toDebugFileName

      public String toDebugFileName()
    • toLanguageKey

      public String toLanguageKey()
    • toShortLanguageKey

      public String toShortLanguageKey()
    • toLanguageKey

      public String toLanguageKey(String pType)
    • toLanguageKey

      public String toLanguageKey(String pType, String pKey)
    • readGreedy

      private static String readGreedy(com.mojang.brigadier.StringReader p_335690_)
    • read

      public static ResourceLocation read(com.mojang.brigadier.StringReader p_135819_) throws com.mojang.brigadier.exceptions.CommandSyntaxException
      Throws:
      com.mojang.brigadier.exceptions.CommandSyntaxException
    • readNonEmpty

      public static ResourceLocation readNonEmpty(com.mojang.brigadier.StringReader p_336027_) throws com.mojang.brigadier.exceptions.CommandSyntaxException
      Throws:
      com.mojang.brigadier.exceptions.CommandSyntaxException
    • isAllowedInResourceLocation

      public static boolean isAllowedInResourceLocation(char pCharacter)
    • isValidPath

      public static boolean isValidPath(String pPath)
      Returns:
      true if the specified path is valid: consists only of [a-z0-9/._-] characters
    • isValidNamespace

      public static boolean isValidNamespace(String pNamespace)
      Returns:
      true if the specified namespace is valid: consists only of [a-z0-9_.-] characters
    • assertValidNamespace

      private static String assertValidNamespace(String pNamespace, String pPath)
    • validPathChar

      public static boolean validPathChar(char pPathChar)
    • validNamespaceChar

      public static boolean validNamespaceChar(char pNamespaceChar)
    • assertValidPath

      private static String assertValidPath(String pNamespace, String pPath)