|
| 1 | +package io.github.mosadie.ExponentialPower; |
| 2 | + |
| 3 | +import java.io.File; |
| 4 | + |
| 5 | +import net.minecraftforge.common.config.Configuration; |
| 6 | +import net.minecraftforge.common.config.Property; |
| 7 | + |
| 8 | +public class ConfigHandler { |
| 9 | + |
| 10 | + //Configuration Catagories |
| 11 | + public static final String CONFIG_ENDER_GENERATOR = "EnderGenerator"; |
| 12 | + public static final String CONFIG_ADVANCED_ENDER_GENERATOR = "AdvancedEnderGenerator"; |
| 13 | + public static final String CONFIG_ENDER_STORAGE = "EnderStorage"; |
| 14 | + |
| 15 | + //Config |
| 16 | + private static Configuration config; |
| 17 | + |
| 18 | + //Advanced Ender Generator Config Values |
| 19 | + public static double ADVANCED_BASE; |
| 20 | + public static int ADVANCED_MAXSTACK; |
| 21 | + |
| 22 | + //Ender Generator Config Values |
| 23 | + public static double REGULAR_BASE; |
| 24 | + public static int REGULAR_MAXSTACK; |
| 25 | + |
| 26 | + //Ender Storage Config Values |
| 27 | + public static long STORAGE_MAXENERGY; |
| 28 | + |
| 29 | + public static void loadConfig(File configFile) { |
| 30 | + config = new Configuration(configFile); |
| 31 | + config.load(); |
| 32 | + |
| 33 | + //Setup Config Variables |
| 34 | + |
| 35 | + //Advanced Ender Generator |
| 36 | + ADVANCED_BASE = getConfigProp(ExponentialPower.CONFIG_ADVANCED_ENDER_GENERATOR,"Base", "Controls the rate of change of the power output. Remember Base^MaxStack must be less than Double.MAX_VALUE for things to work correctly.", Double.toString(2.0),Double.MIN_VALUE,Double.MAX_VALUE).getDouble(); |
| 37 | + ADVANCED_MAXSTACK = getConfigProp(ExponentialPower.CONFIG_ADVANCED_ENDER_GENERATOR, "MaxStack", "Controls the number of Ender Cells required to reach the maximum power output. Min: 1 Max: 64 (inclusive)", Integer.toString(64), 1, 64).getInt(); |
| 38 | + |
| 39 | + //Ender Generator |
| 40 | + REGULAR_BASE = getConfigProp(ExponentialPower.CONFIG_ENDER_GENERATOR, "Base", "Controls the rate of change of the power output. Remember Base^63 must be less than Long.MAX_VALUE for things to work correctly.", Double.toString(2.0), Long.MIN_VALUE, Long.MAX_VALUE).getDouble(); |
| 41 | + REGULAR_MAXSTACK = getConfigProp(ExponentialPower.CONFIG_ENDER_GENERATOR, "MaxStack", "Controls the number of Ender Cells required to reach the maximum power output. Min: 1 Max: 64 (inclusive)", Integer.toString(64), 1, 64).getInt(); |
| 42 | + |
| 43 | + //Ender Storage |
| 44 | + STORAGE_MAXENERGY = getConfigProp(ExponentialPower.CONFIG_ENDER_STORAGE, "EnderStorageMaximum", "The maximum amount of power that can be stored in a single Ender Storage block. Min: 1 Max: 9223372036854775806", "9223372036854775806", 1.0, 9223372036854775806.0).getLong(); |
| 45 | + } |
| 46 | + |
| 47 | + private static Property getConfigProp(String category, String key, String comment, String defaultValue, double minValue, double maxValue) { |
| 48 | + Property prop = config.get(category, key, defaultValue, comment); |
| 49 | + if (prop.isDefault() || prop.getDouble(minValue) < minValue || prop.getDouble(maxValue) > maxValue) { |
| 50 | + ExponentialPower.LOGGER.info("Setting default value of " + category + " " + key + " to " + defaultValue); |
| 51 | + prop.setValue(defaultValue); |
| 52 | + config.save(); |
| 53 | + } |
| 54 | + return prop; |
| 55 | + } |
| 56 | +} |
0 commit comments