ItemBannerColorFix.java
net.minecraft.util.datafix.fixes.ItemBannerColorFix
信息
- 全限定名:net.minecraft.util.datafix.fixes.ItemBannerColorFix
- 类型:public class
- 包:net.minecraft.util.datafix.fixes
- 源码路径:src/main/java/net/minecraft/util/datafix/fixes/ItemBannerColorFix.java
- 起始行号:L18
- 继承:DataFix
- 职责:
TODO
字段/常量
- 无
内部类/嵌套类型
- 无
构造器
public ItemBannerColorFix(Schema outputSchema, boolean changesType) @ L19
- 构造器名:ItemBannerColorFix
- 源码定位:L19
- 修饰符:public
参数:
- outputSchema: Schema
- changesType: boolean
说明:
TODO
方法
下面的方法块按源码顺序生成。
public TypeRewriteRule makeRule() @ L23
- 方法名:makeRule
- 源码定位:L23
- 返回类型:TypeRewriteRule
- 修饰符:public
参数:
- 无
说明:
TODO
代码
public class ItemBannerColorFix extends DataFix {
public ItemBannerColorFix(Schema outputSchema, boolean changesType) {
super(outputSchema, changesType);
}
@Override
public TypeRewriteRule makeRule() {
Type<?> itemStackType = this.getInputSchema().getType(References.ITEM_STACK);
OpticFinder<Pair<String, String>> idF = DSL.fieldFinder("id", DSL.named(References.ITEM_NAME.typeName(), NamespacedSchema.namespacedString()));
OpticFinder<?> tagF = itemStackType.findField("tag");
OpticFinder<?> blockEntityF = tagF.type().findField("BlockEntityTag");
return this.fixTypeEverywhereTyped(
"ItemBannerColorFix",
itemStackType,
input -> {
Optional<Pair<String, String>> id = input.getOptional(idF);
if (id.isPresent() && Objects.equals(id.get().getSecond(), "minecraft:banner")) {
Dynamic<?> rest = input.get(DSL.remainderFinder());
Optional<? extends Typed<?>> tagOpt = input.getOptionalTyped(tagF);
if (tagOpt.isPresent()) {
Typed<?> tag = (Typed<?>)tagOpt.get();
Optional<? extends Typed<?>> blockEntityOpt = tag.getOptionalTyped(blockEntityF);
if (blockEntityOpt.isPresent()) {
Typed<?> blockEntity = (Typed<?>)blockEntityOpt.get();
Dynamic<?> tagRest = tag.get(DSL.remainderFinder());
Dynamic<?> blockEntityRest = blockEntity.getOrCreate(DSL.remainderFinder());
if (blockEntityRest.get("Base").asNumber().result().isPresent()) {
rest = rest.set("Damage", rest.createShort((short)(blockEntityRest.get("Base").asInt(0) & 15)));
Optional<? extends Dynamic<?>> displayOptional = tagRest.get("display").result();
if (displayOptional.isPresent()) {
Dynamic<?> display = (Dynamic<?>)displayOptional.get();
Dynamic<?> pickMarker = display.createMap(
ImmutableMap.of(display.createString("Lore"), display.createList(Stream.of(display.createString("(+NBT"))))
);
if (Objects.equals(display, pickMarker)) {
return input.set(DSL.remainderFinder(), rest);
}
}
blockEntityRest.remove("Base");
return input.set(DSL.remainderFinder(), rest)
.set(tagF, tag.set(blockEntityF, blockEntity.set(DSL.remainderFinder(), blockEntityRest)));
}
}
}
return input.set(DSL.remainderFinder(), rest);
} else {
return input;
}
}
);
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
NamespacedSchema.namespacedString()
- 引用位置: