Search in sources :

Example 6 with IModInfo

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

Example 7 with IModInfo

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;
}
Also used : IModInfo(net.minecraftforge.forgespi.language.IModInfo) CrashReport(net.minecraft.CrashReport) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) LoadingFailedException(net.minecraftforge.fml.LoadingFailedException) CrashReportCategory(net.minecraft.CrashReportCategory)

Aggregations

IModInfo (net.minecraftforge.forgespi.language.IModInfo)7 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)3 PathResourcePack (net.minecraftforge.resource.PathResourcePack)3 NativeImage (com.mojang.blaze3d.platform.NativeImage)2 RenderSystem (com.mojang.blaze3d.systems.RenderSystem)2 PoseStack (com.mojang.blaze3d.vertex.PoseStack)2 Tesselator (com.mojang.blaze3d.vertex.Tesselator)2 File (java.io.File)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 Entry (java.util.Map.Entry)2 Consumer (java.util.function.Consumer)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 Util (net.minecraft.Util)2 Pack (net.minecraft.server.packs.repository.Pack)2