Search in sources :

Example 1 with StitcherException

use of net.minecraft.client.renderer.StitcherException in project UtilityClient2 by Utility-Client.

the class TextureMap method loadTextureAtlas.

public void loadTextureAtlas(IResourceManager resourceManager) {
    int i = Minecraft.getGLMaximumTextureSize();
    Stitcher stitcher = new Stitcher(i, i, true, 0, this.mipmapLevels);
    this.mapUploadedSprites.clear();
    this.listAnimatedSprites.clear();
    int j = Integer.MAX_VALUE;
    int k = 1 << this.mipmapLevels;
    for (Entry<String, TextureAtlasSprite> entry : this.mapRegisteredSprites.entrySet()) {
        TextureAtlasSprite textureatlassprite = (TextureAtlasSprite) entry.getValue();
        ResourceLocation resourcelocation = new ResourceLocation(textureatlassprite.getIconName());
        ResourceLocation resourcelocation1 = this.completeResourceLocation(resourcelocation, 0);
        try {
            IResource iresource = resourceManager.getResource(resourcelocation1);
            BufferedImage[] abufferedimage = new BufferedImage[1 + this.mipmapLevels];
            abufferedimage[0] = TextureUtil.readBufferedImage(iresource.getInputStream());
            TextureMetadataSection texturemetadatasection = (TextureMetadataSection) iresource.getMetadata("texture");
            if (texturemetadatasection != null) {
                List<Integer> list = texturemetadatasection.getListMipmaps();
                if (!list.isEmpty()) {
                    int l = abufferedimage[0].getWidth();
                    int i1 = abufferedimage[0].getHeight();
                    if (MathHelper.roundUpToPowerOfTwo(l) != l || MathHelper.roundUpToPowerOfTwo(i1) != i1) {
                        throw new RuntimeException("Unable to load extra miplevels, source-texture is not power of two");
                    }
                }
                Iterator iterator = list.iterator();
                while (iterator.hasNext()) {
                    int i2 = ((Integer) iterator.next()).intValue();
                    if (i2 > 0 && i2 < abufferedimage.length - 1 && abufferedimage[i2] == null) {
                        ResourceLocation resourcelocation2 = this.completeResourceLocation(resourcelocation, i2);
                        try {
                            abufferedimage[i2] = TextureUtil.readBufferedImage(resourceManager.getResource(resourcelocation2).getInputStream());
                        } catch (IOException ioexception) {
                            logger.error("Unable to load miplevel {} from: {}", new Object[] { Integer.valueOf(i2), resourcelocation2, ioexception });
                        }
                    }
                }
            }
            AnimationMetadataSection animationmetadatasection = (AnimationMetadataSection) iresource.getMetadata("animation");
            textureatlassprite.loadSprite(abufferedimage, animationmetadatasection);
        } catch (RuntimeException runtimeexception) {
            logger.error((String) ("Unable to parse metadata from " + resourcelocation1), (Throwable) runtimeexception);
            continue;
        } catch (IOException ioexception1) {
            logger.error((String) ("Using missing texture, unable to load " + resourcelocation1), (Throwable) ioexception1);
            continue;
        }
        j = Math.min(j, Math.min(textureatlassprite.getIconWidth(), textureatlassprite.getIconHeight()));
        int l1 = Math.min(Integer.lowestOneBit(textureatlassprite.getIconWidth()), Integer.lowestOneBit(textureatlassprite.getIconHeight()));
        if (l1 < k) {
            logger.warn("Texture {} with size {}x{} limits mip level from {} to {}", new Object[] { resourcelocation1, Integer.valueOf(textureatlassprite.getIconWidth()), Integer.valueOf(textureatlassprite.getIconHeight()), Integer.valueOf(MathHelper.calculateLogBaseTwo(k)), Integer.valueOf(MathHelper.calculateLogBaseTwo(l1)) });
            k = l1;
        }
        stitcher.addSprite(textureatlassprite);
    }
    int j1 = Math.min(j, k);
    int k1 = MathHelper.calculateLogBaseTwo(j1);
    if (k1 < this.mipmapLevels) {
        logger.warn("{}: dropping miplevel from {} to {}, because of minimum power of two: {}", new Object[] { this.basePath, Integer.valueOf(this.mipmapLevels), Integer.valueOf(k1), Integer.valueOf(j1) });
        this.mipmapLevels = k1;
    }
    for (final TextureAtlasSprite textureatlassprite1 : this.mapRegisteredSprites.values()) {
        try {
            textureatlassprite1.generateMipmaps(this.mipmapLevels);
        } catch (Throwable throwable1) {
            CrashReport crashreport = CrashReport.makeCrashReport(throwable1, "Applying mipmap");
            CrashReportCategory crashreportcategory = crashreport.makeCategory("Sprite being mipmapped");
            crashreportcategory.addCrashSectionCallable("Sprite name", new Callable<String>() {

                public String call() throws Exception {
                    return textureatlassprite1.getIconName();
                }
            });
            crashreportcategory.addCrashSectionCallable("Sprite size", new Callable<String>() {

                public String call() throws Exception {
                    return textureatlassprite1.getIconWidth() + " x " + textureatlassprite1.getIconHeight();
                }
            });
            crashreportcategory.addCrashSectionCallable("Sprite frames", new Callable<String>() {

                public String call() throws Exception {
                    return textureatlassprite1.getFrameCount() + " frames";
                }
            });
            crashreportcategory.addCrashSection("Mipmap levels", Integer.valueOf(this.mipmapLevels));
            throw new ReportedException(crashreport);
        }
    }
    this.missingImage.generateMipmaps(this.mipmapLevels);
    stitcher.addSprite(this.missingImage);
    try {
        stitcher.doStitch();
    } catch (StitcherException stitcherexception) {
        throw stitcherexception;
    }
    logger.info("Created: {}x{} {}-atlas", new Object[] { Integer.valueOf(stitcher.getCurrentWidth()), Integer.valueOf(stitcher.getCurrentHeight()), this.basePath });
    TextureUtil.allocateTextureImpl(this.getGlTextureId(), this.mipmapLevels, stitcher.getCurrentWidth(), stitcher.getCurrentHeight());
    Map<String, TextureAtlasSprite> map = Maps.<String, TextureAtlasSprite>newHashMap(this.mapRegisteredSprites);
    for (TextureAtlasSprite textureatlassprite2 : stitcher.getStichSlots()) {
        String s = textureatlassprite2.getIconName();
        map.remove(s);
        this.mapUploadedSprites.put(s, textureatlassprite2);
        try {
            TextureUtil.uploadTextureMipmap(textureatlassprite2.getFrameTextureData(0), textureatlassprite2.getIconWidth(), textureatlassprite2.getIconHeight(), textureatlassprite2.getOriginX(), textureatlassprite2.getOriginY(), false, false);
        } catch (Throwable throwable) {
            CrashReport crashreport1 = CrashReport.makeCrashReport(throwable, "Stitching texture atlas");
            CrashReportCategory crashreportcategory1 = crashreport1.makeCategory("Texture being stitched together");
            crashreportcategory1.addCrashSection("Atlas path", this.basePath);
            crashreportcategory1.addCrashSection("Sprite", textureatlassprite2);
            throw new ReportedException(crashreport1);
        }
        if (textureatlassprite2.hasAnimationMetadata()) {
            this.listAnimatedSprites.add(textureatlassprite2);
        }
    }
    for (TextureAtlasSprite textureatlassprite3 : map.values()) {
        textureatlassprite3.copyFrom(this.missingImage);
    }
}
Also used : StitcherException(net.minecraft.client.renderer.StitcherException) AnimationMetadataSection(net.minecraft.client.resources.data.AnimationMetadataSection) CrashReport(net.minecraft.crash.CrashReport) TextureMetadataSection(net.minecraft.client.resources.data.TextureMetadataSection) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) Callable(java.util.concurrent.Callable) ResourceLocation(net.minecraft.util.ResourceLocation) Iterator(java.util.Iterator) IResource(net.minecraft.client.resources.IResource) CrashReportCategory(net.minecraft.crash.CrashReportCategory) ReportedException(net.minecraft.util.ReportedException)

Aggregations

BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 Callable (java.util.concurrent.Callable)1 StitcherException (net.minecraft.client.renderer.StitcherException)1 IResource (net.minecraft.client.resources.IResource)1 AnimationMetadataSection (net.minecraft.client.resources.data.AnimationMetadataSection)1 TextureMetadataSection (net.minecraft.client.resources.data.TextureMetadataSection)1 CrashReport (net.minecraft.crash.CrashReport)1 CrashReportCategory (net.minecraft.crash.CrashReportCategory)1 ReportedException (net.minecraft.util.ReportedException)1 ResourceLocation (net.minecraft.util.ResourceLocation)1