Search in sources :

Example 1 with Stitcher

use of net.minecraft.client.renderer.texture.Stitcher in project ForestryMC by ForestryMC.

the class TextureMapForestry method loadTextureAtlas.

@Override
public void loadTextureAtlas(IResourceManager resourceManager) {
    int i = Minecraft.getGLMaximumTextureSize();
    Stitcher stitcher = new Stitcher(i, i, 0, 0);
    this.mapUploadedSprites.clear();
    this.listAnimatedSprites.clear();
    ProgressManager.ProgressBar bar = ProgressManager.push("Texture stitching", this.mapRegisteredSprites.size());
    for (Map.Entry<String, TextureAtlasSprite> entry : this.mapRegisteredSprites.entrySet()) {
        TextureAtlasSprite textureatlassprite = entry.getValue();
        ResourceLocation resourcelocation = this.getResourceLocation(textureatlassprite);
        bar.step(resourcelocation.getResourcePath());
        IResource iresource = null;
        if (textureatlassprite.hasCustomLoader(resourceManager, resourcelocation)) {
            if (textureatlassprite.load(resourceManager, resourcelocation, l -> mapRegisteredSprites.get(l.toString()))) {
                continue;
            }
        } else
            try {
                PngSizeInfo pngsizeinfo = PngSizeInfo.makeFromResource(resourceManager.getResource(resourcelocation));
                iresource = resourceManager.getResource(resourcelocation);
                boolean flag = iresource.getMetadata("animation") != null;
                textureatlassprite.loadSprite(pngsizeinfo, flag);
            } catch (RuntimeException runtimeexception) {
                FMLClientHandler.instance().trackBrokenTexture(resourcelocation, runtimeexception.getMessage());
                continue;
            } catch (IOException ioexception) {
                FMLClientHandler.instance().trackMissingTexture(resourcelocation);
                continue;
            } finally {
                IOUtils.closeQuietly(iresource);
            }
        stitcher.addSprite(textureatlassprite);
    }
    ProgressManager.pop(bar);
    this.missingImage.generateMipmaps(0);
    stitcher.addSprite(this.missingImage);
    bar = ProgressManager.push("Texture creation", 2);
    bar.step("Stitching");
    stitcher.doStitch();
    Log.info("Created: {}x{} {}-atlas", stitcher.getCurrentWidth(), stitcher.getCurrentHeight(), this.basePath);
    bar.step("Allocating GL texture");
    TextureUtil.allocateTextureImpl(this.getGlTextureId(), 0, stitcher.getCurrentWidth(), stitcher.getCurrentHeight());
    Map<String, TextureAtlasSprite> map = Maps.newHashMap(this.mapRegisteredSprites);
    ProgressManager.pop(bar);
    bar = ProgressManager.push("Texture mipmap and upload", stitcher.getStichSlots().size());
    for (TextureAtlasSprite textureatlassprite1 : stitcher.getStichSlots()) {
        bar.step(textureatlassprite1.getIconName());
        if (textureatlassprite1 == this.missingImage || this.generateMipmaps(resourceManager, textureatlassprite1)) {
            String s = textureatlassprite1.getIconName();
            map.remove(s);
            this.mapUploadedSprites.put(s, textureatlassprite1);
            try {
                TextureUtil.uploadTextureMipmap(textureatlassprite1.getFrameTextureData(0), textureatlassprite1.getIconWidth(), textureatlassprite1.getIconHeight(), textureatlassprite1.getOriginX(), textureatlassprite1.getOriginY(), false, false);
            } catch (Throwable throwable) {
                CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Stitching texture atlas");
                CrashReportCategory crashreportcategory = crashreport.makeCategory("Texture being stitched together");
                crashreportcategory.addCrashSection("Atlas path", this.basePath);
                crashreportcategory.addCrashSection("Sprite", textureatlassprite1);
                throw new ReportedException(crashreport);
            }
            if (textureatlassprite1.hasAnimationMetadata()) {
                this.listAnimatedSprites.add(textureatlassprite1);
            }
        }
    }
    for (TextureAtlasSprite textureatlassprite2 : map.values()) {
        textureatlassprite2.copyFrom(this.missingImage);
    }
    ProgressManager.pop(bar);
}
Also used : TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) CrashReport(net.minecraft.crash.CrashReport) IOException(java.io.IOException) Stitcher(net.minecraft.client.renderer.texture.Stitcher) ProgressManager(net.minecraftforge.fml.common.ProgressManager) ResourceLocation(net.minecraft.util.ResourceLocation) PngSizeInfo(net.minecraft.client.renderer.texture.PngSizeInfo) TextureMap(net.minecraft.client.renderer.texture.TextureMap) Map(java.util.Map) IResource(net.minecraft.client.resources.IResource) CrashReportCategory(net.minecraft.crash.CrashReportCategory) ReportedException(net.minecraft.util.ReportedException)

Aggregations

IOException (java.io.IOException)1 Map (java.util.Map)1 PngSizeInfo (net.minecraft.client.renderer.texture.PngSizeInfo)1 Stitcher (net.minecraft.client.renderer.texture.Stitcher)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 TextureMap (net.minecraft.client.renderer.texture.TextureMap)1 IResource (net.minecraft.client.resources.IResource)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 ProgressManager (net.minecraftforge.fml.common.ProgressManager)1