|
1 | 1 | package pro.mikey.fabric.xray; |
2 | 2 |
|
| 3 | +import net.minecraft.util.math.MathHelper; |
| 4 | +import pro.mikey.fabric.xray.storage.Stores; |
| 5 | + |
3 | 6 | public class StateSettings { |
4 | | - public static final int[] DISTANCE_STEPS = new int[] {2, 4, 8, 16, 32, 64, 128, 256}; |
5 | | - private boolean isActive; |
6 | | - private boolean showLava; |
7 | | - private int range; |
8 | | - private boolean showOverlay; |
9 | | - |
10 | | - public StateSettings() { |
11 | | - this.isActive = false; |
12 | | - this.showLava = false; |
13 | | - this.showOverlay = true; |
14 | | - this.range = 3; |
15 | | - } |
16 | | - |
17 | | - public boolean isActive() { |
18 | | - return this.isActive; |
19 | | - } |
20 | | - |
21 | | - void setActive(boolean active) { |
22 | | - this.isActive = active; |
23 | | - } |
24 | | - |
25 | | - public boolean isShowLava() { |
26 | | - return this.showLava; |
27 | | - } |
28 | | - |
29 | | - public void setShowLava(boolean showLava) { |
30 | | - this.showLava = showLava; |
31 | | - } |
32 | | - |
33 | | - // Fail softly if the index is out of bounds |
34 | | - public int getRange() { |
35 | | - return Math.max(0, Math.min(DISTANCE_STEPS.length - 1, this.range)); |
36 | | - } |
37 | | - |
38 | | - public void increaseRange() { |
39 | | - if (this.range < DISTANCE_STEPS.length - 1) { |
40 | | - this.range += 1; |
41 | | - } else { |
42 | | - this.range = 0; |
43 | | - } |
44 | | - } |
45 | | - |
46 | | - public void decreaseRange() { |
47 | | - if (this.range > 0) { |
48 | | - this.range -= 1; |
49 | | - } else { |
50 | | - this.range = DISTANCE_STEPS.length - 1; |
51 | | - } |
52 | | - } |
53 | | - |
54 | | - public boolean showOverlay() { |
55 | | - return this.showOverlay; |
56 | | - } |
57 | | - |
58 | | - public void setShowOverlay(boolean showOverlay) { |
59 | | - this.showOverlay = showOverlay; |
60 | | - } |
| 7 | + private static final int maxStepsToScan = 5; |
| 8 | + |
| 9 | + private transient boolean isActive; |
| 10 | + private boolean showLava; |
| 11 | + private int range; |
| 12 | + private boolean showOverlay; |
| 13 | + |
| 14 | + public StateSettings() { |
| 15 | + this.isActive = false; |
| 16 | + this.showLava = false; |
| 17 | + this.showOverlay = true; |
| 18 | + this.range = 3; |
| 19 | + } |
| 20 | + |
| 21 | + public boolean isActive() { |
| 22 | + return this.isActive; |
| 23 | + } |
| 24 | + |
| 25 | + void setActive(boolean active) { |
| 26 | + this.isActive = active; |
| 27 | + } |
| 28 | + |
| 29 | + public boolean isShowLava() { |
| 30 | + return this.showLava; |
| 31 | + } |
| 32 | + |
| 33 | + public void setShowLava(boolean showLava) { |
| 34 | + this.showLava = showLava; |
| 35 | + } |
| 36 | + |
| 37 | + public static int getRadius() { |
| 38 | + return MathHelper.clamp(Stores.SETTINGS.get().range, 0, maxStepsToScan) * 3; |
| 39 | + } |
| 40 | + |
| 41 | + public static int getHalfRange() { |
| 42 | + return Math.max(0, getRadius() / 2); |
| 43 | + } |
| 44 | + |
| 45 | + public static int getVisualRadius() { |
| 46 | + return Math.max(1, getRadius()); |
| 47 | + } |
| 48 | + |
| 49 | + public void increaseRange() { |
| 50 | + if (Stores.SETTINGS.get().range < maxStepsToScan) |
| 51 | + Stores.SETTINGS.get().range = Stores.SETTINGS.get().range + 1; |
| 52 | + else |
| 53 | + Stores.SETTINGS.get().range = 0; |
| 54 | + } |
| 55 | + |
| 56 | + public void decreaseRange() { |
| 57 | + if (Stores.SETTINGS.get().range > 0) |
| 58 | + Stores.SETTINGS.get().range = Stores.SETTINGS.get().range - 1; |
| 59 | + else |
| 60 | + Stores.SETTINGS.get().range = maxStepsToScan; |
| 61 | + } |
| 62 | + |
| 63 | + public boolean showOverlay() { |
| 64 | + return this.showOverlay; |
| 65 | + } |
| 66 | + |
| 67 | + public void setShowOverlay(boolean showOverlay) { |
| 68 | + this.showOverlay = showOverlay; |
| 69 | + } |
61 | 70 | } |
0 commit comments