use of forestry.api.modules.IModuleContainer 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);
}
use of forestry.api.modules.IModuleContainer in project ForestryMC by ForestryMC.
the class ModuleManager method registerContainers.
@Override
public void registerContainers(IModuleContainer... containers) {
for (IModuleContainer container : containers) {
Preconditions.checkNotNull(container);
moduleContainers.put(container.getID(), container);
}
}
use of forestry.api.modules.IModuleContainer in project Binnie by ForestryMC.
the class BinnieCore method preInit.
@Mod.EventHandler
public void preInit(final FMLPreInitializationEvent evt) {
MinecraftForge.EVENT_BUS.register(Binnie.LIQUID);
MinecraftForge.EVENT_BUS.register(ModuleManager.class);
Binnie.CONFIGURATION.registerConfiguration(ConfigurationMods.class, this);
for (IModuleContainer container : ForestryAPI.moduleManager.getContainers()) {
if (!(container instanceof ModuleContainer)) {
continue;
}
((ModuleContainer) container).setupAPI();
}
for (FluidContainerType container : FluidContainerType.getBinnieContainers()) {
Item item = new ItemFluidContainer(container);
getProxy().registerItem(item);
}
for (CoreErrorCode errorCode : CoreErrorCode.values()) {
ErrorStateRegistry.registerErrorState(errorCode);
}
super.preInit(evt);
}
Aggregations