use of net.minecraftforge.forgespi.language.IModInfo 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);
}
}
use of net.minecraftforge.forgespi.language.IModInfo in project MinecraftForge by MinecraftForge.
the class CrashReportExtender method dumpModLoadingCrashReport.
public static File dumpModLoadingCrashReport(final Logger logger, final LoadingFailedException error, final File topLevelDir) {
final CrashReport crashReport = CrashReport.forThrowable(new Exception("Mod Loading has failed"), "Mod loading error has occurred");
error.getErrors().forEach(mle -> {
final Optional<IModInfo> modInfo = Optional.ofNullable(mle.getModInfo());
final CrashReportCategory category = crashReport.addCategory(modInfo.map(iModInfo -> "MOD " + iModInfo.getModId()).orElse("NO MOD INFO AVAILABLE"));
Throwable cause = mle.getCause();
int depth = 0;
while (cause != null && cause.getCause() != null && cause.getCause() != cause) {
category.setDetail("Caused by " + (depth++), cause + generateEnhancedStackTrace(cause.getStackTrace()).replaceAll(Strings.LINE_SEPARATOR + "\t", "\n\t\t"));
cause = cause.getCause();
}
if (cause != null)
category.applyStackTrace(cause);
category.setDetail("Mod File", () -> modInfo.map(IModInfo::getOwningFile).map(t -> t.getFile().getFileName()).orElse("NO FILE INFO"));
category.setDetail("Failure message", () -> mle.getCleanMessage().replace("\n", "\n\t\t"));
category.setDetail("Mod Version", () -> modInfo.map(IModInfo::getVersion).map(Object::toString).orElse("NO MOD INFO AVAILABLE"));
category.setDetail("Mod Issue URL", () -> modInfo.map(IModInfo::getOwningFile).map(IModFileInfo.class::cast).flatMap(mfi -> mfi.getConfig().<String>getConfigElement("issueTrackerURL")).orElse("NOT PROVIDED"));
category.setDetail("Exception message", Objects.toString(cause, "MISSING EXCEPTION MESSAGE"));
});
final File file1 = new File(topLevelDir, "crash-reports");
final File file2 = new File(file1, "crash-" + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date()) + "-fml.txt");
if (crashReport.saveToFile(file2)) {
logger.fatal("Crash report saved to {}", file2);
} else {
logger.fatal("Failed to save crash report");
}
System.out.print(crashReport.getFriendlyReport());
return file2;
}
Aggregations