Search in sources :

Example 1 with ModSortingException

use of net.minecraftforge.fml.common.toposort.ModSortingException in project MinecraftForge by MinecraftForge.

the class FMLClientHandler method beginMinecraftLoading.

/**
     * Called to start the whole game off
     *
     * @param minecraft The minecraft instance being launched
     * @param resourcePackList The resource pack list we will populate with mods
     * @param resourceManager The resource manager
     */
@SuppressWarnings("unchecked")
public void beginMinecraftLoading(Minecraft minecraft, List<IResourcePack> resourcePackList, IReloadableResourceManager resourceManager, MetadataSerializer metaSerializer) {
    detectOptifine();
    SplashProgress.start();
    client = minecraft;
    this.resourcePackList = resourcePackList;
    this.metaSerializer = metaSerializer;
    this.resourcePackMap = Maps.newHashMap();
    if (minecraft.isDemo()) {
        FMLLog.severe("DEMO MODE DETECTED, FML will not work. Finishing now.");
        haltGame("FML will not run in demo mode", new RuntimeException());
        return;
    }
    List<String> injectedModContainers = FMLCommonHandler.instance().beginLoading(this);
    try {
        Loader.instance().loadMods(injectedModContainers);
    } catch (WrongMinecraftVersionException wrong) {
        wrongMC = wrong;
    } catch (DuplicateModsFoundException dupes) {
        dupesFound = dupes;
    } catch (Java8VersionException j8mods) {
        j8onlymods = j8mods;
    } catch (MissingModsException missing) {
        modsMissing = missing;
    } catch (ModSortingException sorting) {
        modSorting = sorting;
    } catch (CustomModLoadingErrorDisplayException custom) {
        FMLLog.log(Level.ERROR, custom, "A custom exception was thrown by a mod, the game will now halt");
        customError = custom;
    } catch (MultipleModsErrored multiple) {
        multipleModsErrored = multiple;
    } catch (LoaderException le) {
        haltGame("There was a severe problem during mod loading that has caused the game to fail", le);
        return;
    } finally {
        client.refreshResources();
    }
    try {
        Loader.instance().preinitializeMods();
    } catch (CustomModLoadingErrorDisplayException custom) {
        FMLLog.log(Level.ERROR, custom, "A custom exception was thrown by a mod, the game will now halt");
        customError = custom;
    } catch (LoaderException le) {
        haltGame("There was a severe problem during mod loading that has caused the game to fail", le);
        return;
    }
    Map<String, Map<String, String>> sharedModList = (Map<String, Map<String, String>>) Launch.blackboard.get("modList");
    if (sharedModList == null) {
        sharedModList = Maps.newHashMap();
        Launch.blackboard.put("modList", sharedModList);
    }
    for (ModContainer mc : Loader.instance().getActiveModList()) {
        Map<String, String> sharedModDescriptor = mc.getSharedModDescriptor();
        if (sharedModDescriptor != null) {
            String sharedModId = "fml:" + mc.getModId();
            sharedModList.put(sharedModId, sharedModDescriptor);
        }
    }
}
Also used : MultipleModsErrored(net.minecraftforge.fml.common.MultipleModsErrored) Java8VersionException(net.minecraftforge.fml.common.Java8VersionException) ForgeModContainer(net.minecraftforge.common.ForgeModContainer) ModContainer(net.minecraftforge.fml.common.ModContainer) DummyModContainer(net.minecraftforge.fml.common.DummyModContainer) DuplicateModsFoundException(net.minecraftforge.fml.common.DuplicateModsFoundException) LoaderException(net.minecraftforge.fml.common.LoaderException) ModSortingException(net.minecraftforge.fml.common.toposort.ModSortingException) WrongMinecraftVersionException(net.minecraftforge.fml.common.WrongMinecraftVersionException) MissingModsException(net.minecraftforge.fml.common.MissingModsException) Map(java.util.Map) BiMap(com.google.common.collect.BiMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashBiMap(com.google.common.collect.HashBiMap)

Example 2 with ModSortingException

use of net.minecraftforge.fml.common.toposort.ModSortingException in project MinecraftForge by MinecraftForge.

the class Loader method sortModList.

/**
     * Sort the mods into a sorted list, using dependency information from the
     * containers. The sorting is performed using a {@link TopologicalSort}
     * based on the pre- and post- dependency information provided by the mods.
     */
private void sortModList() {
    FMLLog.finer("Verifying mod requirements are satisfied");
    List<WrongMinecraftVersionException> wrongMinecraftExceptions = new ArrayList<WrongMinecraftVersionException>();
    List<MissingModsException> missingModsExceptions = new ArrayList<MissingModsException>();
    try {
        BiMap<String, ArtifactVersion> modVersions = HashBiMap.create();
        for (ModContainer mod : Iterables.concat(getActiveModList(), ModAPIManager.INSTANCE.getAPIList())) {
            modVersions.put(mod.getModId(), mod.getProcessedVersion());
        }
        ArrayListMultimap<String, String> reqList = ArrayListMultimap.create();
        for (ModContainer mod : getActiveModList()) {
            if (!mod.acceptableMinecraftVersionRange().containsVersion(minecraft.getProcessedVersion())) {
                FMLLog.severe("The mod %s does not wish to run in Minecraft version %s. You will have to remove it to play.", mod.getModId(), getMCVersionString());
                WrongMinecraftVersionException ret = new WrongMinecraftVersionException(mod, getMCVersionString());
                FMLLog.severe(ret.getMessage());
                wrongMinecraftExceptions.add(ret);
                continue;
            }
            Map<String, ArtifactVersion> names = Maps.uniqueIndex(mod.getRequirements(), new ArtifactVersionNameFunction());
            Set<ArtifactVersion> versionMissingMods = Sets.newHashSet();
            Set<String> missingMods = Sets.difference(names.keySet(), modVersions.keySet());
            if (!missingMods.isEmpty()) {
                FMLLog.severe("The mod %s (%s) requires mods %s to be available", mod.getModId(), mod.getName(), missingMods);
                for (String modid : missingMods) {
                    versionMissingMods.add(names.get(modid));
                }
                MissingModsException ret = new MissingModsException(versionMissingMods, mod.getModId(), mod.getName());
                FMLLog.severe(ret.getMessage());
                missingModsExceptions.add(ret);
                continue;
            }
            reqList.putAll(mod.getModId(), names.keySet());
            ImmutableList<ArtifactVersion> allDeps = ImmutableList.<ArtifactVersion>builder().addAll(mod.getDependants()).addAll(mod.getDependencies()).build();
            for (ArtifactVersion v : allDeps) {
                if (modVersions.containsKey(v.getLabel())) {
                    if (!v.containsVersion(modVersions.get(v.getLabel()))) {
                        versionMissingMods.add(v);
                    }
                }
            }
            if (!versionMissingMods.isEmpty()) {
                FMLLog.severe("The mod %s (%s) requires mod versions %s to be available", mod.getModId(), mod.getName(), versionMissingMods);
                MissingModsException ret = new MissingModsException(versionMissingMods, mod.getModId(), mod.getName());
                FMLLog.severe(ret.toString());
                missingModsExceptions.add(ret);
            }
        }
        if (wrongMinecraftExceptions.isEmpty() && missingModsExceptions.isEmpty()) {
            FMLLog.finer("All mod requirements are satisfied");
        } else if (missingModsExceptions.size() == 1 && wrongMinecraftExceptions.isEmpty()) {
            throw missingModsExceptions.get(0);
        } else if (wrongMinecraftExceptions.size() == 1 && missingModsExceptions.isEmpty()) {
            throw wrongMinecraftExceptions.get(0);
        } else {
            throw new MultipleModsErrored(wrongMinecraftExceptions, missingModsExceptions);
        }
        reverseDependencies = Multimaps.invertFrom(reqList, ArrayListMultimap.<String, String>create());
        ModSorter sorter = new ModSorter(getActiveModList(), namedMods);
        try {
            FMLLog.finer("Sorting mods into an ordered list");
            List<ModContainer> sortedMods = sorter.sort();
            // Reset active list to the sorted list
            modController.getActiveModList().clear();
            modController.getActiveModList().addAll(sortedMods);
            // And inject the sorted list into the overall list
            mods.removeAll(sortedMods);
            sortedMods.addAll(mods);
            mods = sortedMods;
            FMLLog.finer("Mod sorting completed successfully");
        } catch (ModSortingException sortException) {
            FMLLog.severe("A dependency cycle was detected in the input mod set so an ordering cannot be determined");
            SortingExceptionData<ModContainer> exceptionData = sortException.getExceptionData();
            FMLLog.severe("The first mod in the cycle is %s", exceptionData.getFirstBadNode());
            FMLLog.severe("The mod cycle involves");
            for (ModContainer mc : exceptionData.getVisitedNodes()) {
                FMLLog.severe("%s : before: %s, after: %s", mc.toString(), mc.getDependants(), mc.getDependencies());
            }
            FMLLog.log(Level.ERROR, sortException, "The full error");
            throw sortException;
        }
    } finally {
        FMLLog.fine("Mod sorting data");
        int unprintedMods = mods.size();
        for (ModContainer mod : getActiveModList()) {
            if (!mod.isImmutable()) {
                FMLLog.fine("\t%s(%s:%s): %s (%s)", mod.getModId(), mod.getName(), mod.getVersion(), mod.getSource().getName(), mod.getSortingRules());
                unprintedMods--;
            }
        }
        if (unprintedMods == mods.size()) {
            FMLLog.fine("No user mods found to sort");
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ArtifactVersion(net.minecraftforge.fml.common.versioning.ArtifactVersion) SortingExceptionData(net.minecraftforge.fml.common.toposort.ModSortingException.SortingExceptionData) ModSortingException(net.minecraftforge.fml.common.toposort.ModSortingException) ModSorter(net.minecraftforge.fml.common.toposort.ModSorter) ArtifactVersionNameFunction(net.minecraftforge.fml.common.functions.ArtifactVersionNameFunction)

Aggregations

ModSortingException (net.minecraftforge.fml.common.toposort.ModSortingException)2 BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ForgeModContainer (net.minecraftforge.common.ForgeModContainer)1 DummyModContainer (net.minecraftforge.fml.common.DummyModContainer)1 DuplicateModsFoundException (net.minecraftforge.fml.common.DuplicateModsFoundException)1 Java8VersionException (net.minecraftforge.fml.common.Java8VersionException)1 LoaderException (net.minecraftforge.fml.common.LoaderException)1 MissingModsException (net.minecraftforge.fml.common.MissingModsException)1 ModContainer (net.minecraftforge.fml.common.ModContainer)1 MultipleModsErrored (net.minecraftforge.fml.common.MultipleModsErrored)1 WrongMinecraftVersionException (net.minecraftforge.fml.common.WrongMinecraftVersionException)1 ArtifactVersionNameFunction (net.minecraftforge.fml.common.functions.ArtifactVersionNameFunction)1 ModSorter (net.minecraftforge.fml.common.toposort.ModSorter)1 SortingExceptionData (net.minecraftforge.fml.common.toposort.ModSortingException.SortingExceptionData)1 ArtifactVersion (net.minecraftforge.fml.common.versioning.ArtifactVersion)1