Class Identifier

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

public final class Identifier extends Object implements Comparable<Identifier>
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 an Identifier.

See Also:
  • Field Details

    • CODEC

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

      public static final StreamCodec<io.netty.buffer.ByteBuf,Identifier> 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

    • Identifier

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

    • createUntrusted

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

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

      public static Identifier parse(String pLocation)
    • withDefaultNamespace

      public static Identifier withDefaultNamespace(String pLocation)
    • tryParse

      public static @Nullable Identifier 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

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

      public static Identifier bySeparator(String pLocation, char pSeparator)
    • tryBySeparator

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

      public static com.mojang.serialization.DataResult<Identifier> read(String pLocation)
    • getPath

      public String getPath()
    • getNamespace

      public String getNamespace()
    • withPath

      public Identifier withPath(String pPath)
    • withPath

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

      public Identifier withPrefix(String pPathPrefix)
    • withSuffix

      public Identifier 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(Identifier pOther)
      Specified by:
      compareTo in interface Comparable<Identifier>
    • compareNamespaced

      public int compareNamespaced(Identifier o)
    • toDebugFileName

      public String toDebugFileName()
    • toLanguageKey

      public String toLanguageKey()
    • toShortLanguageKey

      public String toShortLanguageKey()
    • toShortString

      public String toShortString()
    • toLanguageKey

      public String toLanguageKey(String pType)
    • toLanguageKey

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

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

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

      public static Identifier readNonEmpty(com.mojang.brigadier.StringReader pReader) throws com.mojang.brigadier.exceptions.CommandSyntaxException
      Throws:
      com.mojang.brigadier.exceptions.CommandSyntaxException
    • isAllowedInIdentifier

      public static boolean isAllowedInIdentifier(char pC)
    • 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)