Search in sources :

Example 1 with ModDiscoverer

use of net.minecraftforge.fml.common.discovery.ModDiscoverer in project MinecraftForge by MinecraftForge.

the class Loader method identifyMods.

/**
     * The primary loading code
     *
     *
     * The found resources are first loaded into the {@link #modClassLoader}
     * (always) then scanned for class resources matching the specification
     * above.
     *
     * If they provide the {@link Mod} annotation, they will be loaded as
     * "FML mods"
     *
     * Finally, if they are successfully loaded as classes, they are then added
     * to the available mod list.
     */
private ModDiscoverer identifyMods(List<String> additionalContainers) {
    injectedContainers.addAll(additionalContainers);
    FMLLog.fine("Building injected Mod Containers %s", injectedContainers);
    mods.add(minecraft);
    // Add in the MCP mod container
    mods.add(new InjectedModContainer(mcp, new File("minecraft.jar")));
    for (String cont : injectedContainers) {
        ModContainer mc;
        try {
            mc = (ModContainer) Class.forName(cont, true, modClassLoader).newInstance();
        } catch (Exception e) {
            FMLLog.log(Level.ERROR, e, "A problem occurred instantiating the injected mod container %s", cont);
            throw new LoaderException(e);
        }
        mods.add(new InjectedModContainer(mc, mc.getSource()));
    }
    ModDiscoverer discoverer = new ModDiscoverer();
    FMLLog.fine("Attempting to load mods contained in the minecraft jar file and associated classes");
    discoverer.findClasspathMods(modClassLoader);
    FMLLog.fine("Minecraft jar mods loaded successfully");
    FMLLog.getLogger().log(Level.INFO, "Found {} mods from the command line. Injecting into mod discoverer", ModListHelper.additionalMods.size());
    FMLLog.info("Searching %s for mods", canonicalModsDir.getAbsolutePath());
    discoverer.findModDirMods(canonicalModsDir, ModListHelper.additionalMods.values().toArray(new File[0]));
    File versionSpecificModsDir = new File(canonicalModsDir, mccversion);
    if (versionSpecificModsDir.isDirectory()) {
        FMLLog.info("Also searching %s for mods", versionSpecificModsDir);
        discoverer.findModDirMods(versionSpecificModsDir);
    }
    mods.addAll(discoverer.identifyMods());
    identifyDuplicates(mods);
    namedMods = Maps.uniqueIndex(mods, new ModIdFunction());
    FMLLog.info("Forge Mod Loader has identified %d mod%s to load", mods.size(), mods.size() != 1 ? "s" : "");
    return discoverer;
}
Also used : ModDiscoverer(net.minecraftforge.fml.common.discovery.ModDiscoverer) File(java.io.File) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ModSortingException(net.minecraftforge.fml.common.toposort.ModSortingException) ModIdFunction(net.minecraftforge.fml.common.functions.ModIdFunction)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 ModDiscoverer (net.minecraftforge.fml.common.discovery.ModDiscoverer)1 ModIdFunction (net.minecraftforge.fml.common.functions.ModIdFunction)1 ModSortingException (net.minecraftforge.fml.common.toposort.ModSortingException)1