Search in sources :

Example 1 with LoaderException

use of net.minecraftforge.fml.common.LoaderException in project MinecraftForge by MinecraftForge.

the class FMLClientHandler method beginMinecraftLoading.

/**
     * Called to start the whole game off
     *
     * @param minecraft The minecraft instance being launched
     * @param resourcePackList The resource pack list we will populate with mods
     * @param resourceManager The resource manager
     */
@SuppressWarnings("unchecked")
public void beginMinecraftLoading(Minecraft minecraft, List<IResourcePack> resourcePackList, IReloadableResourceManager resourceManager, MetadataSerializer metaSerializer) {
    detectOptifine();
    SplashProgress.start();
    client = minecraft;
    this.resourcePackList = resourcePackList;
    this.metaSerializer = metaSerializer;
    this.resourcePackMap = Maps.newHashMap();
    if (minecraft.isDemo()) {
        FMLLog.severe("DEMO MODE DETECTED, FML will not work. Finishing now.");
        haltGame("FML will not run in demo mode", new RuntimeException());
        return;
    }
    List<String> injectedModContainers = FMLCommonHandler.instance().beginLoading(this);
    try {
        Loader.instance().loadMods(injectedModContainers);
    } catch (WrongMinecraftVersionException wrong) {
        wrongMC = wrong;
    } catch (DuplicateModsFoundException dupes) {
        dupesFound = dupes;
    } catch (Java8VersionException j8mods) {
        j8onlymods = j8mods;
    } catch (MissingModsException missing) {
        modsMissing = missing;
    } catch (ModSortingException sorting) {
        modSorting = sorting;
    } catch (CustomModLoadingErrorDisplayException custom) {
        FMLLog.log(Level.ERROR, custom, "A custom exception was thrown by a mod, the game will now halt");
        customError = custom;
    } catch (MultipleModsErrored multiple) {
        multipleModsErrored = multiple;
    } catch (LoaderException le) {
        haltGame("There was a severe problem during mod loading that has caused the game to fail", le);
        return;
    } finally {
        client.refreshResources();
    }
    try {
        Loader.instance().preinitializeMods();
    } catch (CustomModLoadingErrorDisplayException custom) {
        FMLLog.log(Level.ERROR, custom, "A custom exception was thrown by a mod, the game will now halt");
        customError = custom;
    } catch (LoaderException le) {
        haltGame("There was a severe problem during mod loading that has caused the game to fail", le);
        return;
    }
    Map<String, Map<String, String>> sharedModList = (Map<String, Map<String, String>>) Launch.blackboard.get("modList");
    if (sharedModList == null) {
        sharedModList = Maps.newHashMap();
        Launch.blackboard.put("modList", sharedModList);
    }
    for (ModContainer mc : Loader.instance().getActiveModList()) {
        Map<String, String> sharedModDescriptor = mc.getSharedModDescriptor();
        if (sharedModDescriptor != null) {
            String sharedModId = "fml:" + mc.getModId();
            sharedModList.put(sharedModId, sharedModDescriptor);
        }
    }
}
Also used : MultipleModsErrored(net.minecraftforge.fml.common.MultipleModsErrored) Java8VersionException(net.minecraftforge.fml.common.Java8VersionException) ForgeModContainer(net.minecraftforge.common.ForgeModContainer) ModContainer(net.minecraftforge.fml.common.ModContainer) DummyModContainer(net.minecraftforge.fml.common.DummyModContainer) DuplicateModsFoundException(net.minecraftforge.fml.common.DuplicateModsFoundException) LoaderException(net.minecraftforge.fml.common.LoaderException) ModSortingException(net.minecraftforge.fml.common.toposort.ModSortingException) WrongMinecraftVersionException(net.minecraftforge.fml.common.WrongMinecraftVersionException) MissingModsException(net.minecraftforge.fml.common.MissingModsException) Map(java.util.Map) BiMap(com.google.common.collect.BiMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashBiMap(com.google.common.collect.HashBiMap)

Example 2 with LoaderException

use of net.minecraftforge.fml.common.LoaderException in project MinecraftForge by MinecraftForge.

the class DirectoryDiscoverer method exploreFileSystem.

public void exploreFileSystem(String path, File modDir, List<ModContainer> harvestedMods, ModCandidate candidate, @Nullable MetadataCollection mc) {
    if (path.length() == 0) {
        File metadata = new File(modDir, "mcmod.info");
        try {
            FileInputStream fis = new FileInputStream(metadata);
            try {
                mc = MetadataCollection.from(fis, modDir.getName());
            } finally {
                IOUtils.closeQuietly(fis);
            }
            FMLLog.fine("Found an mcmod.info file in directory %s", modDir.getName());
        } catch (Exception e) {
            mc = MetadataCollection.from(null, "");
            FMLLog.fine("No mcmod.info file found in directory %s", modDir.getName());
        }
    }
    File[] content = modDir.listFiles(new ClassFilter());
    // Always sort our content
    Arrays.sort(content);
    for (File file : content) {
        if (file.isDirectory()) {
            FMLLog.finer("Recursing into package %s", path + file.getName());
            exploreFileSystem(path + file.getName() + "/", file, harvestedMods, candidate, mc);
            continue;
        }
        Matcher match = classFile.matcher(file.getName());
        if (match.matches()) {
            ASMModParser modParser = null;
            FileInputStream fis = null;
            try {
                fis = new FileInputStream(file);
                modParser = new ASMModParser(fis);
                candidate.addClassEntry(path + file.getName());
            } catch (LoaderException e) {
                FMLLog.log(Level.ERROR, e, "There was a problem reading the file %s - probably this is a corrupt file", file.getPath());
                throw e;
            } catch (Exception e) {
                throw Throwables.propagate(e);
            } finally {
                IOUtils.closeQuietly(fis);
            }
            modParser.validate();
            modParser.sendToTable(table, candidate);
            ModContainer container = ModContainerFactory.instance().build(modParser, candidate.getModContainer(), candidate);
            if (container != null) {
                harvestedMods.add(container);
                container.bindMetadata(mc);
            }
        }
    }
}
Also used : LoaderException(net.minecraftforge.fml.common.LoaderException) ModContainer(net.minecraftforge.fml.common.ModContainer) Matcher(java.util.regex.Matcher) ASMModParser(net.minecraftforge.fml.common.discovery.asm.ASMModParser) File(java.io.File) FileInputStream(java.io.FileInputStream) LoaderException(net.minecraftforge.fml.common.LoaderException)

Example 3 with LoaderException

use of net.minecraftforge.fml.common.LoaderException in project MinecraftForge by MinecraftForge.

the class FMLClientHandler method finishMinecraftLoading.

/**
     * Called a bit later on during initialization to finish loading mods
     * Also initializes key bindings
     *
     */
public void finishMinecraftLoading() {
    if (modsMissing != null || wrongMC != null || customError != null || dupesFound != null || modSorting != null || j8onlymods != null || multipleModsErrored != null) {
        SplashProgress.finish();
        return;
    }
    try {
        Loader.instance().initializeMods();
    } catch (CustomModLoadingErrorDisplayException custom) {
        FMLLog.log(Level.ERROR, custom, "A custom exception was thrown by a mod, the game will now halt");
        customError = custom;
        SplashProgress.finish();
        return;
    } catch (LoaderException le) {
        haltGame("There was a severe problem during mod loading that has caused the game to fail", le);
        return;
    }
    // Reload resources
    client.refreshResources();
    RenderingRegistry.loadEntityRenderers(Minecraft.getMinecraft().getRenderManager().entityRenderMap);
    guiFactories = HashBiMap.create();
    for (ModContainer mc : Loader.instance().getActiveModList()) {
        String className = mc.getGuiClassName();
        if (Strings.isNullOrEmpty(className)) {
            continue;
        }
        try {
            Class<?> clazz = Class.forName(className, true, Loader.instance().getModClassLoader());
            Class<? extends IModGuiFactory> guiClassFactory = clazz.asSubclass(IModGuiFactory.class);
            IModGuiFactory guiFactory = guiClassFactory.newInstance();
            guiFactory.initialize(client);
            guiFactories.put(mc, guiFactory);
        } catch (Exception e) {
            FMLLog.log(Level.ERROR, e, "A critical error occurred instantiating the gui factory for mod %s", mc.getModId());
        }
    }
    loading = false;
    //Reload options to load any mod added keybindings.
    client.gameSettings.loadOptions();
    Loader.instance().loadingComplete();
    SplashProgress.finish();
}
Also used : LoaderException(net.minecraftforge.fml.common.LoaderException) ForgeModContainer(net.minecraftforge.common.ForgeModContainer) ModContainer(net.minecraftforge.fml.common.ModContainer) DummyModContainer(net.minecraftforge.fml.common.DummyModContainer) WrongMinecraftVersionException(net.minecraftforge.fml.common.WrongMinecraftVersionException) DuplicateModsFoundException(net.minecraftforge.fml.common.DuplicateModsFoundException) LoaderException(net.minecraftforge.fml.common.LoaderException) IOException(java.io.IOException) ModSortingException(net.minecraftforge.fml.common.toposort.ModSortingException) MissingModsException(net.minecraftforge.fml.common.MissingModsException) Java8VersionException(net.minecraftforge.fml.common.Java8VersionException)

Example 4 with LoaderException

use of net.minecraftforge.fml.common.LoaderException in project MinecraftForge by MinecraftForge.

the class ConfigManager method load.

public static void load(String modid, Config.Type type) {
    FMLLog.fine("Attempting to inject @Config classes into %s for type %s", modid, type);
    ClassLoader mcl = Loader.instance().getModClassLoader();
    File configDir = Loader.instance().getConfigDir();
    Multimap<Config.Type, ASMData> map = asm_data.get(modid);
    if (map == null)
        return;
    for (ASMData targ : map.get(type)) {
        try {
            Class<?> cls = Class.forName(targ.getClassName(), true, mcl);
            String name = (String) targ.getAnnotationInfo().get("name");
            if (name == null)
                name = modid;
            String category = (String) targ.getAnnotationInfo().get("category");
            if (category == null)
                category = "general";
            File file = new File(configDir, name + ".cfg");
            Configuration cfg = CONFIGS.get(file.getAbsolutePath());
            if (cfg == null) {
                cfg = new Configuration(file);
                cfg.load();
                CONFIGS.put(file.getAbsolutePath(), cfg);
            }
            createConfig(cfg, cls, modid, type == Config.Type.INSTANCE, category);
            cfg.save();
        } catch (Exception e) {
            FMLLog.log(Level.ERROR, e, "An error occurred trying to load a config for %s into %s", modid, targ.getClassName());
            throw new LoaderException(e);
        }
    }
}
Also used : ASMData(net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) LoaderException(net.minecraftforge.fml.common.LoaderException) File(java.io.File) LoaderException(net.minecraftforge.fml.common.LoaderException)

Example 5 with LoaderException

use of net.minecraftforge.fml.common.LoaderException in project MinecraftForge by MinecraftForge.

the class JarDiscoverer method discover.

@Override
public List<ModContainer> discover(ModCandidate candidate, ASMDataTable table) {
    List<ModContainer> foundMods = Lists.newArrayList();
    FMLLog.fine("Examining file %s for potential mods", candidate.getModContainer().getName());
    JarFile jar = null;
    try {
        jar = new JarFile(candidate.getModContainer());
        ZipEntry modInfo = jar.getEntry("mcmod.info");
        MetadataCollection mc = null;
        if (modInfo != null) {
            FMLLog.finer("Located mcmod.info file in file %s", candidate.getModContainer().getName());
            InputStream inputStream = jar.getInputStream(modInfo);
            try {
                mc = MetadataCollection.from(inputStream, candidate.getModContainer().getName());
            } finally {
                IOUtils.closeQuietly(inputStream);
            }
        } else {
            FMLLog.fine("The mod container %s appears to be missing an mcmod.info file", candidate.getModContainer().getName());
            mc = MetadataCollection.from(null, "");
        }
        for (ZipEntry ze : Collections.list(jar.entries())) {
            if (ze.getName() != null && ze.getName().startsWith("__MACOSX")) {
                continue;
            }
            Matcher match = classFile.matcher(ze.getName());
            if (match.matches()) {
                ASMModParser modParser;
                try {
                    InputStream inputStream = jar.getInputStream(ze);
                    try {
                        modParser = new ASMModParser(inputStream);
                    } finally {
                        IOUtils.closeQuietly(inputStream);
                    }
                    candidate.addClassEntry(ze.getName());
                } catch (LoaderException e) {
                    FMLLog.log(Level.ERROR, e, "There was a problem reading the entry %s in the jar %s - probably a corrupt zip", ze.getName(), candidate.getModContainer().getPath());
                    jar.close();
                    throw e;
                }
                modParser.validate();
                modParser.sendToTable(table, candidate);
                ModContainer container = ModContainerFactory.instance().build(modParser, candidate.getModContainer(), candidate);
                if (container != null) {
                    table.addContainer(container);
                    foundMods.add(container);
                    container.bindMetadata(mc);
                    container.setClassVersion(modParser.getClassVersion());
                }
            }
        }
    } catch (Exception e) {
        FMLLog.log(Level.WARN, e, "Zip file %s failed to read properly, it will be ignored", candidate.getModContainer().getName());
    } finally {
        Java6Utils.closeZipQuietly(jar);
    }
    return foundMods;
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer) LoaderException(net.minecraftforge.fml.common.LoaderException) Matcher(java.util.regex.Matcher) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ASMModParser(net.minecraftforge.fml.common.discovery.asm.ASMModParser) MetadataCollection(net.minecraftforge.fml.common.MetadataCollection) JarFile(java.util.jar.JarFile) LoaderException(net.minecraftforge.fml.common.LoaderException)

Aggregations

LoaderException (net.minecraftforge.fml.common.LoaderException)5 ModContainer (net.minecraftforge.fml.common.ModContainer)4 File (java.io.File)2 Matcher (java.util.regex.Matcher)2 ForgeModContainer (net.minecraftforge.common.ForgeModContainer)2 DummyModContainer (net.minecraftforge.fml.common.DummyModContainer)2 DuplicateModsFoundException (net.minecraftforge.fml.common.DuplicateModsFoundException)2 Java8VersionException (net.minecraftforge.fml.common.Java8VersionException)2 MissingModsException (net.minecraftforge.fml.common.MissingModsException)2 WrongMinecraftVersionException (net.minecraftforge.fml.common.WrongMinecraftVersionException)2 ASMModParser (net.minecraftforge.fml.common.discovery.asm.ASMModParser)2 ModSortingException (net.minecraftforge.fml.common.toposort.ModSortingException)2 BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1