Class Identifier
- All Implemented Interfaces:
Comparable<Identifier>
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.
invalid reference
#isValidtryParse(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:
of(String)creates an identifier from a string in<namespace>:<path>format. If the colon is missing, the created identifier has the namespace "minecraft" and the argument is used as the path. When passed an invalid value, this throwsInvalidIdentifierException.of(String, String)creates an identifier from namespace and path. When passed an invalid value, this throwsInvalidIdentifierException.ofVanilla(String)creates an identifier in the "minecraft" namespace.tryParse(String)creates an identifier from a string in<namespace>:<path>format. If the colon is missing, the created identifier has the namespace "minecraft" and the argument is used as the path. When passed an invalid value, this returnsnull.tryParse(String, String)creates an identifier from namespace and path. When passed an invalid value, this returnsnull.fromCommandInput(com.mojang.brigadier.StringReader)reads an identifier from command input reader. When an invalid value is read, this throwsCOMMAND_EXCEPTION.Identifier.Serializeris a serializer for Gson.CODECcan be used to serialize and deserialize an identifier using DataFixerUpper.
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/Identifierintermediary net/minecraft/class_2960official akr
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.mojang.serialization.Codec<Identifier> static final com.mojang.brigadier.exceptions.SimpleCommandExceptionTypestatic final Stringprivate final Stringstatic final charstatic final PacketCodec<ByteBuf, Identifier> private final Stringstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(Identifier identifier) booleanstatic IdentifierfromCommandInput(com.mojang.brigadier.StringReader reader) static IdentifierfromCommandInputNonEmpty(com.mojang.brigadier.StringReader reader) Returns the namespace of the identifier.getPath()Returns the path of the identifier.inthashCode()static booleanisCharValid(char c) private static booleanisNamespaceCharacterValid(char character) Returns whethercharacteris valid for use in identifier namespaces.static booleanisNamespaceValid(String namespace) Returns whethernamespacecan be used as an identifier's namespace.static booleanisPathCharacterValid(char character) Returns whethercharacteris valid for use in identifier paths.static booleanisPathValid(String path) Returns whetherpathcan be used as an identifier's path.static Identifierstatic Identifierprivate static IdentifierofValidated(String namespace, String path) static Identifierprivate static StringreadString(com.mojang.brigadier.StringReader reader) static IdentifierReturns the short translation key, with the default namespace omitted if present.toString()Returns the long translation key, without omitting the default namespace.toTranslationKey(String prefix) Returns the long translation key prefixed withprefixand a dot.toTranslationKey(String prefix, String suffix) Returns the long translation key prefixed withprefixand a dot, and suffixed with a dot andsuffix.Returns the string representation of the identifier with slashes and colons replaced with underscores.static @Nullable IdentifierReturnsidparsed as an identifier, ornullif it cannot be parsed.static @Nullable IdentifierReturns an identifier from the providednamespaceandpath, ornullif either argument is invalid.static @Nullable IdentifiertrySplitOn(String id, char delimiter) static com.mojang.serialization.DataResult<Identifier> private static StringvalidateNamespace(String namespace, String path) private static StringvalidatePath(String namespace, String path) withPath(UnaryOperator<String> pathFunction) withPrefixedPath(String prefix) withSuffixedPath(String suffix)
-
Field Details
-
CODEC
- Mappings:
Namespace Name Mixin selector named CODECLnet/minecraft/util/Identifier;CODEC:Lcom/mojang/serialization/Codec;intermediary field_25139Lnet/minecraft/class_2960;field_25139:Lcom/mojang/serialization/Codec;official aLakr;a:Lcom/mojang/serialization/Codec;
-
PACKET_CODEC
- Mappings:
Namespace Name Mixin selector named PACKET_CODECLnet/minecraft/util/Identifier;PACKET_CODEC:Lnet/minecraft/network/codec/PacketCodec;intermediary field_48267Lnet/minecraft/class_2960;field_48267:Lnet/minecraft/class_9139;official bLakr;b:Lyx;
-
COMMAND_EXCEPTION
public static final com.mojang.brigadier.exceptions.SimpleCommandExceptionType COMMAND_EXCEPTION- Mappings:
Namespace Name Mixin selector named COMMAND_EXCEPTIONLnet/minecraft/util/Identifier;COMMAND_EXCEPTION:Lcom/mojang/brigadier/exceptions/SimpleCommandExceptionType;intermediary field_13354Lnet/minecraft/class_2960;field_13354:Lcom/mojang/brigadier/exceptions/SimpleCommandExceptionType;official cLakr;c:Lcom/mojang/brigadier/exceptions/SimpleCommandExceptionType;
-
NAMESPACE_SEPARATOR
public static final char NAMESPACE_SEPARATOR- See Also:
- Mappings:
Namespace Name Mixin selector named NAMESPACE_SEPARATORLnet/minecraft/util/Identifier;NAMESPACE_SEPARATOR:Cintermediary field_33380Lnet/minecraft/class_2960;field_33380:Cofficial dLakr;d:C
-
DEFAULT_NAMESPACE
- See Also:
- Mappings:
Namespace Name Mixin selector named DEFAULT_NAMESPACELnet/minecraft/util/Identifier;DEFAULT_NAMESPACE:Ljava/lang/String;intermediary field_33381Lnet/minecraft/class_2960;field_33381:Ljava/lang/String;official eLakr;e:Ljava/lang/String;
-
REALMS_NAMESPACE
- See Also:
- Mappings:
Namespace Name Mixin selector named REALMS_NAMESPACELnet/minecraft/util/Identifier;REALMS_NAMESPACE:Ljava/lang/String;intermediary field_33382Lnet/minecraft/class_2960;field_33382:Ljava/lang/String;official fLakr;f:Ljava/lang/String;
-
namespace
- Mappings:
Namespace Name Mixin selector named namespaceLnet/minecraft/util/Identifier;namespace:Ljava/lang/String;intermediary field_13353Lnet/minecraft/class_2960;field_13353:Ljava/lang/String;official hLakr;h:Ljava/lang/String;
-
path
- Mappings:
Namespace Name Mixin selector named pathLnet/minecraft/util/Identifier;path:Ljava/lang/String;intermediary field_13355Lnet/minecraft/class_2960;field_13355:Ljava/lang/String;official iLakr;i:Ljava/lang/String;
-
-
Constructor Details
-
Identifier
- Mappings:
Namespace Name Mixin selector named <init>Lnet/minecraft/util/Identifier;<init>(Ljava/lang/String;Ljava/lang/String;)Vintermediary <init>Lnet/minecraft/class_2960;<init>(Ljava/lang/String;Ljava/lang/String;)Vofficial <init>Lakr;<init>(Ljava/lang/String;Ljava/lang/String;)V
-
-
Method Details
-
ofValidated
- Mappings:
Namespace Name Mixin selector named ofValidatedLnet/minecraft/util/Identifier;ofValidated(Ljava/lang/String;Ljava/lang/String;)Lnet/minecraft/util/Identifier;intermediary method_60936Lnet/minecraft/class_2960;method_60936(Ljava/lang/String;Ljava/lang/String;)Lnet/minecraft/class_2960;official dLakr;d(Ljava/lang/String;Ljava/lang/String;)Lakr;
-
of
- Mappings:
Namespace Name Mixin selector named ofLnet/minecraft/util/Identifier;of(Ljava/lang/String;Ljava/lang/String;)Lnet/minecraft/util/Identifier;intermediary method_60655Lnet/minecraft/class_2960;method_60655(Ljava/lang/String;Ljava/lang/String;)Lnet/minecraft/class_2960;official aLakr;a(Ljava/lang/String;Ljava/lang/String;)Lakr;
-
of
- Mappings:
Namespace Name Mixin selector named ofLnet/minecraft/util/Identifier;of(Ljava/lang/String;)Lnet/minecraft/util/Identifier;intermediary method_60654Lnet/minecraft/class_2960;method_60654(Ljava/lang/String;)Lnet/minecraft/class_2960;official aLakr;a(Ljava/lang/String;)Lakr;
-
ofVanilla
- Mappings:
Namespace Name Mixin selector named ofVanillaLnet/minecraft/util/Identifier;ofVanilla(Ljava/lang/String;)Lnet/minecraft/util/Identifier;intermediary method_60656Lnet/minecraft/class_2960;method_60656(Ljava/lang/String;)Lnet/minecraft/class_2960;official bLakr;b(Ljava/lang/String;)Lakr;
-
tryParse
Returnsidparsed as an identifier, ornullif it cannot be parsed.- Returns:
idparsed as an identifier, ornullif it cannot be parsed- See Also:
- Mappings:
Namespace Name Mixin selector named tryParseLnet/minecraft/util/Identifier;tryParse(Ljava/lang/String;)Lnet/minecraft/util/Identifier;intermediary method_12829Lnet/minecraft/class_2960;method_12829(Ljava/lang/String;)Lnet/minecraft/class_2960;official cLakr;c(Ljava/lang/String;)Lakr;
-
tryParse
Returns an identifier from the providednamespaceandpath, ornullif either argument is invalid.- Returns:
- an identifier from the provided
namespaceandpath, ornullif either argument is invalid - See Also:
- Mappings:
Namespace Name Mixin selector named tryParseLnet/minecraft/util/Identifier;tryParse(Ljava/lang/String;Ljava/lang/String;)Lnet/minecraft/util/Identifier;intermediary method_43902Lnet/minecraft/class_2960;method_43902(Ljava/lang/String;Ljava/lang/String;)Lnet/minecraft/class_2960;official bLakr;b(Ljava/lang/String;Ljava/lang/String;)Lakr;
-
splitOn
- Mappings:
Namespace Name Mixin selector named splitOnLnet/minecraft/util/Identifier;splitOn(Ljava/lang/String;C)Lnet/minecraft/util/Identifier;intermediary method_12838Lnet/minecraft/class_2960;method_12838(Ljava/lang/String;C)Lnet/minecraft/class_2960;official aLakr;a(Ljava/lang/String;C)Lakr;
-
trySplitOn
- Mappings:
Namespace Name Mixin selector named trySplitOnLnet/minecraft/util/Identifier;trySplitOn(Ljava/lang/String;C)Lnet/minecraft/util/Identifier;intermediary method_60935Lnet/minecraft/class_2960;method_60935(Ljava/lang/String;C)Lnet/minecraft/class_2960;official bLakr;b(Ljava/lang/String;C)Lakr;
-
validate
- Mappings:
Namespace Name Mixin selector named validateLnet/minecraft/util/Identifier;validate(Ljava/lang/String;)Lcom/mojang/serialization/DataResult;intermediary method_29186Lnet/minecraft/class_2960;method_29186(Ljava/lang/String;)Lcom/mojang/serialization/DataResult;official dLakr;d(Ljava/lang/String;)Lcom/mojang/serialization/DataResult;
-
getPath
Returns the path of the identifier.- Returns:
- the path of the identifier
- Mappings:
Namespace Name Mixin selector named getPathLnet/minecraft/util/Identifier;getPath()Ljava/lang/String;intermediary method_12832Lnet/minecraft/class_2960;method_12832()Ljava/lang/String;official aLakr;a()Ljava/lang/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 getNamespaceLnet/minecraft/util/Identifier;getNamespace()Ljava/lang/String;intermediary method_12836Lnet/minecraft/class_2960;method_12836()Ljava/lang/String;official bLakr;b()Ljava/lang/String;
-
withPath
- Mappings:
Namespace Name Mixin selector named withPathLnet/minecraft/util/Identifier;withPath(Ljava/lang/String;)Lnet/minecraft/util/Identifier;intermediary method_45136Lnet/minecraft/class_2960;method_45136(Ljava/lang/String;)Lnet/minecraft/class_2960;official eLakr;e(Ljava/lang/String;)Lakr;
-
withPath
- Mappings:
Namespace Name Mixin selector named withPathLnet/minecraft/util/Identifier;withPath(Ljava/util/function/UnaryOperator;)Lnet/minecraft/util/Identifier;intermediary method_45134Lnet/minecraft/class_2960;method_45134(Ljava/util/function/UnaryOperator;)Lnet/minecraft/class_2960;official aLakr;a(Ljava/util/function/UnaryOperator;)Lakr;
-
withPrefixedPath
- Mappings:
Namespace Name Mixin selector named withPrefixedPathLnet/minecraft/util/Identifier;withPrefixedPath(Ljava/lang/String;)Lnet/minecraft/util/Identifier;intermediary method_45138Lnet/minecraft/class_2960;method_45138(Ljava/lang/String;)Lnet/minecraft/class_2960;official fLakr;f(Ljava/lang/String;)Lakr;
-
withSuffixedPath
- Mappings:
Namespace Name Mixin selector named withSuffixedPathLnet/minecraft/util/Identifier;withSuffixedPath(Ljava/lang/String;)Lnet/minecraft/util/Identifier;intermediary method_48331Lnet/minecraft/class_2960;method_48331(Ljava/lang/String;)Lnet/minecraft/class_2960;official gLakr;g(Ljava/lang/String;)Lakr;
-
toString
-
equals
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareToin interfaceComparable<Identifier>- Mappings:
Namespace Name Mixin selector named compareToLnet/minecraft/util/Identifier;compareTo(Lnet/minecraft/util/Identifier;)Iintermediary method_12833Lnet/minecraft/class_2960;method_12833(Lnet/minecraft/class_2960;)Iofficial aLakr;a(Lakr;)I
-
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 toUnderscoreSeparatedStringLnet/minecraft/util/Identifier;toUnderscoreSeparatedString()Ljava/lang/String;intermediary method_36181Lnet/minecraft/class_2960;method_36181()Ljava/lang/String;official cLakr;c()Ljava/lang/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 toTranslationKeyLnet/minecraft/util/Identifier;toTranslationKey()Ljava/lang/String;intermediary method_42094Lnet/minecraft/class_2960;method_42094()Ljava/lang/String;official dLakr;d()Ljava/lang/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 toShortTranslationKeyLnet/minecraft/util/Identifier;toShortTranslationKey()Ljava/lang/String;intermediary method_43903Lnet/minecraft/class_2960;method_43903()Ljava/lang/String;official eLakr;e()Ljava/lang/String;
-
toTranslationKey
Returns the long translation key prefixed withprefixand a dot.- Returns:
- the long translation key prefixed with
prefixand a dot - Mappings:
Namespace Name Mixin selector named toTranslationKeyLnet/minecraft/util/Identifier;toTranslationKey(Ljava/lang/String;)Ljava/lang/String;intermediary method_42093Lnet/minecraft/class_2960;method_42093(Ljava/lang/String;)Ljava/lang/String;official hLakr;h(Ljava/lang/String;)Ljava/lang/String;
-
toTranslationKey
Returns the long translation key prefixed withprefixand a dot, and suffixed with a dot andsuffix.- Returns:
- the long translation key prefixed with
prefixand a dot, and suffixed with a dot andsuffix - Mappings:
Namespace Name Mixin selector named toTranslationKeyLnet/minecraft/util/Identifier;toTranslationKey(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;intermediary method_48747Lnet/minecraft/class_2960;method_48747(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;official cLakr;c(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
-
readString
- Mappings:
Namespace Name Mixin selector named readStringLnet/minecraft/util/Identifier;readString(Lcom/mojang/brigadier/StringReader;)Ljava/lang/String;intermediary method_58275Lnet/minecraft/class_2960;method_58275(Lcom/mojang/brigadier/StringReader;)Ljava/lang/String;official cLakr;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 fromCommandInputLnet/minecraft/util/Identifier;fromCommandInput(Lcom/mojang/brigadier/StringReader;)Lnet/minecraft/util/Identifier;intermediary method_12835Lnet/minecraft/class_2960;method_12835(Lcom/mojang/brigadier/StringReader;)Lnet/minecraft/class_2960;official aLakr;a(Lcom/mojang/brigadier/StringReader;)Lakr;
-
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 fromCommandInputNonEmptyLnet/minecraft/util/Identifier;fromCommandInputNonEmpty(Lcom/mojang/brigadier/StringReader;)Lnet/minecraft/util/Identifier;intermediary method_58274Lnet/minecraft/class_2960;method_58274(Lcom/mojang/brigadier/StringReader;)Lnet/minecraft/class_2960;official bLakr;b(Lcom/mojang/brigadier/StringReader;)Lakr;
-
isCharValid
public static boolean isCharValid(char c) - Mappings:
Namespace Name Mixin selector named isCharValidLnet/minecraft/util/Identifier;isCharValid(C)Zintermediary method_12831Lnet/minecraft/class_2960;method_12831(C)Zofficial aLakr;a(C)Z
-
isPathValid
Returns whetherpathcan be used as an identifier's path.- Returns:
- whether
pathcan be used as an identifier's path - Mappings:
Namespace Name Mixin selector named isPathValidLnet/minecraft/util/Identifier;isPathValid(Ljava/lang/String;)Zintermediary method_20208Lnet/minecraft/class_2960;method_20208(Ljava/lang/String;)Zofficial iLakr;i(Ljava/lang/String;)Z
-
isNamespaceValid
Returns whethernamespacecan be used as an identifier's namespace.- Returns:
- whether
namespacecan be used as an identifier's namespace - Mappings:
Namespace Name Mixin selector named isNamespaceValidLnet/minecraft/util/Identifier;isNamespaceValid(Ljava/lang/String;)Zintermediary method_20209Lnet/minecraft/class_2960;method_20209(Ljava/lang/String;)Zofficial jLakr;j(Ljava/lang/String;)Z
-
validateNamespace
- Mappings:
Namespace Name Mixin selector named validateNamespaceLnet/minecraft/util/Identifier;validateNamespace(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;intermediary method_45135Lnet/minecraft/class_2960;method_45135(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;official eLakr;e(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
-
isPathCharacterValid
public static boolean isPathCharacterValid(char character) Returns whethercharacteris valid for use in identifier paths.- Returns:
- whether
characteris valid for use in identifier paths - Mappings:
Namespace Name Mixin selector named isPathCharacterValidLnet/minecraft/util/Identifier;isPathCharacterValid(C)Zintermediary method_29184Lnet/minecraft/class_2960;method_29184(C)Zofficial bLakr;b(C)Z
-
isNamespaceCharacterValid
private static boolean isNamespaceCharacterValid(char character) Returns whethercharacteris valid for use in identifier namespaces.- Returns:
- whether
characteris valid for use in identifier namespaces - Mappings:
Namespace Name Mixin selector named isNamespaceCharacterValidLnet/minecraft/util/Identifier;isNamespaceCharacterValid(C)Zintermediary method_29185Lnet/minecraft/class_2960;method_29185(C)Zofficial cLakr;c(C)Z
-
validatePath
- Mappings:
Namespace Name Mixin selector named validatePathLnet/minecraft/util/Identifier;validatePath(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;intermediary method_45137Lnet/minecraft/class_2960;method_45137(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;official fLakr;f(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
-