AreaEffectCloudPotionFix.java

net.minecraft.util.datafix.fixes.AreaEffectCloudPotionFix

信息

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

    TODO

字段/常量

内部类/嵌套类型

构造器

public AreaEffectCloudPotionFix(Schema outputSchema) @ L10

  • 构造器名:AreaEffectCloudPotionFix
  • 源码定位:L10
  • 修饰符:public

参数:

  • outputSchema: Schema

说明:

TODO

方法

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

protected Typed<?> fix(Typed<?> entity) @ L14

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

参数:

  • entity: Typed<?>

说明:

TODO

private <T> Dynamic<T> fix(Dynamic<T> entity) @ L19

  • 方法名:fix
  • 源码定位:L19
  • 返回类型: Dynamic
  • 修饰符:private

参数:

  • entity: Dynamic

说明:

TODO

代码

public class AreaEffectCloudPotionFix extends NamedEntityFix {
    public AreaEffectCloudPotionFix(Schema outputSchema) {
        super(outputSchema, false, "AreaEffectCloudPotionFix", References.ENTITY, "minecraft:area_effect_cloud");
    }
 
    @Override
    protected Typed<?> fix(Typed<?> entity) {
        return entity.update(DSL.remainderFinder(), this::fix);
    }
 
    private <T> Dynamic<T> fix(Dynamic<T> entity) {
        Optional<Dynamic<T>> color = entity.get("Color").result();
        Optional<Dynamic<T>> effects = entity.get("effects").result();
        Optional<Dynamic<T>> potion = entity.get("Potion").result();
        entity = entity.remove("Color").remove("effects").remove("Potion");
        if (color.isEmpty() && effects.isEmpty() && potion.isEmpty()) {
            return entity;
        } else {
            Dynamic<T> potionContents = entity.emptyMap();
            if (color.isPresent()) {
                potionContents = potionContents.set("custom_color", color.get());
            }
 
            if (effects.isPresent()) {
                potionContents = potionContents.set("custom_effects", effects.get());
            }
 
            if (potion.isPresent()) {
                potionContents = potionContents.set("potion", potion.get());
            }
 
            return entity.set("potion_contents", potionContents);
        }
    }
}

引用的其他类