SimplestEntityRenameFix.java

net.minecraft.util.datafix.fixes.SimplestEntityRenameFix

信息

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

    TODO

字段/常量

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

      TODO

内部类/嵌套类型

构造器

public SimplestEntityRenameFix(String name, Schema outputSchema, boolean changesType) @ L17

  • 构造器名:SimplestEntityRenameFix
  • 源码定位:L17
  • 修饰符:public

参数:

  • name: String
  • outputSchema: Schema
  • changesType: boolean

说明:

TODO

方法

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

public TypeRewriteRule makeRule() @ L22

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

参数:

说明:

TODO

protected abstract String rename(String name) @ L43

  • 方法名:rename
  • 源码定位:L43
  • 返回类型:String
  • 修饰符:protected abstract

参数:

  • name: String

说明:

TODO

代码

public abstract class SimplestEntityRenameFix extends DataFix {
    private final String name;
 
    public SimplestEntityRenameFix(String name, Schema outputSchema, boolean changesType) {
        super(outputSchema, changesType);
        this.name = name;
    }
 
    @Override
    public TypeRewriteRule makeRule() {
        TaggedChoiceType<String> oldType = (TaggedChoiceType<String>)this.getInputSchema().findChoiceType(References.ENTITY);
        TaggedChoiceType<String> newType = (TaggedChoiceType<String>)this.getOutputSchema().findChoiceType(References.ENTITY);
        Type<Pair<String, String>> entityNameType = DSL.named(References.ENTITY_NAME.typeName(), NamespacedSchema.namespacedString());
        if (!Objects.equals(this.getOutputSchema().getType(References.ENTITY_NAME), entityNameType)) {
            throw new IllegalStateException("Entity name type is not what was expected.");
        } else {
            return TypeRewriteRule.seq(this.fixTypeEverywhere(this.name, oldType, newType, ops -> input -> input.mapFirst(oldName -> {
                String newName = this.rename(oldName);
                Type<?> oldEntityType = oldType.types().get(oldName);
                Type<?> newEntityType = newType.types().get(newName);
                if (!newEntityType.equals(oldEntityType, true, true)) {
                    throw new IllegalStateException(String.format(Locale.ROOT, "Dynamic type check failed: %s not equal to %s", newEntityType, oldEntityType));
                } else {
                    return newName;
                }
            })), this.fixTypeEverywhere(this.name + " for entity name", entityNameType, ops -> input -> input.mapSecond(this::rename)));
        }
    }
 
    protected abstract String rename(final String name);
}

引用的其他类

  • Schema

    • 引用位置: 参数
  • NamespacedSchema

    • 引用位置: 方法调用
    • 关联成员: NamespacedSchema.namespacedString()