Search in sources :

Example 1 with IModFile

use of net.minecraftforge.forgespi.locating.IModFile in project MinecraftForge by MinecraftForge.

the class ModDiscoverer method discoverMods.

public ModValidator discoverMods() {
    LOGGER.debug(LogMarkers.SCAN, "Scanning for mods and other resources to load. We know {} ways to find mods", locatorList.size());
    var loadedFiles = new ArrayList<>();
    for (IModLocator locator : locatorList) {
        LOGGER.debug(LogMarkers.SCAN, "Trying locator {}", locator);
        var modFiles = locator.scanMods();
        for (IModFile mf : modFiles) {
            LOGGER.info(LogMarkers.SCAN, "Found mod file {} of type {} with locator {}", mf.getFileName(), mf.getType(), mf.getLocator());
            StartupMessageManager.modLoaderConsumer().ifPresent(c -> c.accept("Found mod file " + mf.getFileName() + " of type " + mf.getType()));
        }
        loadedFiles.addAll(modFiles);
    }
    final var modFilesMap = loadedFiles.stream().map(ModFile.class::cast).collect(Collectors.groupingBy(IModFile::getType));
    var validator = new ModValidator(modFilesMap);
    validator.stage1Validation();
    return validator;
}
Also used : IModFile(net.minecraftforge.forgespi.locating.IModFile) ArrayList(java.util.ArrayList) IModLocator(net.minecraftforge.forgespi.locating.IModLocator)

Example 2 with IModFile

use of net.minecraftforge.forgespi.locating.IModFile in project MinecraftForge by MinecraftForge.

the class AbstractModLocator method createMod.

protected Optional<IModFile> createMod(Path... path) {
    var mjm = new ModJarMetadata();
    var sj = SecureJar.from(Manifest::new, jar -> jar.findFile(MODS_TOML).isPresent() ? mjm : JarMetadata.from(jar, path), (root, p) -> true, path);
    IModFile mod;
    var type = sj.getManifest().getMainAttributes().getValue(ModFile.TYPE);
    if (sj.findFile(MODS_TOML).isPresent()) {
        LOGGER.debug(LogMarkers.SCAN, "Found {} mod of type {}: {}", MODS_TOML, type, path);
        mod = new ModFile(sj, this, ModFileParser::modsTomlParser);
    } else if (type != null) {
        LOGGER.debug(LogMarkers.SCAN, "Found {} mod of type {}: {}", MANIFEST, type, path);
        mod = new ModFile(sj, this, this::manifestParser);
    } else {
        return Optional.empty();
    }
    mjm.setModFile(mod);
    return Optional.of(mod);
}
Also used : IModFile(net.minecraftforge.forgespi.locating.IModFile) IModFile(net.minecraftforge.forgespi.locating.IModFile) Manifest(java.util.jar.Manifest)

Example 3 with IModFile

use of net.minecraftforge.forgespi.locating.IModFile in project MinecraftForge by MinecraftForge.

the class MinecraftLocator method buildMinecraftTOML.

private IModFileInfo buildMinecraftTOML(final IModFile iModFile) {
    final ModFile modFile = (ModFile) iModFile;
    /*
        final Path mcmodtoml = modFile.findResource("META-INF", "minecraftmod.toml");
        if (Files.notExists(mcmodtoml)) {
            LOGGER.fatal(LOADING, "Mod file {} is missing minecraftmod.toml file", modFile.getFilePath());
            return null;
        }

        final FileConfig mcmodstomlfile = FileConfig.builder(mcmodtoml).build();
        mcmodstomlfile.load();
        mcmodstomlfile.close();
        */
    // We haven't changed this in years, and I can't be asked right now to special case this one file in the path.
    final var conf = Config.inMemory();
    conf.set("modLoader", "minecraft");
    conf.set("loaderVersion", "1");
    conf.set("license", "Mojang Studios, All Rights Reserved");
    final var mods = Config.inMemory();
    mods.set("modId", "minecraft");
    mods.set("version", FMLLoader.versionInfo().mcVersion());
    mods.set("displayName", "Minecraft");
    mods.set("logoFile", "mcplogo.png");
    mods.set("credits", "Mojang, deobfuscated by MCP");
    mods.set("authors", "MCP: Searge,ProfMobius,IngisKahn,Fesh0r,ZeuX,R4wk,LexManos,Bspkrs");
    mods.set("description", "Minecraft, decompiled and deobfuscated with MCP technology");
    conf.set("mods", List.of(mods));
    /*
        conf.putAll(mcmodstomlfile);

        final var extralangs = Stream.<IModFileInfo.LanguageSpec>builder();
        final Path forgemodtoml = modFile.findResource("META-INF", "mods.toml");
        if (Files.notExists(forgemodtoml)) {
            LOGGER.info("No forge mods.toml file found, not loading forge mod");
        } else {
            final FileConfig forgemodstomlfile = FileConfig.builder(forgemodtoml).build();
            forgemodstomlfile.load();
            forgemodstomlfile.close();
            conf.putAll(forgemodstomlfile);
            conf.<List<Object>>get("mods").add(0, mcmodstomlfile.<List<Object>>get("mods").get(0)); // Add MC as a sub-mod
            extralangs.add(new IModFileInfo.LanguageSpec(mcmodstomlfile.get("modLoader"), MavenVersionAdapter.createFromVersionSpec(mcmodstomlfile.get("loaderVersion"))));
        }
        */
    final NightConfigWrapper configWrapper = new NightConfigWrapper(conf);
    // final ModFileInfo modFileInfo = new ModFileInfo(modFile, configWrapper, extralangs.build().toList());
    final ModFileInfo modFileInfo = new ModFileInfo(modFile, configWrapper, List.of());
    configWrapper.setFile(modFileInfo);
    return modFileInfo;
}
Also used : IModFile(net.minecraftforge.forgespi.locating.IModFile) IModFileInfo(net.minecraftforge.forgespi.language.IModFileInfo)

Example 4 with IModFile

use of net.minecraftforge.forgespi.locating.IModFile in project MinecraftForge by MinecraftForge.

the class ModFileParser method modsTomlParser.

public static IModFileInfo modsTomlParser(final IModFile imodFile) {
    ModFile modFile = (ModFile) imodFile;
    LOGGER.debug(LogMarkers.LOADING, "Considering mod file candidate {}", modFile.getFilePath());
    final Path modsjson = modFile.findResource("META-INF", "mods.toml");
    if (!Files.exists(modsjson)) {
        LOGGER.warn(LogMarkers.LOADING, "Mod file {} is missing mods.toml file", modFile.getFilePath());
        return null;
    }
    final FileConfig fileConfig = FileConfig.builder(modsjson).build();
    fileConfig.load();
    fileConfig.close();
    final NightConfigWrapper configWrapper = new NightConfigWrapper(fileConfig);
    final ModFileInfo modFileInfo = new ModFileInfo(modFile, configWrapper);
    configWrapper.setFile(modFileInfo);
    return modFileInfo;
}
Also used : Path(java.nio.file.Path) FileConfig(com.electronwill.nightconfig.core.file.FileConfig) IModFile(net.minecraftforge.forgespi.locating.IModFile) IModFileInfo(net.minecraftforge.forgespi.language.IModFileInfo)

Example 5 with IModFile

use of net.minecraftforge.forgespi.locating.IModFile in project MinecraftForge by MinecraftForge.

the class ClientModLoader method clientPackFinder.

private static void clientPackFinder(Map<IModFile, ? extends PathResourcePack> modResourcePacks, Consumer<Pack> consumer, Pack.PackConstructor factory) {
    List<PathResourcePack> hiddenPacks = new ArrayList<>();
    for (Entry<IModFile, ? extends PathResourcePack> e : modResourcePacks.entrySet()) {
        IModInfo mod = e.getKey().getModInfos().get(0);
        final String name = "mod:" + mod.getModId();
        final Pack packInfo = Pack.create(name, false, e::getValue, factory, Pack.Position.BOTTOM, PackSource.DEFAULT);
        if (packInfo == null) {
            // Vanilla only logs an error, instead of propagating, so handle null and warn that something went wrong
            ModLoader.get().addWarning(new ModLoadingWarning(mod, ModLoadingStage.ERROR, "fml.modloading.brokenresources", e.getKey()));
            continue;
        }
        LOGGER.debug(CORE, "Generating PackInfo named {} for mod file {}", name, e.getKey().getFilePath());
        if (mod.getOwningFile().showAsResourcePack()) {
            consumer.accept(packInfo);
        } else {
            hiddenPacks.add(e.getValue());
        }
    }
    final Pack packInfo = Pack.create("mod_resources", true, () -> new DelegatingResourcePack("mod_resources", "Mod Resources", new PackMetadataSection(new TranslatableComponent("fml.resources.modresources", hiddenPacks.size()), PackType.CLIENT_RESOURCES.getVersion(SharedConstants.getCurrentVersion())), hiddenPacks), factory, Pack.Position.BOTTOM, PackSource.DEFAULT);
    consumer.accept(packInfo);
}
Also used : DelegatingResourcePack(net.minecraftforge.resource.DelegatingResourcePack) IModInfo(net.minecraftforge.forgespi.language.IModInfo) ClientPackSource(net.minecraft.client.resources.ClientPackSource) RepositorySource(net.minecraft.server.packs.repository.RepositorySource) PackType(net.minecraft.server.packs.PackType) File(java.io.File) MinecraftForge(net.minecraftforge.common.MinecraftForge) PackSource(net.minecraft.server.packs.repository.PackSource) IModFile(net.minecraftforge.forgespi.locating.IModFile) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) IModFile(net.minecraftforge.forgespi.locating.IModFile) Pack(net.minecraft.server.packs.repository.Pack) PathResourcePack(net.minecraftforge.resource.PathResourcePack) DelegatingResourcePack(net.minecraftforge.resource.DelegatingResourcePack) PathResourcePack(net.minecraftforge.resource.PathResourcePack) PackMetadataSection(net.minecraft.server.packs.metadata.pack.PackMetadataSection)

Aggregations

IModFile (net.minecraftforge.forgespi.locating.IModFile)6 Pack (net.minecraft.server.packs.repository.Pack)2 PackSource (net.minecraft.server.packs.repository.PackSource)2 RepositorySource (net.minecraft.server.packs.repository.RepositorySource)2 MinecraftForge (net.minecraftforge.common.MinecraftForge)2 IModFileInfo (net.minecraftforge.forgespi.language.IModFileInfo)2 IModInfo (net.minecraftforge.forgespi.language.IModInfo)2 PathResourcePack (net.minecraftforge.resource.PathResourcePack)2 FileConfig (com.electronwill.nightconfig.core.file.FileConfig)1 File (java.io.File)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Manifest (java.util.jar.Manifest)1 ClientPackSource (net.minecraft.client.resources.ClientPackSource)1 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)1 PackType (net.minecraft.server.packs.PackType)1 PackMetadataSection (net.minecraft.server.packs.metadata.pack.PackMetadataSection)1 LevelResource (net.minecraft.world.level.storage.LevelResource)1 ModLoadingStage (net.minecraftforge.fml.ModLoadingStage)1 ModLoadingWarning (net.minecraftforge.fml.ModLoadingWarning)1