BlockRenameFix.java
net.minecraft.util.datafix.fixes.BlockRenameFix
信息
- 全限定名:net.minecraft.util.datafix.fixes.BlockRenameFix
- 类型:public abstract class
- 包:net.minecraft.util.datafix.fixes
- 源码路径:src/main/java/net/minecraft/util/datafix/fixes/BlockRenameFix.java
- 起始行号:L16
- 继承:DataFix
- 职责:
TODO
字段/常量
name- 类型:
String - 修饰符:
private final - 源码定位:
L17 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public BlockRenameFix(Schema outputSchema, String name) @ L19
- 构造器名:BlockRenameFix
- 源码定位:L19
- 修饰符:public
参数:
- outputSchema: Schema
- name: String
说明:
TODO
方法
下面的方法块按源码顺序生成。
public TypeRewriteRule makeRule() @ L24
- 方法名:makeRule
- 源码定位:L24
- 返回类型:TypeRewriteRule
- 修饰符:public
参数:
- 无
说明:
TODO
private Dynamic<?> fixBlockState(Dynamic<?> tag) @ L48
- 方法名:fixBlockState
- 源码定位:L48
- 返回类型:Dynamic<?>
- 修饰符:private
参数:
- tag: Dynamic<?>
说明:
TODO
private String fixFlatBlockState(String string) @ L53
- 方法名:fixFlatBlockState
- 源码定位:L53
- 返回类型:String
- 修饰符:private
参数:
- string: String
说明:
TODO
protected abstract String renameBlock(String block) @ L70
- 方法名:renameBlock
- 源码定位:L70
- 返回类型:String
- 修饰符:protected abstract
参数:
- block: String
说明:
TODO
public static DataFix create(Schema outputSchema, String name, Function<String,String> renamer) @ L72
- 方法名:create
- 源码定位:L72
- 返回类型:DataFix
- 修饰符:public static
参数:
- outputSchema: Schema
- name: String
- renamer: Function<String,String>
说明:
TODO
代码
public abstract class BlockRenameFix extends DataFix {
private final String name;
public BlockRenameFix(Schema outputSchema, String name) {
super(outputSchema, false);
this.name = name;
}
@Override
public TypeRewriteRule makeRule() {
Type<?> blockType = this.getInputSchema().getType(References.BLOCK_NAME);
Type<Pair<String, String>> expectedType = DSL.named(References.BLOCK_NAME.typeName(), NamespacedSchema.namespacedString());
if (!Objects.equals(blockType, expectedType)) {
throw new IllegalStateException("block type is not what was expected.");
} else {
TypeRewriteRule blockRule = this.fixTypeEverywhere(this.name + " for block", expectedType, ops -> input -> input.mapSecond(this::renameBlock));
TypeRewriteRule blockStateRule = this.fixTypeEverywhereTyped(
this.name + " for block_state",
this.getInputSchema().getType(References.BLOCK_STATE),
input -> input.update(DSL.remainderFinder(), this::fixBlockState)
);
TypeRewriteRule flatBlockStateRule = this.fixTypeEverywhereTyped(
this.name + " for flat_block_state",
this.getInputSchema().getType(References.FLAT_BLOCK_STATE),
input -> input.update(
DSL.remainderFinder(), tag -> DataFixUtils.orElse(tag.asString().result().map(this::fixFlatBlockState).map(tag::createString), tag)
)
);
return TypeRewriteRule.seq(blockRule, blockStateRule, flatBlockStateRule);
}
}
private Dynamic<?> fixBlockState(Dynamic<?> tag) {
Optional<String> name = tag.get("Name").asString().result();
return name.isPresent() ? tag.set("Name", tag.createString(this.renameBlock(name.get()))) : tag;
}
private String fixFlatBlockState(String string) {
int startProperties = string.indexOf(91);
int startNbt = string.indexOf(123);
int end = string.length();
if (startProperties > 0) {
end = startProperties;
}
if (startNbt > 0) {
end = Math.min(end, startNbt);
}
String name = string.substring(0, end);
String newName = this.renameBlock(name);
return newName + string.substring(end);
}
protected abstract String renameBlock(String block);
public static DataFix create(Schema outputSchema, String name, Function<String, String> renamer) {
return new BlockRenameFix(outputSchema, name) {
@Override
protected String renameBlock(String block) {
return renamer.apply(block);
}
};
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
NamespacedSchema.namespacedString()
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置: