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);
}
}
}
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;
}
}
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;
}
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"));
}
}
Aggregations