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 namespace, String path)
  • Method Details

    • createUntrusted

      private static ResourceLocation createUntrusted(String namespace, String path)
    • fromNamespaceAndPath

      public static ResourceLocation fromNamespaceAndPath(String namespace, String path)
    • parse

      public static ResourceLocation parse(String location)
    • withDefaultNamespace

      public static ResourceLocation withDefaultNamespace(String location)
    • tryParse

      @Nullable public static ResourceLocation tryParse(String location)
      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:
      location - 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 namespace, String path)
    • bySeparator

      public static ResourceLocation bySeparator(String location, char seperator)
    • tryBySeparator

      @Nullable public static ResourceLocation tryBySeparator(String location, char seperator)
    • read

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

      public String getPath()
    • getNamespace

      public String getNamespace()
    • withPath

      public ResourceLocation withPath(String path)
    • withPath

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

      public ResourceLocation withPrefix(String pathPrefix)
    • withSuffix

      public ResourceLocation withSuffix(String pathSuffix)
    • toString

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

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

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

      public int compareTo(ResourceLocation other)
      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 type)
    • toLanguageKey

      public String toLanguageKey(String type, String key)
    • readGreedy

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

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

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

      public static boolean isAllowedInResourceLocation(char character)
    • isValidPath

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

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

      private static String assertValidNamespace(String namespace, String path)
    • validPathChar

      public static boolean validPathChar(char pathChar)
    • validNamespaceChar

      public static boolean validNamespaceChar(char namespaceChar)
    • assertValidPath

      private static String assertValidPath(String namespace, String path)