VillagerTradeFix.java

net.minecraft.util.datafix.fixes.VillagerTradeFix

信息

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

    TODO

字段/常量

内部类/嵌套类型

构造器

public VillagerTradeFix(Schema outputSchema) @ L16

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

参数:

  • outputSchema: Schema

说明:

TODO

方法

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

protected TypeRewriteRule makeRule() @ L20

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

参数:

说明:

TODO

private Typed<?> updateItemStack(OpticFinder<Pair<String,String>> idF, Typed<?> itemStack) @ L35

  • 方法名:updateItemStack
  • 源码定位:L35
  • 返回类型:Typed<?>
  • 修饰符:private

参数:

  • idF: OpticFinder<Pair<String,String>>
  • itemStack: Typed<?>

说明:

TODO

代码

public class VillagerTradeFix extends DataFix {
    public VillagerTradeFix(Schema outputSchema) {
        super(outputSchema, false);
    }
 
    @Override
    protected TypeRewriteRule makeRule() {
        Type<?> recipeType = this.getInputSchema().getType(References.VILLAGER_TRADE);
        OpticFinder<?> buyFinder = recipeType.findField("buy");
        OpticFinder<?> buyBFinder = recipeType.findField("buyB");
        OpticFinder<?> sellFinder = recipeType.findField("sell");
        OpticFinder<Pair<String, String>> idF = DSL.fieldFinder("id", DSL.named(References.ITEM_NAME.typeName(), NamespacedSchema.namespacedString()));
        Function<Typed<?>, Typed<?>> itemStackUpdater = itemStack -> this.updateItemStack(idF, itemStack);
        return this.fixTypeEverywhereTyped(
            "Villager trade fix",
            recipeType,
            recipe -> recipe.updateTyped(buyFinder, itemStackUpdater).updateTyped(buyBFinder, itemStackUpdater).updateTyped(sellFinder, itemStackUpdater)
        );
    }
 
    private Typed<?> updateItemStack(OpticFinder<Pair<String, String>> idF, Typed<?> itemStack) {
        return itemStack.update(idF, pair -> pair.mapSecond(name -> Objects.equals(name, "minecraft:carved_pumpkin") ? "minecraft:pumpkin" : name));
    }
}

引用的其他类

  • Schema

    • 引用位置: 参数
  • NamespacedSchema

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