BlockNameFlatteningFix.java

net.minecraft.util.datafix.fixes.BlockNameFlatteningFix

信息

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

    TODO

字段/常量

内部类/嵌套类型

构造器

public BlockNameFlatteningFix(Schema outputSchema, boolean changesType) @ L14

  • 构造器名:BlockNameFlatteningFix
  • 源码定位:L14
  • 修饰符:public

参数:

  • outputSchema: Schema
  • changesType: boolean

说明:

TODO

方法

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

public TypeRewriteRule makeRule() @ L18

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

参数:

说明:

TODO

代码

public class BlockNameFlatteningFix extends DataFix {
    public BlockNameFlatteningFix(Schema outputSchema, boolean changesType) {
        super(outputSchema, changesType);
    }
 
    @Override
    public TypeRewriteRule makeRule() {
        Type<?> blockType = this.getInputSchema().getType(References.BLOCK_NAME);
        Type<?> newBlockType = this.getOutputSchema().getType(References.BLOCK_NAME);
        Type<Pair<String, Either<Integer, String>>> expectedBlockType = DSL.named(
            References.BLOCK_NAME.typeName(), DSL.or(DSL.intType(), NamespacedSchema.namespacedString())
        );
        Type<Pair<String, String>> expectedNewBlockType = DSL.named(References.BLOCK_NAME.typeName(), NamespacedSchema.namespacedString());
        if (Objects.equals(blockType, expectedBlockType) && Objects.equals(newBlockType, expectedNewBlockType)) {
            return this.fixTypeEverywhere(
                "BlockNameFlatteningFix",
                expectedBlockType,
                expectedNewBlockType,
                ops -> block -> block.mapSecond(
                    choice -> choice.map(BlockStateData::upgradeBlock, name -> BlockStateData.upgradeBlock(NamespacedSchema.ensureNamespaced(name)))
                )
            );
        } else {
            throw new IllegalStateException("Expected and actual types don't match.");
        }
    }
}

引用的其他类

  • Schema

    • 引用位置: 参数
  • BlockStateData

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

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