DifficultyInstance.java

net.minecraft.world.DifficultyInstance

信息

  • 全限定名:net.minecraft.world.DifficultyInstance
  • 类型:public class
  • 包:net.minecraft.world
  • 源码路径:src/main/java/net/minecraft/world/DifficultyInstance.java
  • 起始行号:L7
  • 职责:

    TODO

字段/常量

  • DIFFICULTY_TIME_GLOBAL_OFFSET

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

      TODO

  • MAX_DIFFICULTY_TIME_GLOBAL

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

      TODO

  • MAX_DIFFICULTY_TIME_LOCAL

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

      TODO

  • base

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

      TODO

  • effectiveDifficulty

    • 类型: float
    • 修饰符: private final
    • 源码定位: L12
    • 说明:

      TODO

内部类/嵌套类型

构造器

public DifficultyInstance(Difficulty base, long totalGameTime, long localGameTime, float moonBrightness) @ L14

  • 构造器名:DifficultyInstance
  • 源码定位:L14
  • 修饰符:public

参数:

  • base: Difficulty
  • totalGameTime: long
  • localGameTime: long
  • moonBrightness: float

说明:

TODO

方法

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

public Difficulty getDifficulty() @ L19

  • 方法名:getDifficulty
  • 源码定位:L19
  • 返回类型:Difficulty
  • 修饰符:public

参数:

说明:

TODO

public float getEffectiveDifficulty() @ L23

  • 方法名:getEffectiveDifficulty
  • 源码定位:L23
  • 返回类型:float
  • 修饰符:public

参数:

说明:

TODO

public boolean isHard() @ L27

  • 方法名:isHard
  • 源码定位:L27
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public boolean isHarderThan(float requiredDifficulty) @ L31

  • 方法名:isHarderThan
  • 源码定位:L31
  • 返回类型:boolean
  • 修饰符:public

参数:

  • requiredDifficulty: float

说明:

TODO

public float getSpecialMultiplier() @ L35

  • 方法名:getSpecialMultiplier
  • 源码定位:L35
  • 返回类型:float
  • 修饰符:public

参数:

说明:

TODO

private float calculateDifficulty(Difficulty base, long totalGameTime, long localGameTime, float moonBrightness) @ L43

  • 方法名:calculateDifficulty
  • 源码定位:L43
  • 返回类型:float
  • 修饰符:private

参数:

  • base: Difficulty
  • totalGameTime: long
  • localGameTime: long
  • moonBrightness: float

说明:

TODO

代码

@Immutable
public class DifficultyInstance {
    private static final float DIFFICULTY_TIME_GLOBAL_OFFSET = -72000.0F;
    private static final float MAX_DIFFICULTY_TIME_GLOBAL = 1440000.0F;
    private static final float MAX_DIFFICULTY_TIME_LOCAL = 3600000.0F;
    private final Difficulty base;
    private final float effectiveDifficulty;
 
    public DifficultyInstance(Difficulty base, long totalGameTime, long localGameTime, float moonBrightness) {
        this.base = base;
        this.effectiveDifficulty = this.calculateDifficulty(base, totalGameTime, localGameTime, moonBrightness);
    }
 
    public Difficulty getDifficulty() {
        return this.base;
    }
 
    public float getEffectiveDifficulty() {
        return this.effectiveDifficulty;
    }
 
    public boolean isHard() {
        return this.effectiveDifficulty >= Difficulty.HARD.ordinal();
    }
 
    public boolean isHarderThan(float requiredDifficulty) {
        return this.effectiveDifficulty > requiredDifficulty;
    }
 
    public float getSpecialMultiplier() {
        if (this.effectiveDifficulty < 2.0F) {
            return 0.0F;
        } else {
            return this.effectiveDifficulty > 4.0F ? 1.0F : (this.effectiveDifficulty - 2.0F) / 2.0F;
        }
    }
 
    private float calculateDifficulty(Difficulty base, long totalGameTime, long localGameTime, float moonBrightness) {
        if (base == Difficulty.PEACEFUL) {
            return 0.0F;
        } else {
            boolean isHard = base == Difficulty.HARD;
            float scale = 0.75F;
            float globalScale = Mth.clamp(((float)totalGameTime + -72000.0F) / 1440000.0F, 0.0F, 1.0F) * 0.25F;
            scale += globalScale;
            float localScale = 0.0F;
            localScale += Mth.clamp((float)localGameTime / 3600000.0F, 0.0F, 1.0F) * (isHard ? 1.0F : 0.75F);
            localScale += Mth.clamp(moonBrightness * 0.25F, 0.0F, globalScale);
            if (base == Difficulty.EASY) {
                localScale *= 0.5F;
            }
 
            scale += localScale;
            return base.getId() * scale;
        }
    }
}

引用的其他类

  • Mth

    • 引用位置: 方法调用
    • 关联成员: Mth.clamp()
  • Difficulty

    • 引用位置: 参数/字段/返回值