FixWolfHealth.java

net.minecraft.util.datafix.fixes.FixWolfHealth

信息

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

    TODO

字段/常量

  • WOLF_ID

    • 类型: String
    • 修饰符: private static final
    • 源码定位: L10
    • 说明:

      TODO

  • WOLF_HEALTH

    • 类型: String
    • 修饰符: private static final
    • 源码定位: L11
    • 说明:

      TODO

内部类/嵌套类型

构造器

public FixWolfHealth(Schema outputSchema) @ L13

  • 构造器名:FixWolfHealth
  • 源码定位:L13
  • 修饰符:public

参数:

  • outputSchema: Schema

说明:

TODO

方法

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

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

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

参数:

  • entity: Typed<?>

说明:

TODO

代码

public class FixWolfHealth extends NamedEntityFix {
    private static final String WOLF_ID = "minecraft:wolf";
    private static final String WOLF_HEALTH = "minecraft:generic.max_health";
 
    public FixWolfHealth(Schema outputSchema) {
        super(outputSchema, false, "FixWolfHealth", References.ENTITY, "minecraft:wolf");
    }
 
    @Override
    protected Typed<?> fix(Typed<?> entity) {
        return entity.update(
            DSL.remainderFinder(),
            dynamic -> {
                MutableBoolean healthAdjusted = new MutableBoolean(false);
                dynamic = dynamic.update(
                    "Attributes",
                    attributes -> attributes.createList(
                        attributes.asStream()
                            .map(
                                attribute -> "minecraft:generic.max_health".equals(NamespacedSchema.ensureNamespaced(attribute.get("Name").asString("")))
                                    ? attribute.update("Base", base -> {
                                        if (base.asDouble(0.0) == 20.0) {
                                            healthAdjusted.setTrue();
                                            return base.createDouble(40.0);
                                        } else {
                                            return base;
                                        }
                                    })
                                    : attribute
                            )
                    )
                );
                if (healthAdjusted.isTrue()) {
                    dynamic = dynamic.update("Health", health -> health.createFloat(health.asFloat(0.0F) * 2.0F));
                }
 
                return dynamic;
            }
        );
    }
}

引用的其他类