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:
    • ALLOWED_NAMESPACE_CHARACTERS

      public static final String ALLOWED_NAMESPACE_CHARACTERS
      See Also:
    • namespace

      private final String namespace
    • path

      private final String path
  • Constructor Details

    • Identifier

      private Identifier(String namespace, String path)
  • Method Details

    • createUntrusted

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

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

      public static Identifier parse(String identifier)
    • withDefaultNamespace

      public static Identifier withDefaultNamespace(String path)
    • tryParse

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

      public static Identifier bySeparator(String identifier, char separator)
    • tryBySeparator

      public static @Nullable Identifier tryBySeparator(String identifier, char separator)
    • read

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

      public String getPath()
    • getNamespace

      public String getNamespace()
    • withPath

      public Identifier withPath(String newPath)
    • withPath

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

      public Identifier withPrefix(String prefix)
    • withSuffix

      public Identifier withSuffix(String suffix)
    • toString

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

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

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

      public int compareNamespaced(Identifier o)
    • compareTo

      public int compareTo(Identifier o)
      Specified by:
      compareTo in interface Comparable<Identifier>
    • resolveAgainst

      public Path resolveAgainst(Path root)
    • toDebugFileName

      public String toDebugFileName()
    • toLanguageKey

      public String toLanguageKey()
    • toShortLanguageKey

      public String toShortLanguageKey()
    • toShortString

      public String toShortString()
    • toLanguageKey

      public String toLanguageKey(String prefix)
    • toLanguageKey

      public String toLanguageKey(String prefix, String suffix)
    • readGreedy

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

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

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

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

      public static boolean validNamespaceChar(char c)
    • assertValidPath

      private static String assertValidPath(String namespace, String path)