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

Re-enable module configuration file #2147

Merged
merged 3 commits into from
Nov 10, 2023
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
4 changes: 2 additions & 2 deletions src/main/java/gregtech/api/modules/GregTechModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
String version() default "";

/**
* A lang key to use for the description of this module in the module configuration file.
* A description of this module in the module configuration file.
*/
String descriptionKey() default "";
String description() default "";
}
3 changes: 2 additions & 1 deletion src/main/java/gregtech/common/ConfigHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import gregtech.api.GregTechAPI;
import net.minecraftforge.common.config.Config;

@Config(modid = GTValues.MODID)
@Config(modid = GTValues.MODID, name = GTValues.MODID + '/' + GTValues.MODID)
public class ConfigHolder {

@Config.Comment("Config options for client-only features")
Expand All @@ -31,6 +31,7 @@ public class ConfigHolder {
@Config.RequiresMcRestart
public static RecipeOptions recipes = new RecipeOptions();

//TODO move to ToolsModule config
@Config.Comment("Config options for Tools and Armor")
@Config.Name("Tool and Armor Options")
@Config.RequiresMcRestart
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/gregtech/core/CoreModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
import gregtech.api.metatileentity.MetaTileEntityUIFactory;
import gregtech.api.modules.GregTechModule;
import gregtech.api.modules.IGregTechModule;
import gregtech.api.pipenet.longdist.LongDistanceNetwork;
import gregtech.api.recipes.ModHandler;
import gregtech.api.pipenet.longdist.LongDistancePipeType;
import gregtech.api.recipes.ModHandler;
import gregtech.api.recipes.RecipeMap;
import gregtech.api.recipes.recipeproperties.TemperatureProperty;
import gregtech.api.unification.OreDictUnifier;
Expand Down Expand Up @@ -76,7 +75,7 @@
moduleID = GregTechModules.MODULE_CORE,
containerID = GTValues.MODID,
name = "GregTech Core",
descriptionKey = "gregtech.modules.core.description",
description = "Core GregTech content. Disabling this disables the entire mod and all its addons.",
coreModule = true
)
public class CoreModule implements IGregTechModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
moduleID = GregTechModules.MODULE_INTEGRATION,
containerID = GTValues.MODID,
name = "GregTech Mod Integration",
descriptionKey = "gregtech.modules.integration.description"
description = "General GregTech Integration Module. Disabling this disables all integration modules."
)
public class IntegrationModule extends BaseGregTechModule {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
containerID = GTValues.MODID,
modDependencies = GTValues.MODID_BAUBLES,
name = "GregTech Baubles Integration",
descriptionKey = "gregtech.modules.baubles_integration.description"
description = "Baubles Integration Module"
)
public class BaublesModule extends IntegrationSubmodule {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
containerID = GTValues.MODID,
modDependencies = GTValues.MODID_CT,
name = "GregTech CraftTweaker Integration",
descriptionKey = "gregtech.modules.ct_integration.description"
description = "CraftTweaker Integration Module"
)
public class CraftTweakerModule extends IntegrationSubmodule {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
containerID = GTValues.MODID,
modDependencies = GTValues.MODID_GROOVYSCRIPT,
name = "GregTech GroovyScript Integration",
descriptionKey = "gregtech.modules.grs_integration.description"
description = "GroovyScript Integration Module"
)
public class GroovyScriptModule extends IntegrationSubmodule {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
containerID = GTValues.MODID,
modDependencies = GTValues.MODID_HWYLA,
name = "GregTech HWYLA Integration",
descriptionKey = "gregtech.modules.hwyla_integration.description"
description = "HWYLA (WAILA) Integration Module"
)
public class HWYLAModule extends IntegrationSubmodule implements IWailaPlugin {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
containerID = GTValues.MODID,
modDependencies = GTValues.MODID_JEI,
name = "GregTech JEI Integration",
descriptionKey = "gregtech.modules.jei_integration.description"
description = "JustEnoughItems Integration Module"
)
public class JustEnoughItemsModule extends IntegrationSubmodule implements IModPlugin {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import gregtech.integration.IntegrationSubmodule;
import gregtech.integration.IntegrationUtil;
import gregtech.integration.opencomputers.drivers.*;
import gregtech.integration.opencomputers.drivers.specific.*;
import gregtech.integration.opencomputers.drivers.specific.DriverConverter;
import gregtech.integration.opencomputers.drivers.specific.DriverFusionReactor;
import gregtech.integration.opencomputers.drivers.specific.DriverPowerSubstation;
import gregtech.integration.opencomputers.drivers.specific.DriverWorldAccelerator;
import gregtech.modules.GregTechModules;
import li.cil.oc.api.Driver;
import li.cil.oc.api.driver.DriverBlock;
Expand All @@ -18,7 +21,7 @@
containerID = GTValues.MODID,
modDependencies = GTValues.MODID_OC,
name = "GregTech OpenComputers Integration",
descriptionKey = "gregtech.modules.oc_integration.description"
description = "OpenComputers Integration Module"
)
public class OpenComputersModule extends IntegrationSubmodule {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
containerID = GTValues.MODID,
modDependencies = GTValues.MODID_TOP,
name = "GregTech TheOneProbe Integration",
descriptionKey = "gregtech.modules.top_integration.description"
description = "TheOneProbe Integration Module"
)
public class TheOneProbeModule extends IntegrationSubmodule {

Expand Down
53 changes: 26 additions & 27 deletions src/main/java/gregtech/modules/ModuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import gregtech.api.GTValues;
import gregtech.api.modules.*;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.discovery.ASMDataTable;
import net.minecraftforge.fml.common.event.*;
Expand All @@ -18,9 +21,9 @@
public class ModuleManager implements IModuleManager {

private static final ModuleManager INSTANCE = new ModuleManager();
//private static final String MODULE_CFG_FILE_NAME = "modules.cfg";
//private static final String MODULE_CFG_CATEGORY_NAME = "modules";
//private static File configFolder;
private static final String MODULE_CFG_FILE_NAME = "modules.cfg";
private static final String MODULE_CFG_CATEGORY_NAME = "modules";
private static File configFolder;

private Map<String, IModuleContainer> containers = new LinkedHashMap<>();
private final Map<ResourceLocation, IGregTechModule> sortedModules = new LinkedHashMap<>();
Expand All @@ -30,7 +33,7 @@ public class ModuleManager implements IModuleManager {

private ModuleStage currentStage = ModuleStage.C_SETUP;
private final Logger logger = LogManager.getLogger("GregTech Module Loader");
//private Configuration config;
private Configuration config;

private ModuleManager() {
}
Expand All @@ -45,11 +48,10 @@ public boolean isModuleEnabled(ResourceLocation id) {
}

public boolean isModuleEnabled(IGregTechModule module) {
return true;
//GregTechModule annotation = module.getClass().getAnnotation(GregTechModule.class);
//String comment = getComment(module);
//Property prop = getConfiguration().get(MODULE_CFG_CATEGORY_NAME, annotation.containerID() + ":" + annotation.moduleID(), true, comment);
//return prop.getBoolean();
GregTechModule annotation = module.getClass().getAnnotation(GregTechModule.class);
String comment = getComment(module);
Property prop = getConfiguration().get(MODULE_CFG_CATEGORY_NAME, annotation.containerID() + ":" + annotation.moduleID(), true, comment);
return prop.getBoolean();
}

@Override
Expand Down Expand Up @@ -87,7 +89,7 @@ public void setup(ASMDataTable asmDataTable, File configDirectory) {
));

currentStage = ModuleStage.M_SETUP;
//configFolder = new File(configDirectory, GTValues.MODID);
configFolder = new File(configDirectory, GTValues.MODID);
Map<String, List<IGregTechModule>> modules = getModules(asmDataTable);
configureModules(modules);

Expand Down Expand Up @@ -211,18 +213,18 @@ public void processIMC(ImmutableList<FMLInterModComms.IMCMessage> messages) {
}

private void configureModules(Map<String, List<IGregTechModule>> modules) {
//Locale locale = Locale.getDefault();
//Locale.setDefault(Locale.ENGLISH);
Locale locale = Locale.getDefault();
Locale.setDefault(Locale.ENGLISH);
Set<ResourceLocation> toLoad = new LinkedHashSet<>();
Set<IGregTechModule> modulesToLoad = new LinkedHashSet<>();
//Configuration config = getConfiguration();
Configuration config = getConfiguration();

for (IModuleContainer container : containers.values()) {
String containerID = container.getID();
List<IGregTechModule> containerModules = modules.get(containerID);
//config.load();
//config.addCustomCategoryComment(MODULE_CFG_CATEGORY_NAME,
// "Module configuration file. Can individually enable/disable modules from GregTech and its addons");
config.load();
config.addCustomCategoryComment(MODULE_CFG_CATEGORY_NAME,
"Module configuration file. Can individually enable/disable modules from GregTech and its addons");
IGregTechModule coreModule = getCoreModule(containerModules);
if (coreModule == null) {
throw new IllegalStateException("Could not find core module for module container " + containerID);
Expand Down Expand Up @@ -286,10 +288,10 @@ private void configureModules(Map<String, List<IGregTechModule>> modules) {

loadedModules.addAll(sortedModules.values());

//if (config.hasChanged()) {
// config.save();
//}
//Locale.setDefault(locale);
if (config.hasChanged()) {
config.save();
}
Locale.setDefault(locale);
}

private static IGregTechModule getCoreModule(List<IGregTechModule> modules) {
Expand Down Expand Up @@ -354,12 +356,10 @@ private void discoverContainers(ASMDataTable table) {
}
}

/*
@SuppressWarnings("deprecation")
private String getComment(IGregTechModule module) {
GregTechModule annotation = module.getClass().getAnnotation(GregTechModule.class);

String comment = I18n.translateToLocal(annotation.descriptionKey());
String comment = annotation.description();
Set<ResourceLocation> dependencies = module.getDependencyUids();
if (!dependencies.isEmpty()) {
Iterator<ResourceLocation> iterator = dependencies.iterator();
Expand All @@ -373,9 +373,9 @@ private String getComment(IGregTechModule module) {
builder.append(" ]");
comment = builder.toString();
}
Set<String> modDependencies = module.getModDependencyIDs();
if (!modDependencies.isEmpty()) {
Iterator<String> iterator = modDependencies.iterator();
String[] modDependencies = annotation.modDependencies();
if (modDependencies != null && modDependencies.length > 0) {
Iterator<String> iterator = Arrays.stream(modDependencies).iterator();
StringBuilder builder = new StringBuilder(comment);
builder.append("\n");
builder.append("Mod Dependencies: [ ");
Expand All @@ -395,5 +395,4 @@ private Configuration getConfiguration() {
}
return config;
}
*/
}
6 changes: 3 additions & 3 deletions src/main/java/gregtech/tools/ToolsModule.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package gregtech.tools;

import gregtech.api.GTValues;
import gregtech.tools.enchants.EnchantmentEnderDamage;
import gregtech.tools.enchants.EnchantmentHardHammer;
import gregtech.api.modules.GregTechModule;
import gregtech.modules.BaseGregTechModule;
import gregtech.modules.GregTechModules;
import gregtech.tools.enchants.EnchantmentEnderDamage;
import gregtech.tools.enchants.EnchantmentHardHammer;
import net.minecraft.enchantment.Enchantment;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
Expand All @@ -20,7 +20,7 @@
moduleID = GregTechModules.MODULE_TOOLS,
containerID = GTValues.MODID,
name = "GregTech Tools",
descriptionKey = "gregtech.modules.tools.description"
description = "GregTech Tools Module. Cannot be disabled for now."
)
public class ToolsModule extends BaseGregTechModule {

Expand Down