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