BlockEntityCustomNameToComponentFix.java
net.minecraft.util.datafix.fixes.BlockEntityCustomNameToComponentFix
信息
- 全限定名:net.minecraft.util.datafix.fixes.BlockEntityCustomNameToComponentFix
- 类型:public class
- 包:net.minecraft.util.datafix.fixes
- 源码路径:src/main/java/net/minecraft/util/datafix/fixes/BlockEntityCustomNameToComponentFix.java
- 起始行号:L17
- 继承:DataFix
- 职责:
TODO
字段/常量
NAMEABLE_BLOCK_ENTITIES- 类型:
Set<String> - 修饰符:
private static final - 源码定位:
L18 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public BlockEntityCustomNameToComponentFix(Schema outputSchema) @ L32
- 构造器名:BlockEntityCustomNameToComponentFix
- 源码定位:L32
- 修饰符:public
参数:
- outputSchema: Schema
说明:
TODO
方法
下面的方法块按源码顺序生成。
public TypeRewriteRule makeRule() @ L36
- 方法名:makeRule
- 源码定位:L36
- 返回类型:TypeRewriteRule
- 修饰符:public
参数:
- 无
说明:
TODO
public static <T> Dynamic<T> fixTagCustomName(Dynamic<T> tag) @ L57
- 方法名:fixTagCustomName
- 源码定位:L57
- 返回类型:
Dynamic - 修饰符:public static
参数:
- tag: Dynamic
说明:
TODO
代码
public class BlockEntityCustomNameToComponentFix extends DataFix {
private static final Set<String> NAMEABLE_BLOCK_ENTITIES = Set.of(
"minecraft:beacon",
"minecraft:banner",
"minecraft:brewing_stand",
"minecraft:chest",
"minecraft:trapped_chest",
"minecraft:dispenser",
"minecraft:dropper",
"minecraft:enchanting_table",
"minecraft:furnace",
"minecraft:hopper",
"minecraft:shulker_box"
);
public BlockEntityCustomNameToComponentFix(Schema outputSchema) {
super(outputSchema, true);
}
@Override
public TypeRewriteRule makeRule() {
OpticFinder<String> idFinder = DSL.fieldFinder("id", NamespacedSchema.namespacedString());
Type<?> inputType = this.getInputSchema().getType(References.BLOCK_ENTITY);
Type<?> outputType = this.getOutputSchema().getType(References.BLOCK_ENTITY);
Type<?> patchedInputType = ExtraDataFixUtils.patchSubType(inputType, inputType, outputType);
return this.fixTypeEverywhereTyped(
"BlockEntityCustomNameToComponentFix",
inputType,
outputType,
input -> {
Optional<String> id = input.getOptional(idFinder);
return id.isPresent() && !NAMEABLE_BLOCK_ENTITIES.contains(id.get())
? ExtraDataFixUtils.cast(outputType, input)
: Util.writeAndReadTypedOrThrow(
ExtraDataFixUtils.cast(patchedInputType, input), outputType, BlockEntityCustomNameToComponentFix::fixTagCustomName
);
}
);
}
public static <T> Dynamic<T> fixTagCustomName(Dynamic<T> tag) {
String name = tag.get("CustomName").asString("");
return name.isEmpty() ? tag.remove("CustomName") : tag.set("CustomName", LegacyComponentDataFixUtils.createPlainTextComponent(tag.getOps(), name));
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Util.writeAndReadTypedOrThrow()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ExtraDataFixUtils.cast(), ExtraDataFixUtils.patchSubType()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
LegacyComponentDataFixUtils.createPlainTextComponent()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
NamespacedSchema.namespacedString()
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置: