ItemWaterPotionFix.java

net.minecraft.util.datafix.fixes.ItemWaterPotionFix

信息

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

    TODO

字段/常量

内部类/嵌套类型

构造器

public ItemWaterPotionFix(Schema outputSchema, boolean changesType) @ L16

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

参数:

  • outputSchema: Schema
  • changesType: boolean

说明:

TODO

方法

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

public TypeRewriteRule makeRule() @ L20

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

参数:

说明:

TODO

代码

public class ItemWaterPotionFix extends DataFix {
    public ItemWaterPotionFix(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");
        return this.fixTypeEverywhereTyped(
            "ItemWaterPotionFix",
            itemStackType,
            input -> {
                Optional<Pair<String, String>> idOpt = input.getOptional(idF);
                if (idOpt.isPresent()) {
                    String id = idOpt.get().getSecond();
                    if ("minecraft:potion".equals(id)
                        || "minecraft:splash_potion".equals(id)
                        || "minecraft:lingering_potion".equals(id)
                        || "minecraft:tipped_arrow".equals(id)) {
                        Typed<?> tag = input.getOrCreateTyped(tagF);
                        Dynamic<?> tagRest = tag.get(DSL.remainderFinder());
                        if (tagRest.get("Potion").asString().result().isEmpty()) {
                            tagRest = tagRest.set("Potion", tagRest.createString("minecraft:water"));
                        }
 
                        return input.set(tagF, tag.set(DSL.remainderFinder(), tagRest));
                    }
                }
 
                return input;
            }
        );
    }
}

引用的其他类

  • Schema

    • 引用位置: 参数
  • NamespacedSchema

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