Search in sources :

Example 6 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 7 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 8 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 9 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)

Example 10 with IModFile

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

the class ServerLifecycleHooks method serverPackFinder.

private static void serverPackFinder(Map<IModFile, ? extends PathResourcePack> modResourcePacks, Consumer<Pack> consumer, Pack.PackConstructor factory) {
    for (Entry<IModFile, ? extends PathResourcePack> e : modResourcePacks.entrySet()) {
        IModInfo mod = e.getKey().getModInfos().get(0);
        // skip the minecraft "mod"
        if (Objects.equals(mod.getModId(), "minecraft"))
            continue;
        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());
        consumer.accept(packInfo);
    }
}
Also used : IModInfo(net.minecraftforge.forgespi.language.IModInfo) RepositorySource(net.minecraft.server.packs.repository.RepositorySource) ModLoadingStage(net.minecraftforge.fml.ModLoadingStage) MinecraftForge(net.minecraftforge.common.MinecraftForge) ConnectionType(net.minecraftforge.network.ConnectionType) PackSource(net.minecraft.server.packs.repository.PackSource) IModFile(net.minecraftforge.forgespi.locating.IModFile) LevelResource(net.minecraft.world.level.storage.LevelResource) IModFile(net.minecraftforge.forgespi.locating.IModFile) ModLoadingWarning(net.minecraftforge.fml.ModLoadingWarning) Pack(net.minecraft.server.packs.repository.Pack) PathResourcePack(net.minecraftforge.resource.PathResourcePack)

Aggregations

IModFile (net.minecraftforge.forgespi.locating.IModFile)10 Path (java.nio.file.Path)5 ArrayList (java.util.ArrayList)3 ModFile (net.minecraftforge.fml.loading.moddiscovery.ModFile)3 FileConfig (com.electronwill.nightconfig.core.file.FileConfig)2 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 File (java.io.File)1 Reader (java.io.Reader)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 Manifest (java.util.jar.Manifest)1 ClientPackSource (net.minecraft.client.resources.ClientPackSource)1 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)1