EmptyItemInVillagerTradeFix.java

net.minecraft.util.datafix.fixes.EmptyItemInVillagerTradeFix

信息

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

    TODO

字段/常量

内部类/嵌套类型

构造器

public EmptyItemInVillagerTradeFix(Schema outputSchema) @ L11

  • 构造器名:EmptyItemInVillagerTradeFix
  • 源码定位:L11
  • 修饰符:public

参数:

  • outputSchema: Schema

说明:

TODO

方法

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

public TypeRewriteRule makeRule() @ L15

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

参数:

说明:

TODO

代码

public class EmptyItemInVillagerTradeFix extends DataFix {
    public EmptyItemInVillagerTradeFix(Schema outputSchema) {
        super(outputSchema, false);
    }
 
    @Override
    public TypeRewriteRule makeRule() {
        Type<?> tradeType = this.getInputSchema().getType(References.VILLAGER_TRADE);
        return this.writeFixAndRead("EmptyItemInVillagerTradeFix", tradeType, tradeType, input -> {
            Dynamic<?> buyB = input.get("buyB").orElseEmptyMap();
            String id = NamespacedSchema.ensureNamespaced(buyB.get("id").asString("minecraft:air"));
            int count = buyB.get("count").asInt(0);
            return !id.equals("minecraft:air") && count != 0 ? input : input.remove("buyB");
        });
    }
}

引用的其他类

  • Schema

    • 引用位置: 参数
  • NamespacedSchema

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