aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/util
diff options
context:
space:
mode:
authorGlease <4586901+Glease@users.noreply.github.com>2022-03-14 14:21:25 +0800
committerGitHub <noreply@github.com>2022-03-14 07:21:25 +0100
commit34a94189cf413164d2364dad26325688bc8128e6 (patch)
tree1e36040a988261d9fd95e5098fc2e49095c88a8e /src/main/java/gregtech/api/util
parentbb924f35d8e8c9ce58f5667e2df03ac02a4215b0 (diff)
downloadGT5-Unofficial-34a94189cf413164d2364dad26325688bc8128e6.tar.gz
GT5-Unofficial-34a94189cf413164d2364dad26325688bc8128e6.tar.bz2
GT5-Unofficial-34a94189cf413164d2364dad26325688bc8128e6.zip
save config late (#982)
Diffstat (limited to 'src/main/java/gregtech/api/util')
-rw-r--r--src/main/java/gregtech/api/util/GT_Config.java17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/main/java/gregtech/api/util/GT_Config.java b/src/main/java/gregtech/api/util/GT_Config.java
index f78abc52fb..4a0b15408f 100644
--- a/src/main/java/gregtech/api/util/GT_Config.java
+++ b/src/main/java/gregtech/api/util/GT_Config.java
@@ -1,6 +1,7 @@
package gregtech.api.util;
import gregtech.api.GregTech_API;
+import gregtech.api.enums.GT_Values;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
@@ -20,13 +21,19 @@ public class GT_Config implements Runnable {
GregTech_API.sAfterGTPreload.add(this); // in case of crash on startup
GregTech_API.sAfterGTLoad.add(this); // in case of crash on startup
GregTech_API.sAfterGTPostload.add(this);
+ if (GT_Values.lateConfigSave)
+ GregTech_API.sFirstWorldTick.add(this);
+ }
+
+ private static boolean shouldSave() {
+ return GT_Values.lateConfigSave ? GT_Values.worldTickHappened : GregTech_API.sPostloadFinished;
}
public static int addIDConfig(Object aCategory, String aName, int aDefault) {
if (GT_Utility.isStringInvalid(aName)) return aDefault;
Property tProperty = sConfigFileIDs.get(aCategory.toString().replaceAll("\\|", "."), aName.replaceAll("\\|", "."), aDefault);
int rResult = tProperty.getInt(aDefault);
- if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) sConfigFileIDs.save();
+ if (!tProperty.wasRead() && shouldSave()) sConfigFileIDs.save();
return rResult;
}
@@ -52,7 +59,7 @@ public class GT_Config implements Runnable {
if (GT_Utility.isStringInvalid(aName)) return aDefault;
Property tProperty = mConfig.get(aCategory.toString().replaceAll("\\|", "_"), (aName + "_" + aDefault).replaceAll("\\|", "_"), aDefault);
boolean rResult = tProperty.getBoolean(aDefault);
- if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) mConfig.save();
+ if (!tProperty.wasRead() && shouldSave()) mConfig.save();
return rResult;
}
@@ -64,7 +71,7 @@ public class GT_Config implements Runnable {
if (GT_Utility.isStringInvalid(aName)) return aDefault;
Property tProperty = mConfig.get(aCategory.toString().replaceAll("\\|", "_"), (aName + "_" + aDefault).replaceAll("\\|", "_"), aDefault);
int rResult = tProperty.getInt(aDefault);
- if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) mConfig.save();
+ if (!tProperty.wasRead() && shouldSave()) mConfig.save();
return rResult;
}
@@ -76,7 +83,7 @@ public class GT_Config implements Runnable {
if (GT_Utility.isStringInvalid(aName)) return aDefault;
Property tProperty = mConfig.get(aCategory.toString().replaceAll("\\|", "_"), (aName + "_" + aDefault).replaceAll("\\|", "_"), aDefault);
double rResult = tProperty.getDouble(aDefault);
- if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) mConfig.save();
+ if (!tProperty.wasRead() && shouldSave()) mConfig.save();
return rResult;
}
@@ -88,7 +95,7 @@ public class GT_Config implements Runnable {
if (GT_Utility.isStringInvalid(aName)) return aDefault;
Property tProperty = mConfig.get(aCategory.toString().replaceAll("\\|", "_"), (aName + "_" + aDefault).replaceAll("\\|", "_"), aDefault);
String rResult = tProperty.getString();
- if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) mConfig.save();
+ if (!tProperty.wasRead() && shouldSave()) mConfig.save();
return rResult;
}