Identifier.java
net.minecraft.resources.Identifier
信息
- 全限定名:net.minecraft.resources.Identifier
- 类型:public final class
- 包:net.minecraft.resources
- 源码路径:src/main/java/net/minecraft/resources/Identifier.java
- 起始行号:L17
- 实现:Comparable
- 职责:
TODO
字段/常量
-
CODEC- 类型:
Codec<Identifier> - 修饰符:
public static final - 源码定位:
L18 - 说明:
TODO
- 类型:
-
STREAM_CODEC- 类型:
StreamCodec<ByteBuf,Identifier> - 修饰符:
public static final - 源码定位:
L19 - 说明:
TODO
- 类型:
-
ERROR_INVALID- 类型:
SimpleCommandExceptionType - 修饰符:
public static final - 源码定位:
L20 - 说明:
TODO
- 类型:
-
NAMESPACE_SEPARATOR- 类型:
char - 修饰符:
public static final - 源码定位:
L21 - 说明:
TODO
- 类型:
-
DEFAULT_NAMESPACE- 类型:
String - 修饰符:
public static final - 源码定位:
L22 - 说明:
TODO
- 类型:
-
REALMS_NAMESPACE- 类型:
String - 修饰符:
public static final - 源码定位:
L23 - 说明:
TODO
- 类型:
-
ALLOWED_NAMESPACE_CHARACTERS- 类型:
String - 修饰符:
public static final - 源码定位:
L24 - 说明:
TODO
- 类型:
-
namespace- 类型:
String - 修饰符:
private final - 源码定位:
L25 - 说明:
TODO
- 类型:
-
path- 类型:
String - 修饰符:
private final - 源码定位:
L26 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
private Identifier(String namespace, String path) @ L28
- 构造器名:Identifier
- 源码定位:L28
- 修饰符:private
参数:
- namespace: String
- path: String
说明:
TODO
方法
下面的方法块按源码顺序生成。
private static Identifier createUntrusted(String namespace, String path) @ L37
- 方法名:createUntrusted
- 源码定位:L37
- 返回类型:Identifier
- 修饰符:private static
参数:
- namespace: String
- path: String
说明:
TODO
public static Identifier fromNamespaceAndPath(String namespace, String path) @ L41
- 方法名:fromNamespaceAndPath
- 源码定位:L41
- 返回类型:Identifier
- 修饰符:public static
参数:
- namespace: String
- path: String
说明:
TODO
public static Identifier parse(String identifier) @ L45
- 方法名:parse
- 源码定位:L45
- 返回类型:Identifier
- 修饰符:public static
参数:
- identifier: String
说明:
TODO
public static Identifier withDefaultNamespace(String path) @ L49
- 方法名:withDefaultNamespace
- 源码定位:L49
- 返回类型:Identifier
- 修饰符:public static
参数:
- path: String
说明:
TODO
public static Identifier tryParse(String identifier) @ L53
- 方法名:tryParse
- 源码定位:L53
- 返回类型:Identifier
- 修饰符:public static
参数:
- identifier: String
说明:
TODO
public static Identifier tryBuild(String namespace, String path) @ L57
- 方法名:tryBuild
- 源码定位:L57
- 返回类型:Identifier
- 修饰符:public static
参数:
- namespace: String
- path: String
说明:
TODO
public static Identifier bySeparator(String identifier, char separator) @ L61
- 方法名:bySeparator
- 源码定位:L61
- 返回类型:Identifier
- 修饰符:public static
参数:
- identifier: String
- separator: char
说明:
TODO
public static Identifier tryBySeparator(String identifier, char separator) @ L76
- 方法名:tryBySeparator
- 源码定位:L76
- 返回类型:Identifier
- 修饰符:public static
参数:
- identifier: String
- separator: char
说明:
TODO
public static DataResult<Identifier> read(String input) @ L93
- 方法名:read
- 源码定位:L93
- 返回类型:DataResult
- 修饰符:public static
参数:
- input: String
说明:
TODO
public String getPath() @ L101
- 方法名:getPath
- 源码定位:L101
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
public String getNamespace() @ L105
- 方法名:getNamespace
- 源码定位:L105
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
public Identifier withPath(String newPath) @ L109
- 方法名:withPath
- 源码定位:L109
- 返回类型:Identifier
- 修饰符:public
参数:
- newPath: String
说明:
TODO
public Identifier withPath(UnaryOperator<String> modifier) @ L113
- 方法名:withPath
- 源码定位:L113
- 返回类型:Identifier
- 修饰符:public
参数:
- modifier: UnaryOperator
说明:
TODO
public Identifier withPrefix(String prefix) @ L117
- 方法名:withPrefix
- 源码定位:L117
- 返回类型:Identifier
- 修饰符:public
参数:
- prefix: String
说明:
TODO
public Identifier withSuffix(String suffix) @ L121
- 方法名:withSuffix
- 源码定位:L121
- 返回类型:Identifier
- 修饰符:public
参数:
- suffix: String
说明:
TODO
public String toString() @ L125
- 方法名:toString
- 源码定位:L125
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean equals(Object o) @ L130
- 方法名:equals
- 源码定位:L130
- 返回类型:boolean
- 修饰符:public
参数:
- o: Object
说明:
TODO
public int hashCode() @ L139
- 方法名:hashCode
- 源码定位:L139
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public int compareTo(Identifier o) @ L144
- 方法名:compareTo
- 源码定位:L144
- 返回类型:int
- 修饰符:public
参数:
- o: Identifier
说明:
TODO
public Path resolveAgainst(Path root) @ L153
- 方法名:resolveAgainst
- 源码定位:L153
- 返回类型:Path
- 修饰符:public
参数:
- root: Path
说明:
TODO
public String toDebugFileName() @ L157
- 方法名:toDebugFileName
- 源码定位:L157
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
public String toLanguageKey() @ L161
- 方法名:toLanguageKey
- 源码定位:L161
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
public String toShortLanguageKey() @ L165
- 方法名:toShortLanguageKey
- 源码定位:L165
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
public String toShortString() @ L169
- 方法名:toShortString
- 源码定位:L169
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
public String toLanguageKey(String prefix) @ L173
- 方法名:toLanguageKey
- 源码定位:L173
- 返回类型:String
- 修饰符:public
参数:
- prefix: String
说明:
TODO
public String toLanguageKey(String prefix, String suffix) @ L177
- 方法名:toLanguageKey
- 源码定位:L177
- 返回类型:String
- 修饰符:public
参数:
- prefix: String
- suffix: String
说明:
TODO
private static String readGreedy(StringReader reader) @ L181
- 方法名:readGreedy
- 源码定位:L181
- 返回类型:String
- 修饰符:private static
参数:
- reader: StringReader
说明:
TODO
public static Identifier read(StringReader reader) @ L191
- 方法名:read
- 源码定位:L191
- 返回类型:Identifier
- 修饰符:public static
参数:
- reader: StringReader
说明:
TODO
public static Identifier readNonEmpty(StringReader reader) @ L203
- 方法名:readNonEmpty
- 源码定位:L203
- 返回类型:Identifier
- 修饰符:public static
参数:
- reader: StringReader
说明:
TODO
public static boolean isAllowedInIdentifier(char c) @ L218
- 方法名:isAllowedInIdentifier
- 源码定位:L218
- 返回类型:boolean
- 修饰符:public static
参数:
- c: char
说明:
TODO
public static boolean isValidPath(String path) @ L222
- 方法名:isValidPath
- 源码定位:L222
- 返回类型:boolean
- 修饰符:public static
参数:
- path: String
说明:
TODO
public static boolean isValidNamespace(String namespace) @ L232
- 方法名:isValidNamespace
- 源码定位:L232
- 返回类型:boolean
- 修饰符:public static
参数:
- namespace: String
说明:
TODO
private static String assertValidNamespace(String namespace, String path) @ L246
- 方法名:assertValidNamespace
- 源码定位:L246
- 返回类型:String
- 修饰符:private static
参数:
- namespace: String
- path: String
说明:
TODO
public static boolean validPathChar(char c) @ L254
- 方法名:validPathChar
- 源码定位:L254
- 返回类型:boolean
- 修饰符:public static
参数:
- c: char
说明:
TODO
private static boolean validNamespaceChar(char c) @ L258
- 方法名:validNamespaceChar
- 源码定位:L258
- 返回类型:boolean
- 修饰符:private static
参数:
- c: char
说明:
TODO
private static String assertValidPath(String namespace, String path) @ L262
- 方法名:assertValidPath
- 源码定位:L262
- 返回类型:String
- 修饰符:private static
参数:
- namespace: String
- path: String
说明:
TODO
代码
public final class Identifier implements Comparable<Identifier> {
public static final Codec<Identifier> CODEC = Codec.STRING.<Identifier>comapFlatMap(Identifier::read, Identifier::toString).stable();
public static final StreamCodec<ByteBuf, Identifier> STREAM_CODEC = ByteBufCodecs.STRING_UTF8.map(Identifier::parse, Identifier::toString);
public static final SimpleCommandExceptionType ERROR_INVALID = new SimpleCommandExceptionType(Component.translatable("argument.id.invalid"));
public static final char NAMESPACE_SEPARATOR = ':';
public static final String DEFAULT_NAMESPACE = "minecraft";
public static final String REALMS_NAMESPACE = "realms";
public static final String ALLOWED_NAMESPACE_CHARACTERS = "[a-z0-9_.-]";
private final String namespace;
private final String path;
private Identifier(String namespace, String path) {
assert isValidNamespace(namespace);
assert isValidPath(path);
this.namespace = namespace;
this.path = path;
}
private static Identifier createUntrusted(String namespace, String path) {
return new Identifier(assertValidNamespace(namespace, path), assertValidPath(namespace, path));
}
public static Identifier fromNamespaceAndPath(String namespace, String path) {
return createUntrusted(namespace, path);
}
public static Identifier parse(String identifier) {
return bySeparator(identifier, ':');
}
public static Identifier withDefaultNamespace(String path) {
return new Identifier("minecraft", assertValidPath("minecraft", path));
}
public static @Nullable Identifier tryParse(String identifier) {
return tryBySeparator(identifier, ':');
}
public static @Nullable Identifier tryBuild(String namespace, String path) {
return isValidNamespace(namespace) && isValidPath(path) ? new Identifier(namespace, path) : null;
}
public static Identifier bySeparator(String identifier, char separator) {
int separatorIndex = identifier.indexOf(separator);
if (separatorIndex >= 0) {
String path = identifier.substring(separatorIndex + 1);
if (separatorIndex != 0) {
String namespace = identifier.substring(0, separatorIndex);
return createUntrusted(namespace, path);
} else {
return withDefaultNamespace(path);
}
} else {
return withDefaultNamespace(identifier);
}
}
public static @Nullable Identifier tryBySeparator(String identifier, char separator) {
int separatorIndex = identifier.indexOf(separator);
if (separatorIndex >= 0) {
String path = identifier.substring(separatorIndex + 1);
if (!isValidPath(path)) {
return null;
} else if (separatorIndex != 0) {
String namespace = identifier.substring(0, separatorIndex);
return isValidNamespace(namespace) ? new Identifier(namespace, path) : null;
} else {
return new Identifier("minecraft", path);
}
} else {
return isValidPath(identifier) ? new Identifier("minecraft", identifier) : null;
}
}
public static DataResult<Identifier> read(String input) {
try {
return DataResult.success(parse(input));
} catch (IdentifierException var2) {
return DataResult.error(() -> "Not a valid resource location: " + input + " " + var2.getMessage());
}
}
public String getPath() {
return this.path;
}
public String getNamespace() {
return this.namespace;
}
public Identifier withPath(String newPath) {
return new Identifier(this.namespace, assertValidPath(this.namespace, newPath));
}
public Identifier withPath(UnaryOperator<String> modifier) {
return this.withPath(modifier.apply(this.path));
}
public Identifier withPrefix(String prefix) {
return this.withPath(prefix + this.path);
}
public Identifier withSuffix(String suffix) {
return this.withPath(this.path + suffix);
}
@Override
public String toString() {
return this.namespace + ":" + this.path;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
} else {
return !(o instanceof Identifier that) ? false : this.namespace.equals(that.namespace) && this.path.equals(that.path);
}
}
@Override
public int hashCode() {
return 31 * this.namespace.hashCode() + this.path.hashCode();
}
public int compareTo(Identifier o) {
int result = this.path.compareTo(o.path);
if (result == 0) {
result = this.namespace.compareTo(o.namespace);
}
return result;
}
public Path resolveAgainst(Path root) {
return root.resolve(this.getNamespace(), this.getPath());
}
public String toDebugFileName() {
return this.toString().replace('/', '_').replace(':', '_');
}
public String toLanguageKey() {
return this.namespace + "." + this.path;
}
public String toShortLanguageKey() {
return this.namespace.equals("minecraft") ? this.path : this.toLanguageKey();
}
public String toShortString() {
return this.namespace.equals("minecraft") ? this.path : this.toString();
}
public String toLanguageKey(String prefix) {
return prefix + "." + this.toLanguageKey();
}
public String toLanguageKey(String prefix, String suffix) {
return prefix + "." + this.toLanguageKey() + "." + suffix;
}
private static String readGreedy(StringReader reader) {
int start = reader.getCursor();
while (reader.canRead() && isAllowedInIdentifier(reader.peek())) {
reader.skip();
}
return reader.getString().substring(start, reader.getCursor());
}
public static Identifier read(StringReader reader) throws CommandSyntaxException {
int start = reader.getCursor();
String raw = readGreedy(reader);
try {
return parse(raw);
} catch (IdentifierException var4) {
reader.setCursor(start);
throw ERROR_INVALID.createWithContext(reader);
}
}
public static Identifier readNonEmpty(StringReader reader) throws CommandSyntaxException {
int start = reader.getCursor();
String raw = readGreedy(reader);
if (raw.isEmpty()) {
throw ERROR_INVALID.createWithContext(reader);
} else {
try {
return parse(raw);
} catch (IdentifierException var4) {
reader.setCursor(start);
throw ERROR_INVALID.createWithContext(reader);
}
}
}
public static boolean isAllowedInIdentifier(char c) {
return c >= '0' && c <= '9' || c >= 'a' && c <= 'z' || c == '_' || c == ':' || c == '/' || c == '.' || c == '-';
}
public static boolean isValidPath(String path) {
for (int i = 0; i < path.length(); i++) {
if (!validPathChar(path.charAt(i))) {
return false;
}
}
return true;
}
public static boolean isValidNamespace(String namespace) {
if (namespace.equals("..")) {
return false;
} else {
for (int i = 0; i < namespace.length(); i++) {
if (!validNamespaceChar(namespace.charAt(i))) {
return false;
}
}
return true;
}
}
private static String assertValidNamespace(String namespace, String path) {
if (!isValidNamespace(namespace)) {
throw new IdentifierException("Non [a-z0-9_.-] character in namespace of identifier: " + namespace + ":" + path);
} else {
return namespace;
}
}
public static boolean validPathChar(char c) {
return c == '_' || c == '-' || c >= 'a' && c <= 'z' || c >= '0' && c <= '9' || c == '/' || c == '.';
}
private static boolean validNamespaceChar(char c) {
return c == '_' || c == '-' || c >= 'a' && c <= 'z' || c >= '0' && c <= '9' || c == '.';
}
private static String assertValidPath(String namespace, String path) {
if (!isValidPath(path)) {
throw new IdentifierException("Non [a-z0-9/._-] character in path of location: " + namespace + ":" + path);
} else {
return path;
}
}
}引用的其他类
-
- 引用位置:
构造调用 - 关联成员:
IdentifierException()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.translatable()
- 引用位置:
-
- 引用位置:
字段
- 引用位置: