DropInvalidSignDataFix.java

net.minecraft.util.datafix.fixes.DropInvalidSignDataFix

信息

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

    TODO

字段/常量

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

      TODO

内部类/嵌套类型

构造器

public DropInvalidSignDataFix(Schema outputSchema, String entityName) @ L20

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

参数:

  • outputSchema: Schema
  • entityName: String

说明:

TODO

方法

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

private <T> Dynamic<T> fix(Dynamic<T> tag) @ L25

  • 方法名:fix
  • 源码定位:L25
  • 返回类型: Dynamic
  • 修饰符:private

参数:

  • tag: Dynamic

说明:

TODO

private static <T> Dynamic<T> fixText(Dynamic<T> tag) @ L36

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

参数:

  • tag: Dynamic

说明:

TODO

public TypeRewriteRule makeRule() @ L51

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

参数:

说明:

TODO

代码

public class DropInvalidSignDataFix extends DataFix {
    private final String entityName;
 
    public DropInvalidSignDataFix(Schema outputSchema, String entityName) {
        super(outputSchema, false);
        this.entityName = entityName;
    }
 
    private <T> Dynamic<T> fix(Dynamic<T> tag) {
        tag = tag.update("front_text", DropInvalidSignDataFix::fixText);
        tag = tag.update("back_text", DropInvalidSignDataFix::fixText);
 
        for (String field : BlockEntitySignDoubleSidedEditableTextFix.FIELDS_TO_DROP) {
            tag = tag.remove(field);
        }
 
        return tag;
    }
 
    private static <T> Dynamic<T> fixText(Dynamic<T> tag) {
        Optional<Stream<Dynamic<T>>> filteredLines = tag.get("filtered_messages").asStreamOpt().result();
        if (filteredLines.isEmpty()) {
            return tag;
        } else {
            Dynamic<T> emptyComponent = LegacyComponentDataFixUtils.createEmptyComponent(tag.getOps());
            List<Dynamic<T>> lines = tag.get("messages").asStreamOpt().result().orElse(Stream.of()).toList();
            List<Dynamic<T>> newFilteredLines = Streams.mapWithIndex(filteredLines.get(), (line, index) -> {
                Dynamic<T> fallbackLine = index < lines.size() ? lines.get((int)index) : emptyComponent;
                return line.equals(emptyComponent) ? fallbackLine : line;
            }).toList();
            return newFilteredLines.equals(lines) ? tag.remove("filtered_messages") : tag.set("filtered_messages", tag.createList(newFilteredLines.stream()));
        }
    }
 
    @Override
    public TypeRewriteRule makeRule() {
        Type<?> entityType = this.getInputSchema().getType(References.BLOCK_ENTITY);
        Type<?> entityChoiceType = this.getInputSchema().getChoiceType(References.BLOCK_ENTITY, this.entityName);
        OpticFinder<?> entityF = DSL.namedChoice(this.entityName, entityChoiceType);
        return this.fixTypeEverywhereTyped(
            "DropInvalidSignDataFix for " + this.entityName,
            entityType,
            input -> input.updateTyped(
                entityF,
                entityChoiceType,
                entity -> {
                    boolean filteredCorrect = entity.get(DSL.remainderFinder()).get("_filtered_correct").asBoolean(false);
                    return filteredCorrect
                        ? entity.update(DSL.remainderFinder(), remainder -> remainder.remove("_filtered_correct"))
                        : Util.writeAndReadTypedOrThrow(entity, entityChoiceType, this::fix);
                }
            )
        );
    }
}

引用的其他类

  • Schema

    • 引用位置: 参数
  • Util

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

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

    • 引用位置: 参数/返回值