Prevent accessing Cfg from mixin before init by initializing in static{}
This commit is contained in:
parent
f03432f1a1
commit
cdbf234d91
|
@ -18,23 +18,22 @@ public class DynRes implements LibWebInit {
|
|||
public static File resFile;
|
||||
public static Cfg cfg;
|
||||
public static String resourceLink = "";
|
||||
private static boolean initialized = false;
|
||||
|
||||
static {
|
||||
AutoConfig.register(Cfg.class, JanksonConfigSerializer::new);
|
||||
cfg = AutoConfig.getConfigHolder(Cfg.class).getConfig();
|
||||
resFile = new File(FabricLoader.getInstance().getGameDir().toFile(), cfg.resourcesFile);
|
||||
if (!resFile.isFile()) {
|
||||
FabricGuiEntry.displayCriticalError(new FileNotFoundException("The file " + resFile + " does not exist in the game directory but is required"), true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(LibWebAPI api) {
|
||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER) {
|
||||
try {
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
AutoConfig.register(Cfg.class, JanksonConfigSerializer::new);
|
||||
cfg = AutoConfig.getConfigHolder(Cfg.class).getConfig();
|
||||
resFile = new File(FabricLoader.getInstance().getGameDir().toFile(), cfg.resourcesFile);
|
||||
if (!resFile.isFile()) {
|
||||
FabricGuiEntry.displayCriticalError(new FileNotFoundException("The file " + resFile + " does not exist in the game directory but is required"), true);
|
||||
}
|
||||
Logger.l.info("Initialized DynRes");
|
||||
}
|
||||
resourceLink = api.registerFile("/resources.zip", resFile.toPath(), !cfg.hashResources);
|
||||
Logger.l.info("Initialized DynRes /resources.zip");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue