Search in sources :

Example 21 with IResourcePack

use of net.minecraft.client.resources.IResourcePack in project MinecraftForge by MinecraftForge.

the class FMLClientHandler method addModAsResource.

@Override
public void addModAsResource(ModContainer container) {
    Class<?> resourcePackType = container.getCustomResourcePackClass();
    if (resourcePackType != null) {
        try {
            IResourcePack pack = (IResourcePack) resourcePackType.getConstructor(ModContainer.class).newInstance(container);
            PackMetadataSection meta = (PackMetadataSection) pack.getPackMetadata(this.metaSerializer, "pack");
            if (meta != null && meta.getPackFormat() == 2) {
                pack = new LegacyV2Adapter(pack);
            }
            resourcePackList.add(pack);
            resourcePackMap.put(container.getModId(), pack);
        } catch (NoSuchMethodException e) {
            FMLLog.log(Level.ERROR, "The container %s (type %s) returned an invalid class for it's resource pack.", container.getName(), container.getClass().getName());
            return;
        } catch (Exception e) {
            FMLLog.log(Level.ERROR, e, "An unexpected exception occurred constructing the custom resource pack for %s", container.getName());
            throw Throwables.propagate(e);
        }
    }
}
Also used : LegacyV2Adapter(net.minecraft.client.resources.LegacyV2Adapter) IResourcePack(net.minecraft.client.resources.IResourcePack) 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) PackMetadataSection(net.minecraft.client.resources.data.PackMetadataSection)

Example 22 with IResourcePack

use of net.minecraft.client.resources.IResourcePack 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 23 with IResourcePack

use of net.minecraft.client.resources.IResourcePack in project ct.js by ChatTriggers.

the class CTJS method injectResourcePack.

private void injectResourcePack(String path) {
    try {
        File pictures = new File(path, "ChatTriggers/images/");
        Field field = FMLClientHandler.class.getDeclaredField("resourcePackList");
        field.setAccessible(true);
        List<IResourcePack> packs = (List<IResourcePack>) field.get(FMLClientHandler.instance());
        imagesPack = new ImagesPack(pictures);
        packs.add(imagesPack);
        pictures.mkdirs();
        assetsDir = pictures;
    } catch (Exception exception) {
        exception.printStackTrace();
    }
}
Also used : Field(java.lang.reflect.Field) List(java.util.List) File(java.io.File) IResourcePack(net.minecraft.client.resources.IResourcePack) ImagesPack(com.chattriggers.ctjs.utils.ImagesPack) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 24 with IResourcePack

use of net.minecraft.client.resources.IResourcePack in project BiomesOPlenty by Glitchfiend.

the class ClientProxy method replaceForgeResources.

private static void replaceForgeResources() {
    if (MiscConfigurationHandler.overrideForgeBuckets) {
        FMLClientHandler clientHandler = FMLClientHandler.instance();
        List<IResourcePack> resourcePackList = ReflectionHelper.getPrivateValue(FMLClientHandler.class, clientHandler, "resourcePackList");
        Map<String, IResourcePack> resourcePackMap = ReflectionHelper.getPrivateValue(FMLClientHandler.class, clientHandler, "resourcePackMap");
        LegacyV2Adapter resourcePack = (LegacyV2Adapter) clientHandler.getResourcePackFor("forge");
        // Remove the old resource pack from the registry
        resourcePackList.remove(resourcePack);
        resourcePackMap.remove("forge");
        // Replace Forge's resource pack with our modified version
        ForgeRedirectedResourcePack redirectedResourcePack = new ForgeRedirectedResourcePack(FMLCommonHandler.instance().findContainerFor("forge"));
        // Add our new resource pack in its place
        resourcePackList.add(redirectedResourcePack);
        resourcePackMap.put("forge", redirectedResourcePack);
    }
}
Also used : ForgeRedirectedResourcePack(biomesoplenty.client.texture.ForgeRedirectedResourcePack) FMLClientHandler(net.minecraftforge.fml.client.FMLClientHandler) LegacyV2Adapter(net.minecraft.client.resources.LegacyV2Adapter) IResourcePack(net.minecraft.client.resources.IResourcePack)

Example 25 with IResourcePack

use of net.minecraft.client.resources.IResourcePack in project ACsGuis by AymericBdy.

the class ACsGuisCssParser method getResource.

/**
 * Helper method to create an input stream for a ResourceLocation, usable by the css parser
 */
public static InputStream getResource(ResourceLocation location) throws IOException, IllegalAccessException {
    List<IResourcePack> list = new ArrayList<>();
    list.addAll((Collection<? extends IResourcePack>) ReflectionHelper.findField(FMLClientHandler.class, "resourcePackList").get(FMLClientHandler.instance()));
    for (ResourcePackRepository.Entry resourcepackrepository$entry : Minecraft.getMinecraft().getResourcePackRepository().getRepositoryEntries()) {
        if (resourcepackrepository$entry.getResourcePack().getResourceDomains().contains(location.getNamespace()))
            list.add(resourcepackrepository$entry.getResourcePack());
    }
    if (Minecraft.getMinecraft().getResourcePackRepository().getServerResourcePack() != null && Minecraft.getMinecraft().getResourcePackRepository().getServerResourcePack().getResourceDomains().contains(location.getNamespace())) {
        list.add(Minecraft.getMinecraft().getResourcePackRepository().getServerResourcePack());
    }
    for (int i = list.size() - 1; i >= 0; --i) {
        IResourcePack iresourcepack1 = list.get(i);
        if (iresourcepack1.resourceExists(location)) {
            return iresourcepack1.getInputStream(location);
        }
    }
    throw new FileNotFoundException(location.toString());
}
Also used : ResourcePackRepository(net.minecraft.client.resources.ResourcePackRepository) FileNotFoundException(java.io.FileNotFoundException) FMLClientHandler(net.minecraftforge.fml.client.FMLClientHandler) IResourcePack(net.minecraft.client.resources.IResourcePack)

Aggregations

IResourcePack (net.minecraft.client.resources.IResourcePack)36 IOException (java.io.IOException)13 File (java.io.File)12 InputStream (java.io.InputStream)10 List (java.util.List)10 ArrayList (java.util.ArrayList)8 ResourceLocation (net.minecraft.util.ResourceLocation)7 ResourcePackRepository (net.minecraft.client.resources.ResourcePackRepository)6 Field (java.lang.reflect.Field)5 AbstractResourcePack (net.minecraft.client.resources.AbstractResourcePack)4 IResourceManager (net.minecraft.client.resources.IResourceManager)4 LegacyV2Adapter (net.minecraft.client.resources.LegacyV2Adapter)4 FileNotFoundException (java.io.FileNotFoundException)3 Set (java.util.Set)3 FallbackResourceManager (net.minecraft.client.resources.FallbackResourceManager)3 FMLClientHandler (net.minecraftforge.fml.client.FMLClientHandler)3 Dimension (java.awt.Dimension)2 BufferedImage (java.awt.image.BufferedImage)2 FileInputStream (java.io.FileInputStream)2 Map (java.util.Map)2