Skip to content

Commit

Permalink
init setting classes before loading
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Jul 4, 2023
1 parent d941a97 commit dc4940b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/main/java/xaeroplus/XaeroPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xaeroplus.module.ModuleManager;
import xaeroplus.settings.XaeroPlusSettingRegistry;
import xaeroplus.util.Shared;

public class XaeroPlus implements ModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("XaeroPlus");
public static final EventBus EVENT_BUS = new EventBus(Runnable::run);
private static boolean a = Shared.settingsLoadedInit; // needed to load static shared classes on init
@Override
public void onInitialize() {
ModuleManager.init();
boolean a = Shared.settingsLoadedInit; // force static instances to init
XaeroPlusSettingRegistry.fastMapSetting.getValue(); // force static instances to init
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Optional;

public class XaeroPlusModSettingsHooks {
private static int loadCount = 0;

public static void saveSettings(File configFile, List<XaeroPlusSetting> settings) throws IOException {
try (PrintWriter writer = new PrintWriter(new FileWriter(configFile, true))) {
Expand All @@ -25,6 +26,7 @@ public static void saveSettings(File configFile, List<XaeroPlusSetting> settings
}

public static void loadSettings(File file, List<XaeroPlusSetting> settings) throws IOException {
loadCount++;
try(BufferedReader reader = new BufferedReader(new FileReader(file))) {
String s;
while ((s = reader.readLine()) != null) {
Expand All @@ -44,7 +46,8 @@ public static void loadSettings(File file, List<XaeroPlusSetting> settings) thro
}
}
}
Shared.onSettingLoad();
// 1 for minimap, 1 for worldmap
if (loadCount == 2) Shared.onAllSettingsDoneLoading();
}

public static void getClientBooleanValue(String enumString, List<XaeroPlusSetting> settings, CallbackInfoReturnable<Boolean> cir) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/xaeroplus/util/Shared.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ public class Shared {
Math.max(1, Math.min(Runtime.getRuntime().availableProcessors() / 2, 4)));
public static final Identifier xpGuiTextures = new Identifier("xaeroplus", "gui/xpgui.png");

public static void onSettingLoad() {
public static void onAllSettingsDoneLoading() {
if (!settingsLoadedInit) { // handle settings where we want them to take effect only on first load
XaeroPlusSettingRegistry.fastMapSetting.getValue(); // force load all settings if they haven't been already
XaeroPlusSettingsReflectionHax.ALL_SETTINGS.get().forEach(XaeroPlusSetting::init);
nullOverworldDimensionFolder = XaeroPlusSettingRegistry.nullOverworldDimensionFolder.getValue();
dataFolderResolutionMode = XaeroPlusSettingRegistry.dataFolderResolutionMode.getValue();
Expand Down

0 comments on commit dc4940b

Please sign in to comment.