TextComponentStringifiedFlagsFix.java

net.minecraft.util.datafix.fixes.TextComponentStringifiedFlagsFix

信息

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

    TODO

字段/常量

内部类/嵌套类型

构造器

public TextComponentStringifiedFlagsFix(Schema outputSchema) @ L13

  • 构造器名:TextComponentStringifiedFlagsFix
  • 源码定位:L13
  • 修饰符:public

参数:

  • outputSchema: Schema

说明:

TODO

方法

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

protected TypeRewriteRule makeRule() @ L17

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

参数:

说明:

TODO

private static <T> Dynamic<T> stringToBool(Dynamic<T> input) @ L42

  • 方法名:stringToBool
  • 源码定位:L42
  • 返回类型: Dynamic
  • 修饰符:private static

参数:

  • input: Dynamic

说明:

TODO

代码

public class TextComponentStringifiedFlagsFix extends DataFix {
    public TextComponentStringifiedFlagsFix(Schema outputSchema) {
        super(outputSchema, false);
    }
 
    @Override
    protected TypeRewriteRule makeRule() {
        Type<Pair<String, Either<?, Pair<?, Pair<?, Pair<?, Dynamic<?>>>>>>> textComponentType = (Type<Pair<String, Either<?, Pair<?, Pair<?, Pair<?, Dynamic<?>>>>>>>)this.getInputSchema()
            .getType(References.TEXT_COMPONENT);
        return this.fixTypeEverywhere(
            "TextComponentStringyFlagsFix",
            textComponentType,
            ops -> named -> named.mapSecond(
                e1 -> e1.mapRight(
                    p2 -> p2.mapSecond(
                        p3 -> p3.mapSecond(
                            p4 -> p4.mapSecond(
                                remainder -> remainder.update("bold", TextComponentStringifiedFlagsFix::stringToBool)
                                    .update("italic", TextComponentStringifiedFlagsFix::stringToBool)
                                    .update("underlined", TextComponentStringifiedFlagsFix::stringToBool)
                                    .update("strikethrough", TextComponentStringifiedFlagsFix::stringToBool)
                                    .update("obfuscated", TextComponentStringifiedFlagsFix::stringToBool)
                            )
                        )
                    )
                )
            )
        );
    }
 
    private static <T> Dynamic<T> stringToBool(Dynamic<T> input) {
        Optional<String> string = input.asString().result();
        return string.isPresent() ? input.createBoolean(Boolean.parseBoolean(string.get())) : input;
    }
}

引用的其他类