Search in sources :

Example 1 with ModIdFunction

use of net.minecraftforge.fml.common.functions.ModIdFunction in project MinecraftForge by MinecraftForge.

the class Loader method setupTestHarness.

/**
     * Used to setup a testharness with a single dummy mod instance for use with various testing hooks
     * @param containers A list of dummy containers that will be returned as "active" for all queries
     */
public void setupTestHarness(ModContainer... containers) {
    modController = new LoadController(this);
    mods = Lists.newArrayList(containers);
    namedMods = Maps.uniqueIndex(mods, new ModIdFunction());
    modController.transition(LoaderState.LOADING, false);
    modController.transition(LoaderState.CONSTRUCTING, false);
    ObjectHolderRegistry.INSTANCE.findObjectHolders(new ASMDataTable());
    modController.forceActiveContainer(containers[0]);
}
Also used : ASMDataTable(net.minecraftforge.fml.common.discovery.ASMDataTable) ModIdFunction(net.minecraftforge.fml.common.functions.ModIdFunction)

Example 2 with ModIdFunction

use of net.minecraftforge.fml.common.functions.ModIdFunction 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)

Example 3 with ModIdFunction

use of net.minecraftforge.fml.common.functions.ModIdFunction in project MinecraftForge by MinecraftForge.

the class ModAPIManager method registerDataTableAndParseAPI.

public void registerDataTableAndParseAPI(ASMDataTable dataTable) {
    this.dataTable = dataTable;
    Set<ASMData> apiList = dataTable.getAll("net.minecraftforge.fml.common.API");
    apiContainers = Maps.newHashMap();
    for (ASMData data : apiList) {
        Map<String, Object> annotationInfo = data.getAnnotationInfo();
        String apiPackage = data.getClassName().substring(0, data.getClassName().indexOf(".package-info"));
        String providedAPI = (String) annotationInfo.get("provides");
        String apiOwner = (String) annotationInfo.get("owner");
        String apiVersion = (String) annotationInfo.get("apiVersion");
        APIContainer container = apiContainers.get(providedAPI);
        if (container == null) {
            container = new APIContainer(providedAPI, apiVersion, data.getCandidate().getModContainer(), VersionParser.parseVersionReference(apiOwner));
            apiContainers.put(providedAPI, container);
        } else {
            container.validate(providedAPI, apiOwner, apiVersion);
        }
        container.addOwnedPackage(apiPackage);
        for (ModContainer mc : data.getCandidate().getContainedMods()) {
            String embeddedIn = mc.getModId();
            if (container.currentReferents.contains(embeddedIn)) {
                continue;
            }
            FMLLog.fine("Found API %s (owned by %s providing %s) embedded in %s", apiPackage, apiOwner, providedAPI, embeddedIn);
            if (!embeddedIn.equals(apiOwner)) {
                container.addAPIReference(embeddedIn);
            }
        }
    }
    for (APIContainer container : apiContainers.values()) {
        for (String pkg : container.packages) {
            Set<ModCandidate> candidates = dataTable.getCandidatesFor(pkg);
            for (ModCandidate candidate : candidates) {
                List<String> candidateIds = Lists.transform(candidate.getContainedMods(), new ModIdFunction());
                if (!candidateIds.contains(container.ownerMod.getLabel()) && !container.currentReferents.containsAll(candidateIds)) {
                    FMLLog.info("Found mod(s) %s containing declared API package %s (owned by %s) without associated API reference", candidateIds, pkg, container.ownerMod);
                    container.addAPIReferences(candidateIds);
                }
            }
        }
        if (apiContainers.containsKey(container.ownerMod.getLabel())) {
            ArtifactVersion owner = container.ownerMod;
            do {
                APIContainer parent = apiContainers.get(owner.getLabel());
                if (parent == container) {
                    FMLLog.finer("APIContainer %s is it's own parent. skipping", owner);
                    container.markSelfReferenced();
                    break;
                }
                FMLLog.finer("Removing upstream parent %s from %s", parent.ownerMod.getLabel(), container);
                container.currentReferents.remove(parent.ownerMod.getLabel());
                container.referredMods.remove(parent.ownerMod);
                owner = parent.ownerMod;
            } while (apiContainers.containsKey(owner.getLabel()));
        }
        FMLLog.fine("Creating API container dummy for API %s: owner: %s, dependents: %s", container.providedAPI, container.ownerMod, container.referredMods);
    }
}
Also used : ASMData(net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData) DefaultArtifactVersion(net.minecraftforge.fml.common.versioning.DefaultArtifactVersion) ArtifactVersion(net.minecraftforge.fml.common.versioning.ArtifactVersion) ModCandidate(net.minecraftforge.fml.common.discovery.ModCandidate) ModIdFunction(net.minecraftforge.fml.common.functions.ModIdFunction)

Aggregations

ModIdFunction (net.minecraftforge.fml.common.functions.ModIdFunction)3 File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 ASMDataTable (net.minecraftforge.fml.common.discovery.ASMDataTable)1 ASMData (net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData)1 ModCandidate (net.minecraftforge.fml.common.discovery.ModCandidate)1 ModDiscoverer (net.minecraftforge.fml.common.discovery.ModDiscoverer)1 ModSortingException (net.minecraftforge.fml.common.toposort.ModSortingException)1 ArtifactVersion (net.minecraftforge.fml.common.versioning.ArtifactVersion)1 DefaultArtifactVersion (net.minecraftforge.fml.common.versioning.DefaultArtifactVersion)1