Search in sources :

Example 1 with ModCandidate

use of io.discloader.discloader.common.discovery.ModCandidate in project DiscLoader by R3alCl0ud.

the class ModRegistry method checkCandidates.

public static CompletableFuture<Void> checkCandidates(List<ModCandidate> mcs) {
    Thread modLoader = new Thread("ModLoader") {

        public void run() {
            ProgressLogger.step(1, 2, "Checking candidates for @Mod annotation");
            logger.info("Checking candidates for @Mod annotation");
            List<ModContainer> containers = new ArrayList<ModContainer>();
            for (int i = 0; i < mcs.size(); i++) {
                activeMod = null;
                ModCandidate candidate = mcs.get(i);
                Class<?> cls = candidate.getModClass();
                ProgressLogger.progress(i + 1, mcs.size(), cls.getName());
                logger.info(cls.getName());
                boolean isMod = cls.isAnnotationPresent(Mod.class);
                if (isMod) {
                    ProgressLogger.progress(i + 1, mcs.size(), String.format("Found @Mod Annotation: %s", cls.getName()));
                    logger.info(String.format("Found @Mod Annotation: %s", cls.getName()));
                    ModContainer mc = new ModContainer(candidate);
                    activeMod = mc;
                    containers.add(mc);
                }
            }
            ProgressLogger.step(2, 2, "Registering uninitialized mods");
            logger.info("Registering uninitialized mods");
            for (int i = 0; i < containers.size(); i++) {
                ModContainer mc = containers.get(i);
                activeMod = mc;
                ProgressLogger.progress(i + 1, containers.size(), mc.modInfo.modid());
                logger.info(mc.modInfo.modid());
                if (preInitMods.containsKey(mc.modInfo.modid())) {
                    logger.severe(String.format("Mod with duplicate id found. \nHALTING STARTUP\nDuplicate ID: %s\n", mc.modInfo.modid()));
                    System.exit(1);
                }
                preInitMods.put(mc.modInfo.modid(), mc);
            }
            activeMod = null;
            ProgressLogger.stage(3, 3, "Registering Mod EventHandlers");
            logger.info("Registering Mod EventHandlers");
            int n = 1;
            for (ModContainer mc : preInitMods.values()) {
                activeMod = mc;
                ProgressLogger.step(n, preInitMods.size(), mc.modInfo.modid());
                logger.info(String.format("Registrying event handlers in: %s", mc.modInfo.modid()));
                mc.discoverHandlers();
                n++;
            }
            activeMod = null;
            ProgressLogger.phase(2, 3, "PreINIT");
            logger.info("PreINIT");
            ProgressLogger.stage(1, 3, "Begin PreINIT");
            logger.info("Begin PreINIT");
            ProgressLogger.stage(2, 3, "Registering Default Language");
            logger.info("Registering Default Language");
            LanguageRegistry.registerLanguage(DLUtil.enUS);
            ProgressLogger.stage(3, 3, "Execute PreINIT");
            logger.info("Execute PreINIT");
            preInit();
        }
    };
    modLoader.start();
    return loaded;
}
Also used : ModContainer(io.discloader.discloader.common.discovery.ModContainer) ArrayList(java.util.ArrayList) ModCandidate(io.discloader.discloader.common.discovery.ModCandidate)

Aggregations

ModCandidate (io.discloader.discloader.common.discovery.ModCandidate)1 ModContainer (io.discloader.discloader.common.discovery.ModContainer)1 ArrayList (java.util.ArrayList)1