ThrownPotionSplitFix.java

net.minecraft.util.datafix.fixes.ThrownPotionSplitFix

信息

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

    TODO

字段/常量

  • itemIdFinder
    • 类型: Supplier<ThrownPotionSplitFix.ItemIdFinder>
    • 修饰符: private final
    • 源码定位: L15
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.util.datafix.fixes.ThrownPotionSplitFix.ItemIdFinder
    • 类型: record
    • 修饰符: private
    • 源码定位: L43
    • 说明:

      TODO

构造器

public ThrownPotionSplitFix(Schema outputSchema) @ L29

  • 构造器名:ThrownPotionSplitFix
  • 源码定位:L29
  • 修饰符:public

参数:

  • outputSchema: Schema

说明:

TODO

方法

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

protected Pair<String,Typed<?>> fix(String name, Typed<?> entity) @ L33

  • 方法名:fix
  • 源码定位:L33
  • 返回类型:Pair<String,Typed<?>>
  • 修饰符:protected

参数:

  • name: String
  • entity: Typed<?>

说明:

TODO

代码

public class ThrownPotionSplitFix extends EntityRenameFix {
    private final Supplier<ThrownPotionSplitFix.ItemIdFinder> itemIdFinder = Suppliers.memoize(
        () -> {
            Type<?> potionType = this.getInputSchema().getChoiceType(References.ENTITY, "minecraft:potion");
            Type<?> patchedPotionType = ExtraDataFixUtils.patchSubType(
                potionType, this.getInputSchema().getType(References.ENTITY), this.getOutputSchema().getType(References.ENTITY)
            );
            OpticFinder<?> itemFinder = patchedPotionType.findField("Item");
            OpticFinder<Pair<String, String>> itemIdFinder = DSL.fieldFinder(
                "id", DSL.named(References.ITEM_NAME.typeName(), NamespacedSchema.namespacedString())
            );
            return new ThrownPotionSplitFix.ItemIdFinder(itemFinder, itemIdFinder);
        }
    );
 
    public ThrownPotionSplitFix(Schema outputSchema) {
        super("ThrownPotionSplitFix", outputSchema, true);
    }
 
    @Override
    protected Pair<String, Typed<?>> fix(String name, Typed<?> entity) {
        if (!name.equals("minecraft:potion")) {
            return Pair.of(name, entity);
        } else {
            String itemId = this.itemIdFinder.get().getItemId(entity);
            return "minecraft:lingering_potion".equals(itemId) ? Pair.of("minecraft:lingering_potion", entity) : Pair.of("minecraft:splash_potion", entity);
        }
    }
 
    private record ItemIdFinder(OpticFinder<?> itemFinder, OpticFinder<Pair<String, String>> itemIdFinder) {
        public String getItemId(Typed<?> entity) {
            return entity.getOptionalTyped(this.itemFinder)
                .flatMap(item -> item.getOptional(this.itemIdFinder))
                .map(Pair::getSecond)
                .map(NamespacedSchema::ensureNamespaced)
                .orElse("");
        }
    }
}

引用的其他类