Search in sources :

Example 1 with ModFile

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

the class ModFileParsers method dummySpongeModParser.

public static IModFileInfo dummySpongeModParser(final IModFile realModFile, final String fileName, final IModFile iModFile) {
    final ModFile modFile = (ModFile) iModFile;
    AppLaunch.logger().debug("Considering sponge platform candidate {}", modFile.getFilePath());
    final Path modsjson = modFile.getLocator().findPath(realModFile, fileName + ".toml");
    if (!Files.exists(modsjson)) {
        AppLaunch.logger().warn("Sponge platform file '{}' is missing the '{}' file", modFile, fileName + ".toml");
        return null;
    } else {
        final FileConfig fileConfig = FileConfig.builder(modsjson).build();
        fileConfig.load();
        fileConfig.close();
        final NightConfigWrapper configWrapper = new NightConfigWrapper(fileConfig);
        try {
            return ModFileParsers.generateModFileMetadata(modFile, configWrapper);
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : Path(java.nio.file.Path) FileConfig(com.electronwill.nightconfig.core.file.FileConfig) ModFile(net.minecraftforge.fml.loading.moddiscovery.ModFile) IModFile(net.minecraftforge.forgespi.locating.IModFile) NightConfigWrapper(net.minecraftforge.fml.loading.moddiscovery.NightConfigWrapper)

Example 2 with ModFile

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

the class ModFileParsers method pluginMetadataParser.

public static IModFileInfo pluginMetadataParser(final String fileName, final IModFile iModFile) {
    final ModFile modFile = (ModFile) iModFile;
    AppLaunch.logger().debug("Considering plugin file candidate {}", modFile.getFilePath());
    final Path metadataFile = modFile.getLocator().findPath(modFile, "META-INF/" + fileName + ".json");
    if (Files.notExists(metadataFile)) {
        AppLaunch.logger().debug("Plugin file '{}' is missing a 'sponge_plugins.json' metadata file in META-INF", modFile);
        return null;
    }
    try {
        final MetadataContainer container;
        try (final Reader reader = Files.newBufferedReader(metadataFile, StandardCharsets.UTF_8)) {
            container = MetadataParser.read(reader);
        }
        final PluginFileConfigurable configurable = new PluginFileConfigurable(container);
        return ModFileParsers.generateModFileMetadata(modFile, configurable);
    } catch (final Exception e) {
        AppLaunch.logger().warn("Could not read metadata for plugin file '{}'", modFile, e);
        return null;
    }
}
Also used : Path(java.nio.file.Path) ModFile(net.minecraftforge.fml.loading.moddiscovery.ModFile) IModFile(net.minecraftforge.forgespi.locating.IModFile) MetadataContainer(org.spongepowered.plugin.metadata.builtin.MetadataContainer) PluginFileConfigurable(org.spongepowered.forge.applaunch.loading.metadata.PluginFileConfigurable) Reader(java.io.Reader)

Example 3 with ModFile

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

the class ForgeBootstrap method scanMods.

@Override
public List<IModFile> scanMods() {
    // Add SpongeForge itself back as a Mod since FML dictates that any jars that have locators are *not* mods
    // TODO I think the actual fix here is to ship the locator code as a jar in jar...
    final List<IModFile> jars = new ArrayList<>();
    try {
        final ModFile spongeforge = ModFile.newFMLInstance(Paths.get(ForgeBootstrap.class.getProtectionDomain().getCodeSource().getLocation().toURI()), this);
        this.modJars.compute(spongeforge, (mf, fs) -> this.createFileSystem(mf));
        jars.add(spongeforge);
        final ModFile spongeapi = this.newDummySpongeFile(spongeforge, this, "spongeapimod");
        jars.add(spongeapi);
        this.dummyModFiles.add(spongeapi);
        final ModFile sponge = this.newDummySpongeFile(spongeforge, this, "spongemod");
        jars.add(sponge);
        this.dummyModFiles.add(sponge);
        final IModFile spongeForgeAsLanguageProvider = LanguageLoaderModFileFactory.INSTANCE.build(Paths.get(ForgeBootstrap.class.getProtectionDomain().getCodeSource().getLocation().toURI()), this, LibraryModFileInfoParser.INSTANCE);
        this.modJars.compute(spongeForgeAsLanguageProvider, (mf, fs) -> this.modJars.get(spongeforge));
        jars.add(spongeForgeAsLanguageProvider);
    } catch (final URISyntaxException ex) {
        throw new RuntimeException(ex);
    }
    // Add Sponge-specific libraries
    if (!FMLEnvironment.production) {
        for (final URL url : Java9ClassLoaderUtil.getSystemClassPathURLs()) {
            try {
                final URI uri = url.toURI();
                final Path path = Paths.get(uri);
                if (this.isLibrary(path)) {
                    final IModFile file = LibraryModFileFactory.INSTANCE.build(path, this, LibraryModFileInfoParser.INSTANCE);
                    this.modJars.compute(file, (mf, fs) -> this.createFileSystem(mf));
                    jars.add(file);
                }
            } catch (final Exception ignore) {
            }
        }
    } else {
        try {
            this.libraryManager.validate();
        } catch (final Exception ex) {
            // todo: more specific?
            throw new RuntimeException("Failed to download and validate Sponge libraries", ex);
        }
        this.libraryManager.finishedProcessing();
        for (final LibraryManager.Library library : this.libraryManager.getAll().values()) {
            final Path path = library.getFile();
            ForgeBootstrap.LOGGER.debug("Adding jar {} to classpath as a library", path);
            final IModFile file = LibraryModFileFactory.INSTANCE.build(path, this, LibraryModFileInfoParser.INSTANCE);
            this.modJars.compute(file, (mf, fs) -> this.createFileSystem(mf));
            jars.add(file);
        }
    }
    return jars;
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) ModFile(net.minecraftforge.fml.loading.moddiscovery.ModFile) IModFile(net.minecraftforge.forgespi.locating.IModFile) IModFile(net.minecraftforge.forgespi.locating.IModFile) LibraryManager(org.spongepowered.forge.applaunch.loading.moddiscovery.library.LibraryManager)

Example 4 with ModFile

use of net.minecraftforge.fml.loading.moddiscovery.ModFile in project NetherEx by LogicTechCorp.

the class NetherExBiomes method registerBiomePacks.

public static void registerBiomePacks(MinecraftServer server) {
    ResourcePackList<ResourcePackInfo> resourcePacks = server.getResourcePacks();
    ModFile modFile = ModList.get().getModFileById(NetherEx.MOD_ID).getFile();
    if (NetherExConfig.NETHER.biomePackUseGlobalBiomePacks.get()) {
        Path globalBiomePacksPath = FMLPaths.getOrCreateGameRelativePath(FMLPaths.CONFIGDIR.get().resolve(Paths.get("netherex", "biome_packs")), "netherex biome packs");
        resourcePacks.addPackFinder(new FolderPackFinder(globalBiomePacksPath.toFile()));
    }
    if (NetherExConfig.NETHER.biomePackUseDefaultBiomePack.get()) {
        resourcePacks.addPackFinder(new BuiltinDataPack(modFile, "default_nether_biome_pack"));
    }
    if (NetherExConfig.NETHER.biomePackUseNetherExBiomePack.get()) {
        resourcePacks.addPackFinder(new BuiltinDataPack(modFile, "netherex_nether_biome_pack"));
    }
    if (NetherExConfig.NETHER.biomePackUseBOPBiomePack.get()) {
        resourcePacks.addPackFinder(new BuiltinDataPack(modFile, "bop_nether_biome_pack"));
    }
    if (NetherExConfig.NETHER.biomePackUseENBBiomePack.get()) {
        resourcePacks.addPackFinder(new BuiltinDataPack(modFile, "enb_nether_biome_pack"));
    }
    if (NetherExConfig.NETHER.biomePackUseBYGBiomePack.get()) {
        resourcePacks.addPackFinder(new BuiltinDataPack(modFile, "byg_nether_biome_pack"));
    }
}
Also used : Path(java.nio.file.Path) ModFile(net.minecraftforge.fml.loading.moddiscovery.ModFile) BuiltinDataPack(logictechcorp.libraryex.resource.BuiltinDataPack) ResourcePackInfo(net.minecraft.resources.ResourcePackInfo) FolderPackFinder(net.minecraft.resources.FolderPackFinder)

Aggregations

Path (java.nio.file.Path)4 ModFile (net.minecraftforge.fml.loading.moddiscovery.ModFile)4 IModFile (net.minecraftforge.forgespi.locating.IModFile)3 FileConfig (com.electronwill.nightconfig.core.file.FileConfig)1 Reader (java.io.Reader)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 BuiltinDataPack (logictechcorp.libraryex.resource.BuiltinDataPack)1 FolderPackFinder (net.minecraft.resources.FolderPackFinder)1 ResourcePackInfo (net.minecraft.resources.ResourcePackInfo)1 NightConfigWrapper (net.minecraftforge.fml.loading.moddiscovery.NightConfigWrapper)1 PluginFileConfigurable (org.spongepowered.forge.applaunch.loading.metadata.PluginFileConfigurable)1 LibraryManager (org.spongepowered.forge.applaunch.loading.moddiscovery.library.LibraryManager)1 MetadataContainer (org.spongepowered.plugin.metadata.builtin.MetadataContainer)1