StatsRenameFix.java
net.minecraft.util.datafix.fixes.StatsRenameFix
信息
- 全限定名:net.minecraft.util.datafix.fixes.StatsRenameFix
- 类型:public class
- 包:net.minecraft.util.datafix.fixes
- 源码路径:src/main/java/net/minecraft/util/datafix/fixes/StatsRenameFix.java
- 起始行号:L13
- 继承:DataFix
- 职责:
TODO
字段/常量
-
name- 类型:
String - 修饰符:
private final - 源码定位:
L14 - 说明:
TODO
- 类型:
-
renames- 类型:
Map<String,String> - 修饰符:
private final - 源码定位:
L15 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public StatsRenameFix(Schema outputSchema, String name, Map<String,String> renames) @ L17
- 构造器名:StatsRenameFix
- 源码定位:L17
- 修饰符:public
参数:
- outputSchema: Schema
- name: String
- renames: Map<String,String>
说明:
TODO
方法
下面的方法块按源码顺序生成。
protected TypeRewriteRule makeRule() @ L23
- 方法名:makeRule
- 源码定位:L23
- 返回类型:TypeRewriteRule
- 修饰符:protected
参数:
- 无
说明:
TODO
private TypeRewriteRule createCriteriaRule() @ L28
- 方法名:createCriteriaRule
- 源码定位:L28
- 返回类型:TypeRewriteRule
- 修饰符:private
参数:
- 无
说明:
TODO
private TypeRewriteRule createStatRule() @ L53
- 方法名:createStatRule
- 源码定位:L53
- 返回类型:TypeRewriteRule
- 修饰符:private
参数:
- 无
说明:
TODO
代码
public class StatsRenameFix extends DataFix {
private final String name;
private final Map<String, String> renames;
public StatsRenameFix(Schema outputSchema, String name, Map<String, String> renames) {
super(outputSchema, false);
this.name = name;
this.renames = renames;
}
@Override
protected TypeRewriteRule makeRule() {
return TypeRewriteRule.seq(this.createStatRule(), this.createCriteriaRule());
}
private TypeRewriteRule createCriteriaRule() {
Type<?> outputType = this.getOutputSchema().getType(References.OBJECTIVE);
Type<?> inputType = this.getInputSchema().getType(References.OBJECTIVE);
OpticFinder<?> criteriaTypeFinder = inputType.findField("CriteriaType");
TaggedChoiceType<?> choiceType = criteriaTypeFinder.type()
.findChoiceType("type", -1)
.orElseThrow(() -> new IllegalStateException("Can't find choice type for criteria"));
Type<?> customFieldType = choiceType.types().get("minecraft:custom");
if (customFieldType == null) {
throw new IllegalStateException("Failed to find custom criterion type variant");
} else {
OpticFinder<?> customTypeFinder = DSL.namedChoice("minecraft:custom", customFieldType);
OpticFinder<String> idFinder = DSL.fieldFinder("id", NamespacedSchema.namespacedString());
return this.fixTypeEverywhereTyped(
this.name,
inputType,
outputType,
input -> input.updateTyped(
criteriaTypeFinder,
stats -> stats.updateTyped(customTypeFinder, custom -> custom.update(idFinder, value -> this.renames.getOrDefault(value, value)))
)
);
}
}
private TypeRewriteRule createStatRule() {
Type<?> outputType = this.getOutputSchema().getType(References.STATS);
Type<?> inputType = this.getInputSchema().getType(References.STATS);
OpticFinder<?> statsFinder = inputType.findField("stats");
OpticFinder<?> customFinder = statsFinder.type().findField("minecraft:custom");
OpticFinder<String> nameFinder = NamespacedSchema.namespacedString().finder();
return this.fixTypeEverywhereTyped(
this.name,
inputType,
outputType,
input -> input.updateTyped(
statsFinder, stats -> stats.updateTyped(customFinder, custom -> custom.update(nameFinder, value -> this.renames.getOrDefault(value, value)))
)
);
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
NamespacedSchema.namespacedString()
- 引用位置: