Search in sources :

Example 1 with ForestryModule

use of forestry.api.modules.ForestryModule in project ForestryMC by ForestryMC.

the class ForestryModules method isModuleEnabled.

@Override
public boolean isModuleEnabled(IForestryModule module) {
    ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
    String comment = ForestryPluginUtil.getComment(module);
    Property prop = getModulesConfig().get(CONFIG_CATEGORY, info.moduleID(), true, comment);
    return prop.getBoolean();
}
Also used : ForestryModule(forestry.api.modules.ForestryModule) IForestryModule(forestry.api.modules.IForestryModule) Property(net.minecraftforge.common.config.Property)

Example 2 with ForestryModule

use of forestry.api.modules.ForestryModule in project ForestryMC by ForestryMC.

the class ForestryPluginUtil method getForestryModules.

public static Map<String, List<IForestryModule>> getForestryModules(ASMDataTable asmDataTable) {
    List<IForestryModule> instances = getInstances(asmDataTable, ForestryModule.class, IForestryModule.class);
    Map<String, List<IForestryModule>> modules = new LinkedHashMap<>();
    for (IForestryModule module : instances) {
        ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
        modules.computeIfAbsent(info.containerID(), k -> new ArrayList<>()).add(module);
    }
    return modules;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) ForestryModule(forestry.api.modules.ForestryModule) Iterator(java.util.Iterator) Map(java.util.Map) ResourceLocation(net.minecraft.util.ResourceLocation) Set(java.util.Set) Log(forestry.core.utils.Log) IForestryModule(forestry.api.modules.IForestryModule) ArrayList(java.util.ArrayList) I18n(net.minecraft.util.text.translation.I18n) ASMDataTable(net.minecraftforge.fml.common.discovery.ASMDataTable) ForestryModule(forestry.api.modules.ForestryModule) IForestryModule(forestry.api.modules.IForestryModule) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) IForestryModule(forestry.api.modules.IForestryModule) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with ForestryModule

use of forestry.api.modules.ForestryModule in project ForestryMC by ForestryMC.

the class ModuleManager method configureModules.

private static void configureModules(Map<String, List<IForestryModule>> modules) {
    Locale locale = Locale.getDefault();
    Locale.setDefault(Locale.ENGLISH);
    Set<ResourceLocation> toLoad = new HashSet<>();
    Set<IForestryModule> modulesToLoad = new HashSet<>();
    ImmutableList<IForestryModule> allModules = ImmutableList.copyOf(modules.values().stream().flatMap(Collection::stream).collect(Collectors.toList()));
    for (IModuleContainer container : moduleContainers.values()) {
        String containerID = container.getID();
        List<IForestryModule> containerModules = modules.get(containerID);
        Configuration config = container.getModulesConfig();
        config.load();
        config.addCustomCategoryComment(CONFIG_CATEGORY, "Disabling these modules can greatly change how the mod functions.\n" + "Your mileage may vary, please report any issues.");
        IForestryModule coreModule = getModuleCore(containerModules);
        if (coreModule != null) {
            containerModules.remove(coreModule);
            containerModules.add(0, coreModule);
        } else {
            Log.debug("Could not find core module for the module container: {}", containerID);
        }
        Iterator<IForestryModule> iterator = containerModules.iterator();
        while (iterator.hasNext()) {
            IForestryModule module = iterator.next();
            if (!container.isAvailable()) {
                iterator.remove();
                Log.info("Module disabled: {}", module);
                continue;
            }
            if (module.canBeDisabled()) {
                if (!container.isModuleEnabled(module)) {
                    configDisabledModules.add(module);
                    iterator.remove();
                    Log.info("Module disabled: {}", module);
                    continue;
                }
                if (!module.isAvailable()) {
                    iterator.remove();
                    Log.info("Module {} failed to load: {}", module, module.getFailMessage());
                    continue;
                }
            }
            ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
            toLoad.add(new ResourceLocation(containerID, info.moduleID()));
            modulesToLoad.add(module);
        }
    }
    // Check Dependencies
    Iterator<IForestryModule> iterator;
    boolean changed;
    do {
        changed = false;
        iterator = modulesToLoad.iterator();
        while (iterator.hasNext()) {
            IForestryModule module = iterator.next();
            Set<ResourceLocation> dependencies = module.getDependencyUids();
            if (!toLoad.containsAll(dependencies)) {
                iterator.remove();
                changed = true;
                ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
                String moduleId = info.moduleID();
                toLoad.remove(new ResourceLocation(moduleId));
                Log.warning("Module {} is missing dependencies: {}", moduleId, dependencies);
            }
        }
    } while (changed);
    // Sort Modules
    do {
        changed = false;
        iterator = modulesToLoad.iterator();
        while (iterator.hasNext()) {
            IForestryModule module = iterator.next();
            if (sortedModules.keySet().containsAll(module.getDependencyUids())) {
                iterator.remove();
                ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
                sortedModules.put(new ResourceLocation(info.containerID(), info.moduleID()), module);
                changed = true;
                break;
            }
        }
    } while (changed);
    for (IModuleContainer container : moduleContainers.values()) {
        Configuration config = container.getModulesConfig();
        if (config.hasChanged()) {
            config.save();
        }
    }
    loadedModules.addAll(sortedModules.values());
    unloadedModules.addAll(allModules);
    unloadedModules.removeAll(sortedModules.values());
    for (IModuleContainer container : moduleContainers.values()) {
        Collection<IForestryModule> loadedModules = sortedModules.values().stream().filter(m -> {
            ForestryModule info = m.getClass().getAnnotation(ForestryModule.class);
            return info.containerID().equals(container.getID());
        }).collect(Collectors.toList());
        Collection<IForestryModule> unloadedModules = ModuleManager.unloadedModules.stream().filter(m -> {
            ForestryModule info = m.getClass().getAnnotation(ForestryModule.class);
            return info.containerID().equals(container.getID());
        }).collect(Collectors.toList());
        container.onConfiguredModules(loadedModules, unloadedModules);
    }
    ForestryAPI.enabledModules = new HashSet<>();
    ForestryAPI.enabledPlugins = new HashSet<>();
    for (IForestryModule module : sortedModules.values()) {
        ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
        ForestryAPI.enabledModules.add(new ResourceLocation(info.containerID(), info.moduleID()));
        if (module instanceof BlankForestryModule) {
            ForestryAPI.enabledPlugins.add(info.containerID() + "." + info.moduleID());
        }
    }
    Locale.setDefault(locale);
}
Also used : Locale(java.util.Locale) CommandHandler(net.minecraft.command.CommandHandler) ForestryModule(forestry.api.modules.ForestryModule) IResupplyHandler(forestry.core.IResupplyHandler) HashMap(java.util.HashMap) Log(forestry.core.utils.Log) IForestryModule(forestry.api.modules.IForestryModule) ArrayList(java.util.ArrayList) ASMDataTable(net.minecraftforge.fml.common.discovery.ASMDataTable) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) MinecraftServer(net.minecraft.server.MinecraftServer) Lists(com.google.common.collect.Lists) IModuleManager(forestry.api.modules.IModuleManager) ImmutableList(com.google.common.collect.ImmutableList) ISaveEventHandler(forestry.core.ISaveEventHandler) Locale(java.util.Locale) Map(java.util.Map) FMLPreInitializationEvent(net.minecraftforge.fml.common.event.FMLPreInitializationEvent) Nullable(javax.annotation.Nullable) LinkedHashSet(java.util.LinkedHashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Iterator(java.util.Iterator) Collection(java.util.Collection) Set(java.util.Set) IPickupHandler(forestry.core.IPickupHandler) Collectors(java.util.stream.Collectors) ICommand(net.minecraft.command.ICommand) IModuleContainer(forestry.api.modules.IModuleContainer) List(java.util.List) ForestryAPI(forestry.api.core.ForestryAPI) ResourceLocation(net.minecraft.util.ResourceLocation) Preconditions(com.google.common.base.Preconditions) Configuration(net.minecraftforge.common.config.Configuration) ForestryModule(forestry.api.modules.ForestryModule) IForestryModule(forestry.api.modules.IForestryModule) Configuration(net.minecraftforge.common.config.Configuration) IModuleContainer(forestry.api.modules.IModuleContainer) ResourceLocation(net.minecraft.util.ResourceLocation) Collection(java.util.Collection) IForestryModule(forestry.api.modules.IForestryModule) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 4 with ForestryModule

use of forestry.api.modules.ForestryModule in project ForestryMC by ForestryMC.

the class ForestryCompatPlugins method isModuleEnabled.

@Override
public boolean isModuleEnabled(IForestryModule module) {
    ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
    String comment = ForestryPluginUtil.getComment(module);
    Property prop = getModulesConfig().get(CONFIG_CATEGORY, info.moduleID(), true, comment);
    return prop.getBoolean();
}
Also used : ForestryModule(forestry.api.modules.ForestryModule) IForestryModule(forestry.api.modules.IForestryModule) Property(net.minecraftforge.common.config.Property)

Example 5 with ForestryModule

use of forestry.api.modules.ForestryModule in project ForestryMC by ForestryMC.

the class CommandModules method makeListEntry.

private static String makeListEntry(IForestryModule module) {
    String entry = module.isAvailable() ? TextFormatting.GREEN.toString() : TextFormatting.RED.toString();
    ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
    if (info != null) {
        entry += info.moduleID();
        if (!info.version().isEmpty()) {
            entry += " (" + info.version() + ")";
        }
    } else {
        entry += "???";
    }
    return entry;
}
Also used : ForestryModule(forestry.api.modules.ForestryModule) IForestryModule(forestry.api.modules.IForestryModule)

Aggregations

ForestryModule (forestry.api.modules.ForestryModule)9 IForestryModule (forestry.api.modules.IForestryModule)9 ArrayList (java.util.ArrayList)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 Property (net.minecraftforge.common.config.Property)3 Log (forestry.core.utils.Log)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 ASMDataTable (net.minecraftforge.fml.common.discovery.ASMDataTable)2 Preconditions (com.google.common.base.Preconditions)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 ForestryAPI (forestry.api.core.ForestryAPI)1 IModuleContainer (forestry.api.modules.IModuleContainer)1