Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 1.21 config file #676

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -52,7 +52,7 @@ public static void debug(String message, Level level) {
}

public static ResourceLocation getRL(String resource) {
return new ResourceLocation(MOD_ID, resource);
return ResourceLocation.fromNamespaceAndPath(MOD_ID, resource);
}

public void commonSetup(FMLCommonSetupEvent event) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,53 @@
package de.srendi.advancedperipherals.common.configuration;

import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModLoadingContext;
import net.neoforged.fml.config.ConfigFileTypeHandler;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.config.IConfigSpec;
import net.neoforged.fml.loading.FMLPaths;

import java.nio.file.Path;
import java.util.function.Function;
import java.util.HashMap;
import java.util.Map;

public class APConfig extends ModConfig {
public class APConfig {

public static final ConfigFileHandler CONFIG_FILE_HANDLER = new ConfigFileHandler();
// public static final ConfigFileHandler CONFIG_FILE_HANDLER = new ConfigFileHandler();
diemoell marked this conversation as resolved.
Show resolved Hide resolved
private static final Map<IConfigSpec, IAPConfig> KNOWN_CONFIGS = new HashMap<>();

public static final GeneralConfig GENERAL_CONFIG = new GeneralConfig();
public static final PeripheralsConfig PERIPHERALS_CONFIG = new PeripheralsConfig();
public static final MetaphysicsConfig METAPHYSICS_CONFIG = new MetaphysicsConfig();
public static final WorldConfig WORLD_CONFIG = new WorldConfig();

public APConfig(IAPConfig config, ModContainer container) {
super(config.getType(), config.getConfigSpec(), container, "Advancedperipherals/" + config.getFileName() + ".toml");
public APConfig() {
}

public static void register(ModLoadingContext context) {
//Creates the config folder
FMLPaths.getOrCreateGameRelativePath(FMLPaths.CONFIGDIR.get().resolve("Advancedperipherals"));

ModContainer modContainer = context.getActiveContainer();
modContainer.addConfig(new APConfig(GENERAL_CONFIG, modContainer));
modContainer.addConfig(new APConfig(PERIPHERALS_CONFIG, modContainer));
modContainer.addConfig(new APConfig(METAPHYSICS_CONFIG, modContainer));
modContainer.addConfig(new APConfig(WORLD_CONFIG, modContainer));
APConfigHelper.registerConfig(KNOWN_CONFIGS, modContainer, GENERAL_CONFIG);
APConfigHelper.registerConfig(KNOWN_CONFIGS, modContainer, PERIPHERALS_CONFIG);
APConfigHelper.registerConfig(KNOWN_CONFIGS, modContainer, METAPHYSICS_CONFIG);
APConfigHelper.registerConfig(KNOWN_CONFIGS, modContainer, WORLD_CONFIG);
}

public static class APConfigHelper {
public static String getAPConfigFilePath(IAPConfig config) {
return "Advancedperipherals/" + config.getFileName() + ".toml";
}

public static void registerConfig(Map<IConfigSpec, IAPConfig> knownConfigs, ModContainer modContainer, IAPConfig config) {
modContainer.registerConfig(config.getType(), config.getConfigSpec(), APConfigHelper.getAPConfigFilePath(config));
knownConfigs.put(config.getConfigSpec(), config);
}

/*@Override
diemoell marked this conversation as resolved.
Show resolved Hide resolved
public ConfigFileTypeHandler getHandler() {
return CONFIG_FILE_HANDLER;
}*/

public static class ConfigFileHandler extends ConfigFileTypeHandler {
/*public static class ConfigFileHandler extends ConfigFileTypeHandler {

public static Path getPath(Path path) {
if (path.endsWith("serverconfig"))
Expand All @@ -56,6 +64,6 @@ public Function<ModConfig, CommentedFileConfig> reader(Path configBasePath) {
@Override
public void unload(ModConfig config) {
super.unload(config);
}
}*/
}
}
Loading