diff options
| author | Arslaan Pathan <[email protected]> | 2025-10-08 22:44:10 +1300 |
|---|---|---|
| committer | Arslaan Pathan <[email protected]> | 2025-10-08 22:44:10 +1300 |
| commit | 90f0c0722175466856b82ef65ada129eb972c425 (patch) | |
| tree | c80ab1c31b3e56066a7c6daa9bdd67c6bd4197cf /src/main/java/net/justlearning/arslaan3102/arslaansmagichax/modules/settings/NumberSetting.java | |
| parent | 9db037f2508ce99f51f6b9fee54a8e1ad12fe566 (diff) | |
| download | arslaansmagichax-90f0c0722175466856b82ef65ada129eb972c425.tar.xz arslaansmagichax-90f0c0722175466856b82ef65ada129eb972c425.zip | |
finish clickgui, add more hacks, add settings, add mixins, add packet event buses and packet events, what the cook why did i put so much shit in one commit
Diffstat (limited to 'src/main/java/net/justlearning/arslaan3102/arslaansmagichax/modules/settings/NumberSetting.java')
| -rw-r--r-- | src/main/java/net/justlearning/arslaan3102/arslaansmagichax/modules/settings/NumberSetting.java | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/modules/settings/NumberSetting.java b/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/modules/settings/NumberSetting.java new file mode 100644 index 0000000..d0f2bee --- /dev/null +++ b/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/modules/settings/NumberSetting.java @@ -0,0 +1,66 @@ +package net.justlearning.arslaan3102.arslaansmagichax.modules.settings; + +public class NumberSetting extends Setting { + + private double min, max, increment; + private double value; + + public NumberSetting(String name, double min, double max, double defaultValue, double increment) { + super(name); + this.min = min; + this.max = max; + this.value = defaultValue; + this.increment = increment; + } + + public static double clamp(double value, double min, double max) { + value = Math.max(min, value); + value = Math.min(max, value); + return value; + } + + public double getValue() { + return value; + } + + public float getValueFloat() { + return (float) value; + } + + public int getValueInt() { + return (int) value; + } + + public double getIncrement() { + return increment; + } + + public double getMin() { + return min; + } + + public double getMax() { + return max; + } + + public void setValue(double value) { + value = clamp(value, this.min, this.max); + value = Math.round(value * (1.0 / this.increment)) / (1.0 / this.increment); + this.value = value; + } + + public void increment(boolean positive) { + if (positive) setValue(getValue() + getIncrement()); + else setValue(getValue() - getIncrement()); + } + + @Override + public String getValueAsString() { + return String.valueOf(value); + } + + @Override + public void setValueFromString(String value) { + setValue(Double.parseDouble(value)); + } +} |
