TriState.java
net.minecraft.util.TriState
信息
- 全限定名:net.minecraft.util.TriState
- 类型:public enum
- 包:net.minecraft.util
- 源码路径:src/main/java/net/minecraft/util/TriState.java
- 起始行号:L7
- 实现:StringRepresentable
- 职责:
TODO
字段/常量
-
TRUE, FALSE, DEFAULT- 类型:
TriState - 修饰符:
package-private - 源码定位:
L8 - 说明:
TODO
- 类型:
-
CODEC- 类型:
Codec<TriState> - 修饰符:
public static final - 源码定位:
L12 - 说明:
TODO
- 类型:
-
name- 类型:
String - 修饰符:
private final - 源码定位:
L20 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
private TriState(String name) @ L22
- 构造器名:TriState
- 源码定位:L22
- 修饰符:private
参数:
- name: String
说明:
TODO
方法
下面的方法块按源码顺序生成。
public static TriState from(boolean value) @ L26
- 方法名:from
- 源码定位:L26
- 返回类型:TriState
- 修饰符:public static
参数:
- value: boolean
说明:
TODO
public boolean toBoolean(boolean defaultValue) @ L30
- 方法名:toBoolean
- 源码定位:L30
- 返回类型:boolean
- 修饰符:public
参数:
- defaultValue: boolean
说明:
TODO
public String getSerializedName() @ L38
- 方法名:getSerializedName
- 源码定位:L38
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
代码
public enum TriState implements StringRepresentable {
TRUE("true"),
FALSE("false"),
DEFAULT("default");
public static final Codec<TriState> CODEC = Codec.either(Codec.BOOL, StringRepresentable.fromEnum(TriState::values))
.xmap(either -> either.map(TriState::from, Function.identity()), triState -> {
return switch (triState) {
case TRUE -> Either.left(true);
case FALSE -> Either.left(false);
case DEFAULT -> Either.right(triState);
};
});
private final String name;
private TriState(String name) {
this.name = name;
}
public static TriState from(boolean value) {
return value ? TRUE : FALSE;
}
public boolean toBoolean(boolean defaultValue) {
return switch (this) {
case TRUE -> true;
case FALSE -> false;
default -> defaultValue;
};
}
@Override
public String getSerializedName() {
return this.name;
}
}引用的其他类
- StringRepresentable
- 引用位置:
实现/方法调用 - 关联成员:
StringRepresentable.fromEnum()
- 引用位置: