Class Identifier

java.lang.Object
net.minecraft.util.Identifier
All Implemented Interfaces:
Comparable<Identifier>
Direct Known Subclasses:
ModelIdentifier

public class Identifier extends Object implements Comparable<Identifier>
An identifier used to identify things. This is also known as "resource location", "namespaced ID", "location", or just "ID". This is a non-typed immutable object, and identifies things using a combination of namespace and path. Identifiers should always be compared using equals(java.lang.Object) method, not ==.

Format

Identifiers are formatted as <namespace>:<path>. If the namespace and colon are omitted, the namespace defaults to "minecraft".

The namespace and path must contain only ASCII lowercase letters ( [a-z]), ASCII digits ([0-9]), or the characters _, ., and -. The path can also contain the standard path separator /. Uppercase letters cannot be used. isValid(java.lang.String) can be used to check whether a string is a valid identifier. When handling externally provided identifiers, it should either validate or use tryParse(java.lang.String) instead of the constructor. Another common mistake is using a formatted string with %d or %f to construct an identifier without specifying the locate explicitly, as they are not guaranteed to be ASCII digits in certain locales. Use String.format(Locale, String, Object[]) with Locale.ROOT instead of String.formatted(java.lang.Object...).

Namespace

The namespace of an identifier identifies the origin of the thing. For example, two mods to the game could both add an item with the ID "orange"; the namespace is used to differentiate the two. (The convention is to use the ID assigned to the mod as the namespace.)

A namespace only determines the source of an identifier, and does not determine its purpose; so long as two identifiers are used for different purposes, they can share the namespace and path. For example, the identifier minecraft:dirt is shared by blocks and items. There is no need to change the identifier to, say, minecraft_block:dirt or minecraft_item:dirt.

Several namespaces are reserved for vanilla use. While those identifiers can be used for referencing and overwriting vanilla things, it is highly discouraged to use them to identify your own, new things. For example, a modded block or a new biome added by data packs should not use the reserved namespaces, but it's fine to use them when modifying an existing biome under that namespace. The reserved namespaces are "minecraft", brigadier, and "realms". "minecraft" is also the default namespace used when no namespace is provided.

Path

The path of the identifier identifies the thing within the namespace, such as between different items from the same mod. Additionally, this is sometimes used to refer to a file path, such as in textures.

Creation

There are many ways to create a new identifier:

Using Identifier

Identifiers identify several objects in the game. Registry holds objects, such as blocks and items, that are identified by an identifier. Textures are also identified using an identifier; such an identifier is represented as a file path with an extension, such as minecraft:textures/entity/pig/pig.png.

The string representation of the identifier (<namespace>:<path>) can be obtained by calling toString(). This always includes the namespace. An identifier can be converted to a translation key using toTranslationKey(String) method.

RegistryKey

Identifier is not type-aware; minecraft:tnt could refer to a TNT block, a TNT item, or a TNT entity. To identify a registered object uniquely, RegistryKey can be used. A registry key is a combination of the registry's identifier and the object's identifier.

Mappings:
Namespace Name
named net/minecraft/util/Identifier
intermediary net/minecraft/class_2960
official alf
  • Field Details

    • CODEC

      public static final com.mojang.serialization.Codec<Identifier> CODEC
      Mappings:
      Namespace Name Mixin selector
      named CODEC Lnet/minecraft/util/Identifier;CODEC:Lcom/mojang/serialization/Codec;
      intermediary field_25139 Lnet/minecraft/class_2960;field_25139:Lcom/mojang/serialization/Codec;
      official a Lalf;a:Lcom/mojang/serialization/Codec;
    • PACKET_CODEC

      public static final PacketCodec<ByteBuf,Identifier> PACKET_CODEC
      Mappings:
      Namespace Name Mixin selector
      named PACKET_CODEC Lnet/minecraft/util/Identifier;PACKET_CODEC:Lnet/minecraft/network/codec/PacketCodec;
      intermediary field_48267 Lnet/minecraft/class_2960;field_48267:Lnet/minecraft/class_9139;
      official b Lalf;b:Lzn;
    • COMMAND_EXCEPTION

      public static final com.mojang.brigadier.exceptions.SimpleCommandExceptionType COMMAND_EXCEPTION
      Mappings:
      Namespace Name Mixin selector
      named COMMAND_EXCEPTION Lnet/minecraft/util/Identifier;COMMAND_EXCEPTION:Lcom/mojang/brigadier/exceptions/SimpleCommandExceptionType;
      intermediary field_13354 Lnet/minecraft/class_2960;field_13354:Lcom/mojang/brigadier/exceptions/SimpleCommandExceptionType;
      official c Lalf;c:Lcom/mojang/brigadier/exceptions/SimpleCommandExceptionType;
    • NAMESPACE_SEPARATOR

      public static final char NAMESPACE_SEPARATOR
      See Also:
      Mappings:
      Namespace Name Mixin selector
      named NAMESPACE_SEPARATOR Lnet/minecraft/util/Identifier;NAMESPACE_SEPARATOR:C
      intermediary field_33380 Lnet/minecraft/class_2960;field_33380:C
      official d Lalf;d:C
    • DEFAULT_NAMESPACE

      public static final String DEFAULT_NAMESPACE
      See Also:
      Mappings:
      Namespace Name Mixin selector
      named DEFAULT_NAMESPACE Lnet/minecraft/util/Identifier;DEFAULT_NAMESPACE:Ljava/lang/String;
      intermediary field_33381 Lnet/minecraft/class_2960;field_33381:Ljava/lang/String;
      official e Lalf;e:Ljava/lang/String;
    • REALMS_NAMESPACE

      public static final String REALMS_NAMESPACE
      See Also:
      Mappings:
      Namespace Name Mixin selector
      named REALMS_NAMESPACE Lnet/minecraft/util/Identifier;REALMS_NAMESPACE:Ljava/lang/String;
      intermediary field_33382 Lnet/minecraft/class_2960;field_33382:Ljava/lang/String;
      official f Lalf;f:Ljava/lang/String;
    • namespace

      private final String namespace
      Mappings:
      Namespace Name Mixin selector
      named namespace Lnet/minecraft/util/Identifier;namespace:Ljava/lang/String;
      intermediary field_13353 Lnet/minecraft/class_2960;field_13353:Ljava/lang/String;
      official g Lalf;g:Ljava/lang/String;
    • path

      private final String path
      Mappings:
      Namespace Name Mixin selector
      named path Lnet/minecraft/util/Identifier;path:Ljava/lang/String;
      intermediary field_13355 Lnet/minecraft/class_2960;field_13355:Ljava/lang/String;
      official h Lalf;h:Ljava/lang/String;
  • Constructor Details

    • Identifier

      protected Identifier(String namespace, String path, @Nullable @Nullable Identifier.ExtraData extraData)
      Mappings:
      Namespace Name Mixin selector
      named <init> Lnet/minecraft/util/Identifier;<init>(Ljava/lang/String;Ljava/lang/String;Lnet/minecraft/util/Identifier$ExtraData;)V
      intermediary <init> Lnet/minecraft/class_2960;<init>(Ljava/lang/String;Ljava/lang/String;Lnet/minecraft/class_2960$class_7658;)V
      official <init> Lalf;<init>(Ljava/lang/String;Ljava/lang/String;Lalf$a;)V
    • Identifier

      public Identifier(String namespace, String path)
      Mappings:
      Namespace Name Mixin selector
      named <init> Lnet/minecraft/util/Identifier;<init>(Ljava/lang/String;Ljava/lang/String;)V
      intermediary <init> Lnet/minecraft/class_2960;<init>(Ljava/lang/String;Ljava/lang/String;)V
      official <init> Lalf;<init>(Ljava/lang/String;Ljava/lang/String;)V
    • Identifier

      private Identifier(String[] id)
      Mappings:
      Namespace Name Mixin selector
      named <init> Lnet/minecraft/util/Identifier;<init>([Ljava/lang/String;)V
      intermediary <init> Lnet/minecraft/class_2960;<init>([Ljava/lang/String;)V
      official <init> Lalf;<init>([Ljava/lang/String;)V
    • Identifier

      public Identifier(String id)

      Takes a string of the form <namespace>:<path> or <path> which will use the default namespace, for example minecraft:iron_ingot or iron_ingot.

      The string will be split (on the :) into an identifier with the specified path and namespace. Prefer using the Identifier(java.lang.String, java.lang.String) constructor that takes the namespace and path as individual parameters to avoid mistakes.

      If there is no colon in the given string argument, the namespace will be set to "minecraft", and the path will be the given argument. If the colon is the first character of the given string argument (i.e. the namespace is empty), the namespace will also be set to "minecraft", and the path will be the given argument without the initial colon.

      Throws:
      InvalidIdentifierException - if the string cannot be parsed as an identifier.
      Mappings:
      Namespace Name Mixin selector
      named <init> Lnet/minecraft/util/Identifier;<init>(Ljava/lang/String;)V
      intermediary <init> Lnet/minecraft/class_2960;<init>(Ljava/lang/String;)V
      official <init> Lalf;<init>(Ljava/lang/String;)V
  • Method Details

    • splitOn

      public static Identifier splitOn(String id, char delimiter)
      Mappings:
      Namespace Name Mixin selector
      named splitOn Lnet/minecraft/util/Identifier;splitOn(Ljava/lang/String;C)Lnet/minecraft/util/Identifier;
      intermediary method_12838 Lnet/minecraft/class_2960;method_12838(Ljava/lang/String;C)Lnet/minecraft/class_2960;
      official a Lalf;a(Ljava/lang/String;C)Lalf;
    • tryParse

      @Nullable public static @Nullable Identifier tryParse(String id)
      Returns id parsed as an identifier, or null if it cannot be parsed.
      Returns:
      id parsed as an identifier, or null if it cannot be parsed
      See Also:
      Mappings:
      Namespace Name Mixin selector
      named tryParse Lnet/minecraft/util/Identifier;tryParse(Ljava/lang/String;)Lnet/minecraft/util/Identifier;
      intermediary method_12829 Lnet/minecraft/class_2960;method_12829(Ljava/lang/String;)Lnet/minecraft/class_2960;
      official a Lalf;a(Ljava/lang/String;)Lalf;
    • of

      @Nullable public static @Nullable Identifier of(String namespace, String path)
      Returns an identifier from the provided namespace and path, or null if either argument is invalid.
      Returns:
      an identifier from the provided namespace and path, or null if either argument is invalid
      See Also:
      Mappings:
      Namespace Name Mixin selector
      named of Lnet/minecraft/util/Identifier;of(Ljava/lang/String;Ljava/lang/String;)Lnet/minecraft/util/Identifier;
      intermediary method_43902 Lnet/minecraft/class_2960;method_43902(Ljava/lang/String;Ljava/lang/String;)Lnet/minecraft/class_2960;
      official a Lalf;a(Ljava/lang/String;Ljava/lang/String;)Lalf;
    • split

      protected static String[] split(String id, char delimiter)
      Splits the id into an array of two strings at the first occurrence of delimiter, excluding the delimiter character, or uses "minecraft" for the first string in the resulting array when the deliminator does not exist or is the first character.
      Mappings:
      Namespace Name Mixin selector
      named split Lnet/minecraft/util/Identifier;split(Ljava/lang/String;C)[Ljava/lang/String;
      intermediary method_12830 Lnet/minecraft/class_2960;method_12830(Ljava/lang/String;C)[Ljava/lang/String;
      official b Lalf;b(Ljava/lang/String;C)[Ljava/lang/String;
    • validate

      public static com.mojang.serialization.DataResult<Identifier> validate(String id)
      Mappings:
      Namespace Name Mixin selector
      named validate Lnet/minecraft/util/Identifier;validate(Ljava/lang/String;)Lcom/mojang/serialization/DataResult;
      intermediary method_29186 Lnet/minecraft/class_2960;method_29186(Ljava/lang/String;)Lcom/mojang/serialization/DataResult;
      official b Lalf;b(Ljava/lang/String;)Lcom/mojang/serialization/DataResult;
    • getPath

      public String getPath()
      Returns the path of the identifier.
      Returns:
      the path of the identifier
      Mappings:
      Namespace Name Mixin selector
      named getPath Lnet/minecraft/util/Identifier;getPath()Ljava/lang/String;
      intermediary method_12832 Lnet/minecraft/class_2960;method_12832()Ljava/lang/String;
      official a Lalf;a()Ljava/lang/String;
    • getNamespace

      public String getNamespace()
      Returns the namespace of the identifier.

      This returns "minecraft" for identifiers created without a namespace.

      Returns:
      the namespace of the identifier
      Mappings:
      Namespace Name Mixin selector
      named getNamespace Lnet/minecraft/util/Identifier;getNamespace()Ljava/lang/String;
      intermediary method_12836 Lnet/minecraft/class_2960;method_12836()Ljava/lang/String;
      official b Lalf;b()Ljava/lang/String;
    • withPath

      public Identifier withPath(String path)
      Mappings:
      Namespace Name Mixin selector
      named withPath Lnet/minecraft/util/Identifier;withPath(Ljava/lang/String;)Lnet/minecraft/util/Identifier;
      intermediary method_45136 Lnet/minecraft/class_2960;method_45136(Ljava/lang/String;)Lnet/minecraft/class_2960;
      official c Lalf;c(Ljava/lang/String;)Lalf;
    • withPath

      public Identifier withPath(UnaryOperator<String> pathFunction)
      Mappings:
      Namespace Name Mixin selector
      named withPath Lnet/minecraft/util/Identifier;withPath(Ljava/util/function/UnaryOperator;)Lnet/minecraft/util/Identifier;
      intermediary method_45134 Lnet/minecraft/class_2960;method_45134(Ljava/util/function/UnaryOperator;)Lnet/minecraft/class_2960;
      official a Lalf;a(Ljava/util/function/UnaryOperator;)Lalf;
    • withPrefixedPath

      public Identifier withPrefixedPath(String prefix)
      Mappings:
      Namespace Name Mixin selector
      named withPrefixedPath Lnet/minecraft/util/Identifier;withPrefixedPath(Ljava/lang/String;)Lnet/minecraft/util/Identifier;
      intermediary method_45138 Lnet/minecraft/class_2960;method_45138(Ljava/lang/String;)Lnet/minecraft/class_2960;
      official d Lalf;d(Ljava/lang/String;)Lalf;
    • withSuffixedPath

      public Identifier withSuffixedPath(String suffix)
      Mappings:
      Namespace Name Mixin selector
      named withSuffixedPath Lnet/minecraft/util/Identifier;withSuffixedPath(Ljava/lang/String;)Lnet/minecraft/util/Identifier;
      intermediary method_48331 Lnet/minecraft/class_2960;method_48331(Ljava/lang/String;)Lnet/minecraft/class_2960;
      official e Lalf;e(Ljava/lang/String;)Lalf;
    • toString

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

      public boolean equals(Object o)
      Overrides:
      equals in class Object
      Mappings:
      Namespace Name Mixin selector
      named equals Lnet/minecraft/util/Identifier;equals(Ljava/lang/Object;)Z
      intermediary equals Lnet/minecraft/class_2960;equals(Ljava/lang/Object;)Z
      official equals Lalf;equals(Ljava/lang/Object;)Z
    • hashCode

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

      public int compareTo(Identifier identifier)
      Specified by:
      compareTo in interface Comparable<Identifier>
      Mappings:
      Namespace Name Mixin selector
      named compareTo Lnet/minecraft/util/Identifier;compareTo(Lnet/minecraft/util/Identifier;)I
      intermediary method_12833 Lnet/minecraft/class_2960;method_12833(Lnet/minecraft/class_2960;)I
      official a Lalf;a(Lalf;)I
    • toUnderscoreSeparatedString

      public String toUnderscoreSeparatedString()
      Returns the string representation of the identifier with slashes and colons replaced with underscores.
      Returns:
      the string representation of the identifier with slashes and colons replaced with underscores
      Mappings:
      Namespace Name Mixin selector
      named toUnderscoreSeparatedString Lnet/minecraft/util/Identifier;toUnderscoreSeparatedString()Ljava/lang/String;
      intermediary method_36181 Lnet/minecraft/class_2960;method_36181()Ljava/lang/String;
      official c Lalf;c()Ljava/lang/String;
    • toTranslationKey

      public String toTranslationKey()
      Returns the long translation key, without omitting the default namespace.
      Returns:
      the long translation key, without omitting the default namespace
      Mappings:
      Namespace Name Mixin selector
      named toTranslationKey Lnet/minecraft/util/Identifier;toTranslationKey()Ljava/lang/String;
      intermediary method_42094 Lnet/minecraft/class_2960;method_42094()Ljava/lang/String;
      official d Lalf;d()Ljava/lang/String;
    • toShortTranslationKey

      public String toShortTranslationKey()
      Returns the short translation key, with the default namespace omitted if present.
      Returns:
      the short translation key, with the default namespace omitted if present
      Mappings:
      Namespace Name Mixin selector
      named toShortTranslationKey Lnet/minecraft/util/Identifier;toShortTranslationKey()Ljava/lang/String;
      intermediary method_43903 Lnet/minecraft/class_2960;method_43903()Ljava/lang/String;
      official e Lalf;e()Ljava/lang/String;
    • toTranslationKey

      public String toTranslationKey(String prefix)
      Returns the long translation key prefixed with prefix and a dot.
      Returns:
      the long translation key prefixed with prefix and a dot
      Mappings:
      Namespace Name Mixin selector
      named toTranslationKey Lnet/minecraft/util/Identifier;toTranslationKey(Ljava/lang/String;)Ljava/lang/String;
      intermediary method_42093 Lnet/minecraft/class_2960;method_42093(Ljava/lang/String;)Ljava/lang/String;
      official f Lalf;f(Ljava/lang/String;)Ljava/lang/String;
    • toTranslationKey

      public String toTranslationKey(String prefix, String suffix)
      Returns the long translation key prefixed with prefix and a dot, and suffixed with a dot and suffix.
      Returns:
      the long translation key prefixed with prefix and a dot, and suffixed with a dot and suffix
      Mappings:
      Namespace Name Mixin selector
      named toTranslationKey Lnet/minecraft/util/Identifier;toTranslationKey(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
      intermediary method_48747 Lnet/minecraft/class_2960;method_48747(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
      official b Lalf;b(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    • readString

      private static String readString(com.mojang.brigadier.StringReader reader)
      Mappings:
      Namespace Name Mixin selector
      named readString Lnet/minecraft/util/Identifier;readString(Lcom/mojang/brigadier/StringReader;)Ljava/lang/String;
      intermediary method_58275 Lnet/minecraft/class_2960;method_58275(Lcom/mojang/brigadier/StringReader;)Ljava/lang/String;
      official c Lalf;c(Lcom/mojang/brigadier/StringReader;)Ljava/lang/String;
    • fromCommandInput

      public static Identifier fromCommandInput(com.mojang.brigadier.StringReader reader) throws com.mojang.brigadier.exceptions.CommandSyntaxException
      Throws:
      com.mojang.brigadier.exceptions.CommandSyntaxException
      Mappings:
      Namespace Name Mixin selector
      named fromCommandInput Lnet/minecraft/util/Identifier;fromCommandInput(Lcom/mojang/brigadier/StringReader;)Lnet/minecraft/util/Identifier;
      intermediary method_12835 Lnet/minecraft/class_2960;method_12835(Lcom/mojang/brigadier/StringReader;)Lnet/minecraft/class_2960;
      official a Lalf;a(Lcom/mojang/brigadier/StringReader;)Lalf;
    • fromCommandInputNonEmpty

      public static Identifier fromCommandInputNonEmpty(com.mojang.brigadier.StringReader reader) throws com.mojang.brigadier.exceptions.CommandSyntaxException
      Throws:
      com.mojang.brigadier.exceptions.CommandSyntaxException
      Mappings:
      Namespace Name Mixin selector
      named fromCommandInputNonEmpty Lnet/minecraft/util/Identifier;fromCommandInputNonEmpty(Lcom/mojang/brigadier/StringReader;)Lnet/minecraft/util/Identifier;
      intermediary method_58274 Lnet/minecraft/class_2960;method_58274(Lcom/mojang/brigadier/StringReader;)Lnet/minecraft/class_2960;
      official b Lalf;b(Lcom/mojang/brigadier/StringReader;)Lalf;
    • isCharValid

      public static boolean isCharValid(char c)
      Mappings:
      Namespace Name Mixin selector
      named isCharValid Lnet/minecraft/util/Identifier;isCharValid(C)Z
      intermediary method_12831 Lnet/minecraft/class_2960;method_12831(C)Z
      official a Lalf;a(C)Z
    • isPathValid

      public static boolean isPathValid(String path)
      Returns whether path can be used as an identifier's path.
      Returns:
      whether path can be used as an identifier's path
      Mappings:
      Namespace Name Mixin selector
      named isPathValid Lnet/minecraft/util/Identifier;isPathValid(Ljava/lang/String;)Z
      intermediary method_20208 Lnet/minecraft/class_2960;method_20208(Ljava/lang/String;)Z
      official g Lalf;g(Ljava/lang/String;)Z
    • isNamespaceValid

      public static boolean isNamespaceValid(String namespace)
      Returns whether namespace can be used as an identifier's namespace.
      Returns:
      whether namespace can be used as an identifier's namespace
      Mappings:
      Namespace Name Mixin selector
      named isNamespaceValid Lnet/minecraft/util/Identifier;isNamespaceValid(Ljava/lang/String;)Z
      intermediary method_20209 Lnet/minecraft/class_2960;method_20209(Ljava/lang/String;)Z
      official h Lalf;h(Ljava/lang/String;)Z
    • validateNamespace

      private static String validateNamespace(String namespace, String path)
      Mappings:
      Namespace Name Mixin selector
      named validateNamespace Lnet/minecraft/util/Identifier;validateNamespace(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
      intermediary method_45135 Lnet/minecraft/class_2960;method_45135(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
      official c Lalf;c(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    • isPathCharacterValid

      public static boolean isPathCharacterValid(char character)
      Returns whether character is valid for use in identifier paths.
      Returns:
      whether character is valid for use in identifier paths
      Mappings:
      Namespace Name Mixin selector
      named isPathCharacterValid Lnet/minecraft/util/Identifier;isPathCharacterValid(C)Z
      intermediary method_29184 Lnet/minecraft/class_2960;method_29184(C)Z
      official b Lalf;b(C)Z
    • isNamespaceCharacterValid

      private static boolean isNamespaceCharacterValid(char character)
      Returns whether character is valid for use in identifier namespaces.
      Returns:
      whether character is valid for use in identifier namespaces
      Mappings:
      Namespace Name Mixin selector
      named isNamespaceCharacterValid Lnet/minecraft/util/Identifier;isNamespaceCharacterValid(C)Z
      intermediary method_29185 Lnet/minecraft/class_2960;method_29185(C)Z
      official c Lalf;c(C)Z
    • isValid

      public static boolean isValid(String id)
      Returns whether id can be parsed as an identifier.
      Returns:
      whether id can be parsed as an identifier
      Mappings:
      Namespace Name Mixin selector
      named isValid Lnet/minecraft/util/Identifier;isValid(Ljava/lang/String;)Z
      intermediary method_20207 Lnet/minecraft/class_2960;method_20207(Ljava/lang/String;)Z
      official i Lalf;i(Ljava/lang/String;)Z
    • validatePath

      private static String validatePath(String namespace, String path)
      Mappings:
      Namespace Name Mixin selector
      named validatePath Lnet/minecraft/util/Identifier;validatePath(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
      intermediary method_45137 Lnet/minecraft/class_2960;method_45137(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
      official d Lalf;d(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;