AddNewChoices.java

net.minecraft.util.datafix.fixes.AddNewChoices

信息

  • 全限定名:net.minecraft.util.datafix.fixes.AddNewChoices
  • 类型:public class
  • 包:net.minecraft.util.datafix.fixes
  • 源码路径:src/main/java/net/minecraft/util/datafix/fixes/AddNewChoices.java
  • 起始行号:L12
  • 继承:DataFix
  • 职责:

    TODO

字段/常量

  • name

    • 类型: String
    • 修饰符: private final
    • 源码定位: L13
    • 说明:

      TODO

  • type

    • 类型: TypeReference
    • 修饰符: private final
    • 源码定位: L14
    • 说明:

      TODO

内部类/嵌套类型

构造器

public AddNewChoices(Schema outputSchema, String name, TypeReference type) @ L16

  • 构造器名:AddNewChoices
  • 源码定位:L16
  • 修饰符:public

参数:

  • outputSchema: Schema
  • name: String
  • type: TypeReference

说明:

TODO

方法

下面的方法块按源码顺序生成。

public TypeRewriteRule makeRule() @ L22

  • 方法名:makeRule
  • 源码定位:L22
  • 返回类型:TypeRewriteRule
  • 修饰符:public

参数:

说明:

TODO

private <K> TypeRewriteRule cap(TaggedChoiceType<K> inputType, TaggedChoiceType<?> outputType) @ L29

  • 方法名:cap
  • 源码定位:L29
  • 返回类型: TypeRewriteRule
  • 修饰符:private

参数:

  • inputType: TaggedChoiceType
  • outputType: TaggedChoiceType<?>

说明:

TODO

代码

public class AddNewChoices extends DataFix {
    private final String name;
    private final TypeReference type;
 
    public AddNewChoices(Schema outputSchema, String name, TypeReference type) {
        super(outputSchema, true);
        this.name = name;
        this.type = type;
    }
 
    @Override
    public TypeRewriteRule makeRule() {
        TaggedChoiceType<?> inputType = this.getInputSchema().findChoiceType(this.type);
        TaggedChoiceType<?> outputType = this.getOutputSchema().findChoiceType(this.type);
        return this.cap(inputType, outputType);
    }
 
    private <K> TypeRewriteRule cap(TaggedChoiceType<K> inputType, TaggedChoiceType<?> outputType) {
        if (inputType.getKeyType() != outputType.getKeyType()) {
            throw new IllegalStateException("Could not inject: key type is not the same");
        } else {
            return this.fixTypeEverywhere(
                this.name,
                inputType,
                (TaggedChoiceType<K>)outputType,
                ops -> input -> {
                    if (!((TaggedChoiceType<K>)outputType).hasType(input.getFirst())) {
                        throw new IllegalArgumentException(
                            String.format(Locale.ROOT, "%s: Unknown type %s in '%s'", this.name, input.getFirst(), this.type.typeName())
                        );
                    } else {
                        return input;
                    }
                }
            );
        }
    }
}

引用的其他类