Skip to content

Commit f8725d9

Browse files
committed
Fix config files being empty until blocks are used.
Fixes #18.
1 parent f8c6a87 commit f8725d9

10 files changed

Lines changed: 80 additions & 36 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
1111
//Only edit below this line, the above code adds and enables the nessasary things for Forge to be setup.
1212

1313

14-
version = "1.4.0"
14+
version = "1.4.0.1"
1515
group= "io.github.mosadie.ExponentialPower" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
1616
archivesBaseName = "ExponentialPower"
1717

src/main/java/io/github/mosadie/ExponentialPower/CommonProxy.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
public class CommonProxy {
1616
public void preInit(FMLPreInitializationEvent e) {
17+
ConfigHandler.loadConfig(e.getSuggestedConfigurationFile());
1718
NetworkRegistry.INSTANCE.registerGuiHandler(ExponentialPower.instance, new GUIHandler());
1819
}
1920

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
}

src/main/java/io/github/mosadie/ExponentialPower/ExponentialPower.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import org.apache.logging.log4j.Logger;
44
import net.minecraftforge.common.MinecraftForge;
5-
import net.minecraftforge.common.config.Configuration;
6-
import net.minecraftforge.common.config.Property;
75
import net.minecraftforge.fml.common.Mod;
86
import net.minecraftforge.fml.common.Mod.EventHandler;
97
import net.minecraftforge.fml.common.Mod.Instance;
@@ -16,7 +14,7 @@
1614
public class ExponentialPower {
1715
public static final String MODID = "exponentialpower";
1816
public static final String MODNAME = "Exponential Power";
19-
public static final String VERSION = "1.4.0";
17+
public static final String VERSION = "1.4.0.1";
2018
public static final String UPDATEJSON = "https://raw.githubusercontent.com/MoSadie/ExponentialPower/master/update.json";
2119

2220
public static final String CONFIG_ENDER_GENERATOR = "EnderGenerator";
@@ -28,8 +26,6 @@ public class ExponentialPower {
2826

2927
public static Logger LOGGER;
3028

31-
public static Configuration config;
32-
3329
@SidedProxy(clientSide="io.github.mosadie.ExponentialPower.ClientProxy", serverSide="io.github.mosadie.ExponentialPower.ServerProxy")
3430
public static CommonProxy proxy;
3531

@@ -39,8 +35,6 @@ public ExponentialPower() {
3935

4036
@EventHandler
4137
public void preInit(FMLPreInitializationEvent e) {
42-
config = new Configuration(e.getSuggestedConfigurationFile());
43-
config.load();
4438
LOGGER = e.getModLog();
4539
proxy.preInit(e);
4640
//Create Blocks and Items
@@ -57,13 +51,4 @@ public void postInit(FMLPostInitializationEvent e) {
5751
proxy.postInit(e);
5852
//Don't Think I need this...
5953
}
60-
61-
public static Property getConfigProp(String category, String key, String comment, String defaultValue) {
62-
Property prop = config.get(category, key, defaultValue, comment);
63-
if (prop.isDefault()) {
64-
prop.setValue(defaultValue);
65-
config.save();
66-
}
67-
return prop;
68-
}
6954
}

src/main/java/io/github/mosadie/ExponentialPower/GUIContainer/ContainerAdvancedEnderGeneratorTE.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.github.mosadie.ExponentialPower.GUIContainer;
22

3-
import io.github.mosadie.ExponentialPower.ExponentialPower;
3+
import io.github.mosadie.ExponentialPower.ConfigHandler;
44
import io.github.mosadie.ExponentialPower.TileEntitys.AdvancedEnderGeneratorTE;
55
import net.minecraft.entity.player.EntityPlayer;
66
import net.minecraft.inventory.Container;
@@ -15,7 +15,7 @@ public class ContainerAdvancedEnderGeneratorTE extends Container {
1515
public ContainerAdvancedEnderGeneratorTE(IInventory playerInv, AdvancedEnderGeneratorTE te) {
1616
this.te = te;
1717

18-
int maxStack = ExponentialPower.getConfigProp(ExponentialPower.CONFIG_ADVANCED_ENDER_GENERATOR, "MaxStack", "Controls the number of Ender Cells required to reach the maximum power output and how many Ender Cells can be placed in the generator. Min: 1 Max: 64 (inclusive)", Integer.toString(64)).getInt();
18+
int maxStack = ConfigHandler.ADVANCED_MAXSTACK;
1919
if (maxStack > 64) maxStack = 64;
2020
else if (maxStack <= 0) maxStack = 1;
2121

src/main/java/io/github/mosadie/ExponentialPower/GUIContainer/ContainerEnderGeneratorTE.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.github.mosadie.ExponentialPower.GUIContainer;
22

3-
import io.github.mosadie.ExponentialPower.ExponentialPower;
3+
import io.github.mosadie.ExponentialPower.ConfigHandler;
44
import io.github.mosadie.ExponentialPower.TileEntitys.EnderGeneratorTE;
55
import net.minecraft.entity.player.EntityPlayer;
66
import net.minecraft.inventory.Container;
@@ -15,7 +15,7 @@ public class ContainerEnderGeneratorTE extends Container {
1515
public ContainerEnderGeneratorTE(IInventory playerInv, EnderGeneratorTE te) {
1616
this.te = te;
1717

18-
int maxStack = ExponentialPower.getConfigProp(ExponentialPower.CONFIG_ENDER_GENERATOR, "MaxStack", "Controls the number of Ender Cells required to reach the maximum power output and how many Ender Cells can be placed in the generator. Min: 1 Max: 64 (inclusive)", Integer.toString(64)).getInt();
18+
int maxStack = ConfigHandler.REGULAR_MAXSTACK;
1919
if (maxStack > 64) maxStack = 64;
2020
else if (maxStack <= 0) maxStack = 1;
2121

src/main/java/io/github/mosadie/ExponentialPower/TileEntitys/AdvancedEnderGeneratorTE.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import javax.annotation.Nullable;
44

5-
import io.github.mosadie.ExponentialPower.ExponentialPower;
5+
import io.github.mosadie.ExponentialPower.ConfigHandler;
66
import io.github.mosadie.ExponentialPower.Items.ItemManager;
77
import io.github.mosadie.ExponentialPower.energy.advancedgenerator.*;
88
import net.darkhax.tesla.api.ITeslaConsumer;
@@ -38,8 +38,8 @@ public class AdvancedEnderGeneratorTE extends TileEntity implements ITickable, I
3838
private TeslaEnergyConnection tec;
3939

4040
public AdvancedEnderGeneratorTE() {
41-
base = ExponentialPower.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)).getDouble();
42-
maxStack = ExponentialPower.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)).getInt();
41+
base = ConfigHandler.ADVANCED_BASE;
42+
maxStack = ConfigHandler.ADVANCED_MAXSTACK;
4343
if (maxStack > 64) maxStack = 64;
4444
else if (maxStack <= 0) maxStack = 1;
4545
fec = new ForgeEnergyConnection(this, true, false);

src/main/java/io/github/mosadie/ExponentialPower/TileEntitys/EnderGeneratorTE.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import javax.annotation.Nullable;
44

5-
import io.github.mosadie.ExponentialPower.ExponentialPower;
5+
import io.github.mosadie.ExponentialPower.ConfigHandler;
66
import io.github.mosadie.ExponentialPower.Items.ItemManager;
77
import io.github.mosadie.ExponentialPower.energy.generator.*;
88
import net.darkhax.tesla.api.ITeslaConsumer;
@@ -31,15 +31,15 @@ public class EnderGeneratorTE extends TileEntity implements ITickable, IInventor
3131
public NonNullList<ItemStack> Inventory = NonNullList.withSize(1, ItemStack.EMPTY);
3232
public String customName;
3333

34-
private final long base;
34+
private final double base;
3535
private int maxStack;
3636

3737
private ForgeEnergyConnection fec;
3838
private TeslaEnergyConnection tec;
3939

4040
public EnderGeneratorTE() {
41-
base = ExponentialPower.getConfigProp(ExponentialPower.CONFIG_ENDER_GENERATOR, "Base", "Controls the rate of change of the power output. Remember Base^MaxStack must be less than Long.MAX_VALUE for things to work correctly.", Long.toString(2)).getLong();
42-
maxStack = ExponentialPower.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)).getInt();
41+
base = ConfigHandler.REGULAR_BASE;
42+
maxStack = ConfigHandler.REGULAR_MAXSTACK;
4343
if (maxStack > 64) maxStack = 64;
4444
else if (maxStack <= 0) maxStack = 1;
4545
fec = new ForgeEnergyConnection(this, true, false);
@@ -299,9 +299,9 @@ public boolean isEmpty() {
299299
return Inventory.get(0).getCount() == 0;
300300
}
301301

302-
private long longPow (long a, double b) {
302+
private long longPow (double a, double b) {
303303
if (b == 0) return 1L;
304-
if (b == 1) return a;
304+
if (b == 1) return (long)a;
305305
return (long)Math.pow(a, b);
306306
}
307307
}

src/main/java/io/github/mosadie/ExponentialPower/TileEntitys/EnderStorageTE.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
import java.util.EnumMap;
44
import javax.annotation.Nullable;
5-
6-
import io.github.mosadie.ExponentialPower.ExponentialPower;
5+
import io.github.mosadie.ExponentialPower.ConfigHandler;
76
import io.github.mosadie.ExponentialPower.energy.storage.ForgeEnergyConnection;
87
import io.github.mosadie.ExponentialPower.energy.storage.TeslaEnergyConnection;
98
import net.darkhax.tesla.api.ITeslaConsumer;
@@ -28,7 +27,7 @@ public class EnderStorageTE extends TileEntity implements ITickable {
2827
private EnumMap<EnumFacing,TeslaEnergyConnection> tec;
2928

3029
public EnderStorageTE() {
31-
maxEnergy = ExponentialPower.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").getLong();
30+
maxEnergy = ConfigHandler.STORAGE_MAXENERGY;
3231
if (maxEnergy < 1) maxEnergy = 1;
3332
freezeExpend = new EnumMap<EnumFacing,Boolean>(EnumFacing.class);
3433
fec = new EnumMap<EnumFacing,ForgeEnergyConnection>(EnumFacing.class);

update.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
{
22
"homepage": "https://minecraft.curseforge.com/projects/exponential-power",
33
"1.12.2" {
4+
"1.4.0.1": "See https://github.com/MoSadie/ExponentialPower/releases/tag/v1.4.0.1",
45
"1.4.0": "See https://github.com/MoSadie/ExponentialPower/releases/tag/v1.4.0",
56
"1.3.2": "See https://github.com/MoSadie/ExponentialPower/releases/tag/v1.3.2"
67
},
78
"1.12.1"
9+
"1.4.0.1": "See https://github.com/MoSadie/ExponentialPower/releases/tag/v1.4.0.1",
810
"1.4.0": "See https://github.com/MoSadie/ExponentialPower/releases/tag/v1.4.0",
911
"1.3.1.1": "See https://github.com/MoSadie/ExponentialPower/releases/tag/v1.3.1.1"
1012
},
1113
"1.12": {
14+
"1.4.0.1": "See https://github.com/MoSadie/ExponentialPower/releases/tag/v1.4.0.1",
1215
"1.4.0": "See https://github.com/MoSadie/ExponentialPower/releases/tag/v1.4.0",
1316
"1.3.1.1": "See https://github.com/MoSadie/ExponentialPower/releases/tag/v1.3.1.1",
1417
"1.3.1": "See https://github.com/MoSadie/ExponentialPower/releases/tag/v1.3.1"
@@ -25,9 +28,9 @@
2528
"1.0.0": "See https://github.com/MoSadie/ExponentialPower/releases/tag/v1.0"
2629
},
2730
"promos": {
28-
"1.12.2-recommended": "1.4.0",
29-
"1.12.1-recommended": "1.4.0",
30-
"1.12-recommended": "1.4.0",
31+
"1.12.2-recommended": "1.4.0.1",
32+
"1.12.1-recommended": "1.4.0.1",
33+
"1.12-recommended": "1.4.0.1",
3134
"1.11.2-recommended": "1.3.0",
3235
"1.10.2-recommended": "1.0.1"
3336
}

0 commit comments

Comments
 (0)