From c8ab72e550b6a3510891c07e7f7ce2a4d387ce8c Mon Sep 17 00:00:00 2001 From: OneEyeMaker Date: Fri, 22 Sep 2017 08:21:34 +0300 Subject: [PATCH] Now configuration doesn't ignores minimum and maximum values --- .../mod/config/ConfigValues.java | 10 +++++----- .../mod/config/values/ConfigBoolValues.java | 5 +++++ .../mod/config/values/ConfigDoubleValues.java | 18 ++++++++++++++++++ .../mod/config/values/ConfigIntListValues.java | 7 ++++++- .../mod/config/values/ConfigIntValues.java | 18 ++++++++++++++++++ .../config/values/ConfigStringListValues.java | 7 ++++++- 6 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/ConfigValues.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/ConfigValues.java index 1e74fbf60..f98d06d8c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/ConfigValues.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/ConfigValues.java @@ -25,23 +25,23 @@ public final class ConfigValues{ public static void defineConfigValues(Configuration config){ for(ConfigIntValues currConf : ConfigIntValues.values()){ - currConf.currentValue = config.get(currConf.category, currConf.name, currConf.defaultValue, currConf.desc, currConf.min, currConf.max).getInt(); + currConf.initializeValue(config); } for(ConfigDoubleValues currConf : ConfigDoubleValues.values()){ - currConf.currentValue = config.get(currConf.category, currConf.name, currConf.defaultValue, currConf.desc, currConf.min, currConf.max).getDouble(); + currConf.initializeValue(config); } for(ConfigBoolValues currConf : ConfigBoolValues.values()){ - currConf.currentValue = config.get(currConf.category, currConf.name, currConf.defaultValue, currConf.desc).getBoolean(); + currConf.initializeValue(config); } for(ConfigIntListValues currConf : ConfigIntListValues.values()){ - currConf.currentValue = config.get(currConf.category, currConf.name, currConf.defaultValue, currConf.desc).getIntList(); + currConf.initializeValue(config); } for(ConfigStringListValues currConf : ConfigStringListValues.values()){ - currConf.currentValue = config.get(currConf.category, currConf.name, currConf.defaultValue, currConf.desc).getStringList(); + currConf.initializeValue(config); } parseConfiguratorConfig(); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java index ac3223669..bd73e9380 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java @@ -11,6 +11,7 @@ package de.ellpeck.actuallyadditions.mod.config.values; import de.ellpeck.actuallyadditions.mod.config.ConfigCategories; +import net.minecraftforge.common.config.Configuration; public enum ConfigBoolValues{ @@ -72,6 +73,10 @@ public enum ConfigBoolValues{ this.desc = desc; } + public void initializeValue(Configuration config){ + this.currentValue = config.get(this.category, this.name, this.defaultValue, this.desc).getBoolean(); + } + public boolean isEnabled(){ return this.currentValue; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigDoubleValues.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigDoubleValues.java index 312fd4d9d..ece72e082 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigDoubleValues.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigDoubleValues.java @@ -1,6 +1,8 @@ package de.ellpeck.actuallyadditions.mod.config.values; import de.ellpeck.actuallyadditions.mod.config.ConfigCategories; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; public enum ConfigDoubleValues { @@ -31,6 +33,22 @@ public enum ConfigDoubleValues this.desc = desc; } + public void initializeValue(Configuration config){ + Property property = config.get(this.category, this.name, this.defaultValue, this.desc, this.min, this.max); + double value = property.getDouble(); + if (value < this.min) + { + value = this.min; + property.set(this.min); + } + if (value > this.max) + { + value = this.max; + property.set(this.max); + } + this.currentValue = value; + } + public double getValue(){ return this.currentValue; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigIntListValues.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigIntListValues.java index 400a2f854..0c019f980 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigIntListValues.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigIntListValues.java @@ -11,6 +11,7 @@ package de.ellpeck.actuallyadditions.mod.config.values; import de.ellpeck.actuallyadditions.mod.config.ConfigCategories; +import net.minecraftforge.common.config.Configuration; public enum ConfigIntListValues{ @@ -33,8 +34,12 @@ public enum ConfigIntListValues{ this.desc = desc; } + public void initializeValue(Configuration config){ + this.currentValue = config.get(this.category, this.name, this.defaultValue, this.desc).getIntList(); + } + public int[] getValue(){ return this.currentValue; } -} \ No newline at end of file +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigIntValues.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigIntValues.java index 4d00641f1..35032afcf 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigIntValues.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigIntValues.java @@ -11,6 +11,8 @@ package de.ellpeck.actuallyadditions.mod.config.values; import de.ellpeck.actuallyadditions.mod.config.ConfigCategories; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; public enum ConfigIntValues{ @@ -79,6 +81,22 @@ public enum ConfigIntValues{ this.desc = desc; } + public void initializeValue(Configuration config){ + Property property = config.get(this.category, this.name, this.defaultValue, this.desc, this.min, this.max); + int value = property.getInt(); + if (value < this.min) + { + value = this.min; + property.set(this.min); + } + if (value > this.max) + { + value = this.max; + property.set(this.max); + } + this.currentValue = value; + } + public int getValue(){ return this.currentValue; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigStringListValues.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigStringListValues.java index ff239b302..13e2afdcc 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigStringListValues.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigStringListValues.java @@ -11,6 +11,7 @@ package de.ellpeck.actuallyadditions.mod.config.values; import de.ellpeck.actuallyadditions.mod.config.ConfigCategories; +import net.minecraftforge.common.config.Configuration; public enum ConfigStringListValues{ @@ -41,8 +42,12 @@ public enum ConfigStringListValues{ this.desc = desc; } + public void initializeValue(Configuration config){ + this.currentValue = config.get(this.category, this.name, this.defaultValue, this.desc).getStringList(); + } + public String[] getValue(){ return this.currentValue; } -} \ No newline at end of file +}