V1451_6.java
net.minecraft.util.datafix.schemas.V1451_6
信息
- 全限定名:net.minecraft.util.datafix.schemas.V1451_6
- 类型:public class
- 包:net.minecraft.util.datafix.schemas
- 源码路径:src/main/java/net/minecraft/util/datafix/schemas/V1451_6.java
- 起始行号:L19
- 继承:NamespacedSchema
- 职责:
TODO
字段/常量
-
SPECIAL_OBJECTIVE_MARKER- 类型:
String - 修饰符:
public static final - 源码定位:
L20 - 说明:
TODO
- 类型:
-
UNPACK_OBJECTIVE_ID- 类型:
HookFunction - 修饰符:
protected static final public - 源码定位:
L21 - 说明:
TODO
- 类型:
-
REPACK_OBJECTIVE_ID- 类型:
HookFunction - 修饰符:
protected static final public - 源码定位:
L61 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public V1451_6(int versionKey, Schema parent) @ L88
- 构造器名:V1451_6
- 源码定位:L88
- 修饰符:public
参数:
- versionKey: int
- parent: Schema
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void registerTypes(Schema schema, Map<String,Supplier<TypeTemplate>> entityTypes, Map<String,Supplier<TypeTemplate>> blockEntityTypes) @ L92
- 方法名:registerTypes
- 源码定位:L92
- 返回类型:void
- 修饰符:public
参数:
- schema: Schema
- entityTypes: Map<String,Supplier
> - blockEntityTypes: Map<String,Supplier
>
说明:
TODO
protected static Map<String,Supplier<TypeTemplate>> createCriterionTypes(Schema schema) @ L128
- 方法名:createCriterionTypes
- 源码定位:L128
- 返回类型:Map<String,Supplier
> - 修饰符:protected static
参数:
- schema: Schema
说明:
TODO
public static String packNamespacedWithDot(String location) @ L146
- 方法名:packNamespacedWithDot
- 源码定位:L146
- 返回类型:String
- 修饰符:public static
参数:
- location: String
说明:
TODO
代码
public class V1451_6 extends NamespacedSchema {
public static final String SPECIAL_OBJECTIVE_MARKER = "_special";
protected static final HookFunction UNPACK_OBJECTIVE_ID = new HookFunction() {
@Override
public <T> T apply(DynamicOps<T> ops, T value) {
Dynamic<T> input = new Dynamic<>(ops, value);
return DataFixUtils.orElse(
input.get("CriteriaName")
.asString()
.result()
.map(name -> {
int colonPos = name.indexOf(58);
if (colonPos < 0) {
return Pair.of("_special", name);
} else {
try {
Identifier statType = Identifier.bySeparator(name.substring(0, colonPos), '.');
Identifier statId = Identifier.bySeparator(name.substring(colonPos + 1), '.');
return Pair.of(statType.toString(), statId.toString());
} catch (Exception var4) {
return Pair.of("_special", name);
}
}
})
.map(
explodedId -> input.set(
"CriteriaType",
input.createMap(
ImmutableMap.of(
input.createString("type"),
input.createString(explodedId.getFirst()),
input.createString("id"),
input.createString(explodedId.getSecond())
)
)
)
),
input
)
.getValue();
}
};
protected static final HookFunction REPACK_OBJECTIVE_ID = new HookFunction() {
@Override
public <T> T apply(DynamicOps<T> ops, T value) {
Dynamic<T> input = new Dynamic<>(ops, value);
Optional<Dynamic<T>> repackedId = input.get("CriteriaType")
.get()
.result()
.flatMap(
type -> {
Optional<String> statType = type.get("type").asString().result();
Optional<String> statId = type.get("id").asString().result();
if (statType.isPresent() && statId.isPresent()) {
String unpackedType = statType.get();
return unpackedType.equals("_special")
? Optional.of(input.createString(statId.get()))
: Optional.of(
type.createString(V1451_6.packNamespacedWithDot(unpackedType) + ":" + V1451_6.packNamespacedWithDot(statId.get()))
);
} else {
return Optional.empty();
}
}
);
return DataFixUtils.orElse(repackedId.map(id -> input.set("CriteriaName", (Dynamic<?>)id).remove("CriteriaType")), input).getValue();
}
};
public V1451_6(int versionKey, Schema parent) {
super(versionKey, parent);
}
@Override
public void registerTypes(Schema schema, Map<String, Supplier<TypeTemplate>> entityTypes, Map<String, Supplier<TypeTemplate>> blockEntityTypes) {
super.registerTypes(schema, entityTypes, blockEntityTypes);
Supplier<TypeTemplate> ITEM_STATS = () -> DSL.compoundList(References.ITEM_NAME.in(schema), DSL.constType(DSL.intType()));
schema.registerType(
false,
References.STATS,
() -> DSL.optionalFields(
"stats",
DSL.optionalFields(
Pair.of("minecraft:mined", DSL.compoundList(References.BLOCK_NAME.in(schema), DSL.constType(DSL.intType()))),
Pair.of("minecraft:crafted", ITEM_STATS.get()),
Pair.of("minecraft:used", ITEM_STATS.get()),
Pair.of("minecraft:broken", ITEM_STATS.get()),
Pair.of("minecraft:picked_up", ITEM_STATS.get()),
Pair.of("minecraft:dropped", ITEM_STATS.get()),
Pair.of("minecraft:killed", DSL.compoundList(References.ENTITY_NAME.in(schema), DSL.constType(DSL.intType()))),
Pair.of("minecraft:killed_by", DSL.compoundList(References.ENTITY_NAME.in(schema), DSL.constType(DSL.intType()))),
Pair.of("minecraft:custom", DSL.compoundList(DSL.constType(namespacedString()), DSL.constType(DSL.intType())))
)
)
);
Map<String, Supplier<TypeTemplate>> criterionTypes = createCriterionTypes(schema);
schema.registerType(
false,
References.OBJECTIVE,
() -> DSL.hook(
DSL.optionalFields(
"CriteriaType", DSL.taggedChoiceLazy("type", DSL.string(), criterionTypes), "DisplayName", References.TEXT_COMPONENT.in(schema)
),
UNPACK_OBJECTIVE_ID,
REPACK_OBJECTIVE_ID
)
);
}
protected static Map<String, Supplier<TypeTemplate>> createCriterionTypes(Schema schema) {
Supplier<TypeTemplate> itemCriterion = () -> DSL.optionalFields("id", References.ITEM_NAME.in(schema));
Supplier<TypeTemplate> blockCriterion = () -> DSL.optionalFields("id", References.BLOCK_NAME.in(schema));
Supplier<TypeTemplate> entityCriterion = () -> DSL.optionalFields("id", References.ENTITY_NAME.in(schema));
Map<String, Supplier<TypeTemplate>> criterionTypes = Maps.newHashMap();
criterionTypes.put("minecraft:mined", blockCriterion);
criterionTypes.put("minecraft:crafted", itemCriterion);
criterionTypes.put("minecraft:used", itemCriterion);
criterionTypes.put("minecraft:broken", itemCriterion);
criterionTypes.put("minecraft:picked_up", itemCriterion);
criterionTypes.put("minecraft:dropped", itemCriterion);
criterionTypes.put("minecraft:killed", entityCriterion);
criterionTypes.put("minecraft:killed_by", entityCriterion);
criterionTypes.put("minecraft:custom", () -> DSL.optionalFields("id", DSL.constType(namespacedString())));
criterionTypes.put("_special", () -> DSL.optionalFields("id", DSL.constType(DSL.string())));
return criterionTypes;
}
public static String packNamespacedWithDot(String location) {
Identifier parsedLoc = Identifier.tryParse(location);
return parsedLoc != null ? parsedLoc.getNamespace() + "." + parsedLoc.getPath() : location;
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
Identifier.bySeparator(), Identifier.tryParse()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
继承
- 引用位置: