Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
import generations.gg.generations.core.generationscore.world.sound.GenerationsSounds;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.RandomSource;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;

import java.nio.file.Path;

/**
* The Main Class of the Generations-Core mod. (Common)
* Registers the mod's items and blocks with Minecraft using Architectury.
Expand All @@ -48,10 +51,15 @@ public class GenerationsCore
/** Cobblemon Detection **/
public static boolean cobblemon = false;

/** Config Directory **/
public static Path CONFIG_DIRECTORY;

/**
* Initializes the Generations-Core mod.
* @param configDirectory The config directory for the Generations-Core mod.
*/
public static void init(boolean cobblemon) {
public static void init(boolean cobblemon, @NotNull Path configDirectory) {
CONFIG_DIRECTORY = configDirectory;
GenerationsCore.cobblemon = cobblemon;
GenerationsSounds.init();
GenerationsCreativeTabs.init();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import generations.gg.generations.core.generationscore.GenerationsCoreExpectPlatform;
import generations.gg.generations.core.generationscore.GenerationsCore;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

import java.nio.file.Files;
Expand All @@ -20,20 +21,23 @@ public class ConfigLoader {

/**
* Loads a config file for a Generations module/extension.
* @param clazz The class of the config file.
* @param subfolder The subfolder for the Generations module/extension. This should be what comes after generations_ in the modid
* @param name The name of the config file.
*
* @param clazz The class of the config file.
* @param subfolder The subfolder for the Generations module/extension. This should be what comes after generations_ in the modid
* @param name The name of the config file.
* @return The config file.
*/
@ApiStatus.Internal
public static <T> T loaderConfig(@NotNull Class<T> clazz, String subfolder, String name) {
try {
Path configPath = GenerationsCoreExpectPlatform.getConfigDirectory().resolve(Path.of("generations", subfolder, name + ".json"));
Path configPath = GenerationsCore.CONFIG_DIRECTORY.resolve(Path.of("generations", subfolder, name + ".json"));
T value = clazz.getConstructor().newInstance();

if (Files.notExists(configPath)) Files.createDirectories(configPath.getParent());
else if (Files.exists(configPath)) value = GSON.fromJson(Files.newBufferedReader(configPath), clazz);

Files.writeString(configPath, GSON.toJson(value));
GenerationsCore.LOGGER.info("Generations-" + subfolder + " config loaded!");
return value;
} catch (Exception e) {
throw new RuntimeException("Failed to load config.", e);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class GenerationsCoreFabric extends GenerationsCore implements ModInitializer {
@Override
public void onInitialize() {
GenerationsCore.init(FabricLoader.getInstance().isModLoaded("cobblemon"));
GenerationsCore.init(FabricLoader.getInstance().isModLoaded("cobblemon"), FabricLoader.getInstance().getConfigDir());
VanillaCompat.setup();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLPaths;

/**
* Forge Main class for GenerationsCore.
Expand All @@ -29,7 +30,7 @@ public GenerationsCoreForge() {
// Submit our event bus to let architectury register our content on the right time
IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
EventBuses.registerModEventBus(GenerationsCore.MOD_ID, eventBus);
GenerationsCore.init(ModList.get().isLoaded("cobblemon"));
GenerationsCore.init(ModList.get().isLoaded("cobblemon"), FMLPaths.CONFIGDIR.get());
eventBus.addListener(this::onInitialize);
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> GenerationsCoreClientForge.init(eventBus));
}
Expand Down