ItemRenameFix.java

net.minecraft.util.datafix.fixes.ItemRenameFix

信息

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

    TODO

字段/常量

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

      TODO

内部类/嵌套类型

构造器

public ItemRenameFix(Schema outputSchema, String name) @ L16

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

参数:

  • outputSchema: Schema
  • name: String

说明:

TODO

方法

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

public TypeRewriteRule makeRule() @ L21

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

参数:

说明:

TODO

protected abstract String fixItem(String item) @ L31

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

参数:

  • item: String

说明:

TODO

public static DataFix create(Schema outputSchema, String name, Function<String,String> fixItem) @ L33

  • 方法名:create
  • 源码定位:L33
  • 返回类型:DataFix
  • 修饰符:public static

参数:

  • outputSchema: Schema
  • name: String
  • fixItem: Function<String,String>

说明:

TODO

代码

public abstract class ItemRenameFix extends DataFix {
    private final String name;
 
    public ItemRenameFix(Schema outputSchema, String name) {
        super(outputSchema, false);
        this.name = name;
    }
 
    @Override
    public TypeRewriteRule makeRule() {
        Type<Pair<String, String>> itemNameType = DSL.named(References.ITEM_NAME.typeName(), NamespacedSchema.namespacedString());
        if (!Objects.equals(this.getInputSchema().getType(References.ITEM_NAME), itemNameType)) {
            throw new IllegalStateException("item name type is not what was expected.");
        } else {
            return this.fixTypeEverywhere(this.name, itemNameType, ops -> input -> input.mapSecond(this::fixItem));
        }
    }
 
    protected abstract String fixItem(final String item);
 
    public static DataFix create(Schema outputSchema, String name, Function<String, String> fixItem) {
        return new ItemRenameFix(outputSchema, name) {
            @Override
            protected String fixItem(String item) {
                return fixItem.apply(item);
            }
        };
    }
}

引用的其他类

  • Schema

    • 引用位置: 参数
  • NamespacedSchema

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