UnflattenTextComponentFix.java

net.minecraft.util.datafix.fixes.UnflattenTextComponentFix

信息

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

    TODO

字段/常量

  • LOGGER
    • 类型: Logger
    • 修饰符: private static final
    • 源码定位: L18
    • 说明:

      TODO

内部类/嵌套类型

构造器

public UnflattenTextComponentFix(Schema outputSchema) @ L20

  • 构造器名:UnflattenTextComponentFix
  • 源码定位:L20
  • 修饰符:public

参数:

  • outputSchema: Schema

说明:

TODO

方法

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

protected TypeRewriteRule makeRule() @ L24

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

参数:

说明:

TODO

private <T> TypeRewriteRule createFixer(Type<Pair<String,String>> textComponentType, Type<T> newTextComponentType) @ L31

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

参数:

  • textComponentType: Type<Pair<String,String>>
  • newTextComponentType: Type

说明:

TODO

private static <T> Dynamic<T> unflattenJson(DynamicOps<T> ops, String jsonString) @ L40

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

参数:

  • ops: DynamicOps
  • jsonString: String

说明:

TODO

代码

public class UnflattenTextComponentFix extends DataFix {
    private static final Logger LOGGER = LogUtils.getLogger();
 
    public UnflattenTextComponentFix(Schema outputSchema) {
        super(outputSchema, true);
    }
 
    @Override
    protected TypeRewriteRule makeRule() {
        Type<Pair<String, String>> textComponentType = (Type<Pair<String, String>>)this.getInputSchema().getType(References.TEXT_COMPONENT);
        Type<?> newTextComponentType = this.getOutputSchema().getType(References.TEXT_COMPONENT);
        return this.createFixer(textComponentType, newTextComponentType);
    }
 
    private <T> TypeRewriteRule createFixer(Type<Pair<String, String>> textComponentType, Type<T> newTextComponentType) {
        return this.fixTypeEverywhere(
            "UnflattenTextComponentFix",
            textComponentType,
            newTextComponentType,
            ops -> input -> Util.readTypedOrThrow(newTextComponentType, unflattenJson(ops, input.getSecond()), true).getValue()
        );
    }
 
    private static <T> Dynamic<T> unflattenJson(DynamicOps<T> ops, String jsonString) {
        try {
            JsonElement json = LenientJsonParser.parse(jsonString);
            if (!json.isJsonNull()) {
                return new Dynamic<>(ops, JsonOps.INSTANCE.convertTo(ops, json));
            }
        } catch (Exception var3) {
            LOGGER.error("Failed to unflatten text component json: {}", jsonString, var3);
        }
 
        return new Dynamic<>(ops, ops.createString(jsonString));
    }
}

引用的其他类

  • Schema

    • 引用位置: 参数
  • LenientJsonParser

    • 引用位置: 方法调用
    • 关联成员: LenientJsonParser.parse()
  • Util

    • 引用位置: 方法调用
    • 关联成员: Util.readTypedOrThrow()
  • ResolvableProfile

    • 引用位置: 返回值