Search in sources :

Example 1 with ModFileInfo

use of net.minecraftforge.fml.loading.moddiscovery.ModFileInfo in project MinecraftForge by MinecraftForge.

the class ModLoader method gatherAndInitializeMods.

/**
 * Run on the primary starting thread by ClientModLoader and ServerModLoader
 * @param syncExecutor An executor to run tasks on the main thread
 * @param parallelExecutor An executor to run tasks on a parallel loading thread pool
 * @param periodicTask Optional periodic task to perform on the main thread while other activities run
 */
public void gatherAndInitializeMods(final ModWorkManager.DrivenExecutor syncExecutor, final Executor parallelExecutor, final Runnable periodicTask) {
    loadingStateValid = true;
    statusConsumer.ifPresent(c -> c.accept("Waiting for scan to complete"));
    FMLLoader.backgroundScanHandler.waitForScanToComplete(periodicTask);
    statusConsumer.ifPresent(c -> c.accept("Loading mods"));
    final ModList modList = ModList.of(loadingModList.getModFiles().stream().map(ModFileInfo::getFile).toList(), loadingModList.getMods());
    if (!this.loadingExceptions.isEmpty()) {
        LOGGER.fatal(CORE, "Error during pre-loading phase", loadingExceptions.get(0));
        modList.setLoadedMods(Collections.emptyList());
        loadingStateValid = false;
        throw new LoadingFailedException(loadingExceptions);
    }
    statusConsumer.ifPresent(c -> c.accept("Building Mod List"));
    final List<ModContainer> modContainers = loadingModList.getModFiles().stream().map(ModFileInfo::getFile).map(this::buildMods).<ModContainer>mapMulti(Iterable::forEach).toList();
    if (!loadingExceptions.isEmpty()) {
        LOGGER.fatal(CORE, "Failed to initialize mod containers", loadingExceptions.get(0));
        modList.setLoadedMods(Collections.emptyList());
        loadingStateValid = false;
        throw new LoadingFailedException(loadingExceptions);
    }
    modList.setLoadedMods(modContainers);
    this.modList = modList;
    statusConsumer.ifPresent(c -> c.accept("Dispatching gathering events"));
    stateManager.getStates(ModLoadingPhase.GATHER).forEach(mls -> dispatchAndHandleError(mls, syncExecutor, parallelExecutor, periodicTask));
    statusConsumer.ifPresent(c -> c.accept("Gathering phase complete"));
}
Also used : ModFileInfo(net.minecraftforge.fml.loading.moddiscovery.ModFileInfo) LoadingModList(net.minecraftforge.fml.loading.LoadingModList)

Example 2 with ModFileInfo

use of net.minecraftforge.fml.loading.moddiscovery.ModFileInfo in project MinecraftForge by MinecraftForge.

the class LoadingModList method findAllURLsForResource.

public Enumeration<URL> findAllURLsForResource(final String resName) {
    final String resourceName;
    // strip a leading slash
    if (resName.startsWith("/")) {
        resourceName = resName.substring(1);
    } else {
        resourceName = resName;
    }
    return new Enumeration<URL>() {

        private final Iterator<ModFileInfo> modFileIterator = modFiles.iterator();

        private URL next;

        @Override
        public boolean hasMoreElements() {
            if (next != null)
                return true;
            next = findNextURL();
            return next != null;
        }

        @Override
        public URL nextElement() {
            if (next == null) {
                next = findNextURL();
                if (next == null)
                    throw new NoSuchElementException();
            }
            URL result = next;
            next = null;
            return result;
        }

        private URL findNextURL() {
            while (modFileIterator.hasNext()) {
                final ModFileInfo next = modFileIterator.next();
                final Path resource = next.getFile().findResource(resourceName);
                if (Files.exists(resource)) {
                    return LamdbaExceptionUtils.uncheck(() -> new URL("modjar://" + next.getMods().get(0).getModId() + "/" + resourceName));
                }
            }
            return null;
        }
    };
}
Also used : Path(java.nio.file.Path) ModFileInfo(net.minecraftforge.fml.loading.moddiscovery.ModFileInfo) URL(java.net.URL)

Example 3 with ModFileInfo

use of net.minecraftforge.fml.loading.moddiscovery.ModFileInfo in project SpongeCommon by SpongePowered.

the class ModFileParsers method generateModFileMetadata.

private static ModFileInfo generateModFileMetadata(final ModFile file, final IConfigurable configurable) throws Exception {
    ModFileParsers.modFileInfoConstructor.setAccessible(true);
    final ModFileInfo modFileInfo = ModFileParsers.modFileInfoConstructor.newInstance(file, configurable);
    ModFileParsers.modFileInfoConstructor.setAccessible(false);
    if (configurable instanceof NightConfigWrapper) {
        ModFileParsers.modFileInfoField.setAccessible(true);
        ModFileParsers.modFileInfoField.set(configurable, modFileInfo);
        ModFileParsers.modFileInfoField.setAccessible(false);
    }
    return modFileInfo;
}
Also used : IModFileInfo(net.minecraftforge.forgespi.language.IModFileInfo) ModFileInfo(net.minecraftforge.fml.loading.moddiscovery.ModFileInfo) NightConfigWrapper(net.minecraftforge.fml.loading.moddiscovery.NightConfigWrapper)

Aggregations

ModFileInfo (net.minecraftforge.fml.loading.moddiscovery.ModFileInfo)3 URL (java.net.URL)1 Path (java.nio.file.Path)1 LoadingModList (net.minecraftforge.fml.loading.LoadingModList)1 NightConfigWrapper (net.minecraftforge.fml.loading.moddiscovery.NightConfigWrapper)1 IModFileInfo (net.minecraftforge.forgespi.language.IModFileInfo)1