| 1 | package net.minecraft.world;
|
| 2 |
|
| 3 | import javax.annotation.concurrent.Immutable;
|
| 4 | import net.minecraft.util.Mth;
|
| 5 |
|
| 6 | @Immutable
|
| 7 | public class DifficultyInstance {
|
| 8 | private static final float DIFFICULTY_TIME_GLOBAL_OFFSET = -72000.0F;
|
| 9 | private static final float MAX_DIFFICULTY_TIME_GLOBAL = 1440000.0F;
|
| 10 | private static final float MAX_DIFFICULTY_TIME_LOCAL = 3600000.0F;
|
| 11 | private final Difficulty base;
|
| 12 | private final float effectiveDifficulty;
|
| 13 |
|
| 14 | public DifficultyInstance(final Difficulty base, final long totalGameTime, final long localGameTime, final float moonBrightness) {
|
| 15 | this.base = base;
|
| 16 | this.effectiveDifficulty = this.calculateDifficulty(base, totalGameTime, localGameTime, moonBrightness);
|
| 17 | }
|
| 18 |
|
| 19 | public Difficulty getDifficulty() {
|
| 20 | return this.base;
|
| 21 | }
|
| 22 |
|
| 23 | public float getEffectiveDifficulty() {
|
| 24 | return this.effectiveDifficulty;
|
| 25 | }
|
| 26 |
|
| 27 | public boolean isHard() {
|
| 28 | return this.effectiveDifficulty >= Difficulty.HARD.ordinal();
|
| 29 | }
|
| 30 |
|
| 31 | public boolean isHarderThan(final float requiredDifficulty) {
|
| 32 | return this.effectiveDifficulty > requiredDifficulty;
|
| 33 | }
|
| 34 |
|
| 35 | public float getSpecialMultiplier() {
|
| 36 | if (this.effectiveDifficulty < 2.0F) {
|
| 37 | return 0.0F;
|
| 38 | } else {
|
| 39 | return this.effectiveDifficulty > 4.0F ? 1.0F : (this.effectiveDifficulty - 2.0F) / 2.0F;
|
| 40 | }
|
| 41 | }
|
| 42 |
|
| 43 | private float calculateDifficulty(final Difficulty base, final long totalGameTime, final long localGameTime, final float moonBrightness) {
|
| 44 | if (base == Difficulty.PEACEFUL) {
|
| 45 | return 0.0F;
|
| 46 | }
|
| 47 |
|
| 48 | boolean isHard = base == Difficulty.HARD;
|
| 49 | float scale = 0.75F;
|
| 50 | float globalScale = Mth.clamp(((float)totalGameTime + -72000.0F) / 1440000.0F, 0.0F, 1.0F) * 0.25F;
|
| 51 | scale += globalScale;
|
| 52 | float localScale = 0.0F;
|
| 53 | localScale += Mth.clamp((float)localGameTime / 3600000.0F, 0.0F, 1.0F) * (isHard ? 1.0F : 0.75F);
|
| 54 | localScale += Mth.clamp(moonBrightness * 0.25F, 0.0F, globalScale);
|
| 55 | if (base == Difficulty.EASY) {
|
| 56 | localScale *= 0.5F;
|
| 57 | }
|
| 58 |
|
| 59 | scale += localScale;
|
| 60 | return base.getId() * scale;
|
| 61 | }
|
| 62 | }
|
| 63 |
|