Search in sources :

Example 1 with Disableable

use of net.minecraftforge.fml.common.ModContainer.Disableable in project MinecraftForge by MinecraftForge.

the class GuiModList method updateCache.

private void updateCache() {
    configModButton.visible = false;
    disableModButton.visible = false;
    modInfo = null;
    if (selectedMod == null)
        return;
    ResourceLocation logoPath = null;
    Dimension logoDims = new Dimension(0, 0);
    List<String> lines = new ArrayList<String>();
    CheckResult vercheck = ForgeVersion.getResult(selectedMod);
    String logoFile = selectedMod.getMetadata().logoFile;
    if (!logoFile.isEmpty()) {
        TextureManager tm = mc.getTextureManager();
        IResourcePack pack = FMLClientHandler.instance().getResourcePackFor(selectedMod.getModId());
        try {
            BufferedImage logo = null;
            if (pack != null) {
                logo = pack.getPackImage();
            } else {
                InputStream logoResource = getClass().getResourceAsStream(logoFile);
                if (logoResource != null)
                    logo = ImageIO.read(logoResource);
            }
            if (logo != null) {
                logoPath = tm.getDynamicTextureLocation("modlogo", new DynamicTexture(logo));
                logoDims = new Dimension(logo.getWidth(), logo.getHeight());
            }
        } catch (IOException e) {
        }
    }
    if (!selectedMod.getMetadata().autogenerated) {
        disableModButton.visible = true;
        disableModButton.enabled = true;
        disableModButton.packedFGColour = 0;
        Disableable disableable = selectedMod.canBeDisabled();
        if (disableable == Disableable.RESTART) {
            disableModButton.packedFGColour = 0xFF3377;
        } else if (disableable != Disableable.YES) {
            disableModButton.enabled = false;
        }
        IModGuiFactory guiFactory = FMLClientHandler.instance().getGuiFactoryFor(selectedMod);
        configModButton.visible = true;
        configModButton.enabled = guiFactory != null && guiFactory.mainConfigGuiClass() != null;
        lines.add(selectedMod.getMetadata().name);
        lines.add(String.format("Version: %s (%s)", selectedMod.getDisplayVersion(), selectedMod.getVersion()));
        lines.add(String.format("Mod ID: '%s' Mod State: %s", selectedMod.getModId(), Loader.instance().getModState(selectedMod)));
        if (!selectedMod.getMetadata().credits.isEmpty()) {
            lines.add("Credits: " + selectedMod.getMetadata().credits);
        }
        lines.add("Authors: " + selectedMod.getMetadata().getAuthorList());
        lines.add("URL: " + selectedMod.getMetadata().url);
        if (selectedMod.getMetadata().childMods.isEmpty())
            lines.add("No child mods for this mod");
        else
            lines.add("Child mods: " + selectedMod.getMetadata().getChildModList());
        if (vercheck.status == Status.OUTDATED || vercheck.status == Status.BETA_OUTDATED)
            lines.add("Update Available: " + (vercheck.url == null ? "" : vercheck.url));
        lines.add(null);
        lines.add(selectedMod.getMetadata().description);
    } else {
        lines.add(WHITE + selectedMod.getName());
        lines.add(WHITE + "Version: " + selectedMod.getVersion());
        lines.add(WHITE + "Mod State: " + Loader.instance().getModState(selectedMod));
        if (vercheck.status == Status.OUTDATED || vercheck.status == Status.BETA_OUTDATED)
            lines.add("Update Available: " + (vercheck.url == null ? "" : vercheck.url));
        lines.add(null);
        lines.add(RED + "No mod information found");
        lines.add(RED + "Ask your mod author to provide a mod mcmod.info file");
    }
    if ((vercheck.status == Status.OUTDATED || vercheck.status == Status.BETA_OUTDATED) && vercheck.changes.size() > 0) {
        lines.add(null);
        lines.add("Changes:");
        for (Entry<ComparableVersion, String> entry : vercheck.changes.entrySet()) {
            lines.add("  " + entry.getKey() + ":");
            lines.add(entry.getValue());
            lines.add(null);
        }
    }
    modInfo = new Info(this.width - this.listWidth - 30, lines, logoPath, logoDims);
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) DynamicTexture(net.minecraft.client.renderer.texture.DynamicTexture) Dimension(java.awt.Dimension) TextComponentString(net.minecraft.util.text.TextComponentString) IOException(java.io.IOException) ComparableVersion(net.minecraftforge.fml.common.versioning.ComparableVersion) IResourcePack(net.minecraft.client.resources.IResourcePack) BufferedImage(java.awt.image.BufferedImage) TextureManager(net.minecraft.client.renderer.texture.TextureManager) ResourceLocation(net.minecraft.util.ResourceLocation) CheckResult(net.minecraftforge.common.ForgeVersion.CheckResult) Disableable(net.minecraftforge.fml.common.ModContainer.Disableable)

Example 2 with Disableable

use of net.minecraftforge.fml.common.ModContainer.Disableable in project MinecraftForge by MinecraftForge.

the class Loader method runtimeDisableMod.

public void runtimeDisableMod(String modId) {
    ModContainer mc = namedMods.get(modId);
    Disableable disableable = mc.canBeDisabled();
    if (disableable == Disableable.NEVER) {
        FMLLog.info("Cannot disable mod %s - it is never allowed to be disabled", modId);
        return;
    }
    if (disableable == Disableable.DEPENDENCIES) {
        FMLLog.info("Cannot disable mod %s - there are dependent mods that require its presence", modId);
        return;
    }
    if (disableable == Disableable.YES) {
        FMLLog.info("Runtime disabling mod %s", modId);
        modController.disableMod(mc);
        List<ModContainer> localmods = Lists.newArrayList(mods);
        localmods.remove(mc);
        mods = ImmutableList.copyOf(localmods);
    }
    try {
        Properties props = new Properties();
        props.load(new FileReader(forcedModFile));
        props.put(modId, "false");
        props.store(new FileWriter(forcedModFile), null);
    } catch (Exception e) {
        FMLLog.log(Level.INFO, e, "An error occurred writing the fml mod states file, your disabled change won't persist");
    }
}
Also used : FileWriter(java.io.FileWriter) FileReader(java.io.FileReader) Disableable(net.minecraftforge.fml.common.ModContainer.Disableable) Properties(java.util.Properties) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ModSortingException(net.minecraftforge.fml.common.toposort.ModSortingException)

Aggregations

IOException (java.io.IOException)2 Disableable (net.minecraftforge.fml.common.ModContainer.Disableable)2 Dimension (java.awt.Dimension)1 BufferedImage (java.awt.image.BufferedImage)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 DynamicTexture (net.minecraft.client.renderer.texture.DynamicTexture)1 TextureManager (net.minecraft.client.renderer.texture.TextureManager)1 IResourcePack (net.minecraft.client.resources.IResourcePack)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 CheckResult (net.minecraftforge.common.ForgeVersion.CheckResult)1 ModSortingException (net.minecraftforge.fml.common.toposort.ModSortingException)1 ComparableVersion (net.minecraftforge.fml.common.versioning.ComparableVersion)1