Search in sources :

Example 1 with TextureMetadataSection

use of net.minecraft.client.resources.data.TextureMetadataSection in project UtilityClient2 by Utility-Client.

the class SimpleTexture method loadTexture.

public void loadTexture(IResourceManager resourceManager) throws IOException {
    this.deleteGlTexture();
    InputStream inputstream = null;
    try {
        IResource iresource = resourceManager.getResource(this.textureLocation);
        inputstream = iresource.getInputStream();
        BufferedImage bufferedimage = TextureUtil.readBufferedImage(inputstream);
        boolean flag = false;
        boolean flag1 = false;
        if (iresource.hasMetadata()) {
            try {
                TextureMetadataSection texturemetadatasection = (TextureMetadataSection) iresource.getMetadata("texture");
                if (texturemetadatasection != null) {
                    flag = texturemetadatasection.getTextureBlur();
                    flag1 = texturemetadatasection.getTextureClamp();
                }
            } catch (RuntimeException runtimeexception) {
                logger.warn((String) ("Failed reading metadata of: " + this.textureLocation), (Throwable) runtimeexception);
            }
        }
        TextureUtil.uploadTextureImageAllocate(this.getGlTextureId(), bufferedimage, flag, flag1);
    } finally {
        if (inputstream != null) {
            inputstream.close();
        }
    }
}
Also used : InputStream(java.io.InputStream) TextureMetadataSection(net.minecraft.client.resources.data.TextureMetadataSection) IResource(net.minecraft.client.resources.IResource) BufferedImage(java.awt.image.BufferedImage)

Example 2 with TextureMetadataSection

use of net.minecraft.client.resources.data.TextureMetadataSection in project ChocolateQuestRepoured by TeamChocoQuest.

the class AutoGlowingTexture method load.

@Override
public void load(IResourceManager resourceManager) throws IOException {
    this.releaseId();
    try (IResource iresource = resourceManager.getResource(this.originalTexture)) {
        // Needed to get the GL-texture id
        Texture ito = Minecraft.getInstance().textureManager.getTexture(iresource.getLocation());
        NativeImage bufferedimage = NativeImage.read(TextureUtil.readResource(iresource.getInputStream()));
        NativeImage glowingBI = new NativeImage(bufferedimage.getWidth(), bufferedimage.getHeight(), false);
        boolean flag = false;
        boolean flag1 = false;
        // if (iresource.hasMetadata()) {
        try {
            // DONE: Fix this for the CTS!! Cts for whatever reason tries to load png as mcmeta file...
            TextureMetadataSection texturemetadatasection = iresource.getMetadata(new TextureMetadataSectionSerializer());
            if (texturemetadatasection != null) {
                flag = texturemetadatasection.isBlur();
                flag1 = texturemetadatasection.isClamp();
            }
            GlowingMetadataSection glowInformation = iresource.getMetadata(new GlowingMetadataSectionSerializer());
            if (glowInformation != null) {
                for (Tuple<Tuple<Integer, Integer>, Tuple<Integer, Integer>> area : glowInformation.getGlowingSections()) {
                    for (int ix = area.getA().getA(); ix < area.getB().getA(); ix++) {
                        for (int iy = area.getA().getB(); iy < area.getB().getB(); iy++) {
                            glowingBI.setPixelRGBA(ix, iy, bufferedimage.getPixelRGBA(ix, iy));
                            // Remove it from the original
                            bufferedimage.setPixelRGBA(ix, iy, 0);
                        }
                    }
                }
            }
        /*
					 * String name = this.texture.getPath().replace("/", "-");
					 * File outputFile = new File(CQRMain.CQ_CONFIG_FOLDER, name);
					 * ImageIO.write(glowingBI, "png", outputFile);
					 */
        } catch (RuntimeException runtimeexception) {
            LOGGER.warn("Failed reading metadata of: {}", this.originalTexture, runtimeexception);
        }
        // }
        TextureUtil.uploadTextureImageAllocate(this.getId(), glowingBI, flag, flag1);
        // Also upload the changes to the original texture...
        TextureUtil.uploadTextureImage(ito.getId(), bufferedimage);
    }
}
Also used : NativeImage(net.minecraft.client.renderer.texture.NativeImage) GlowingMetadataSection(team.cqr.cqrepoured.client.resources.data.GlowingMetadataSection) TextureMetadataSection(net.minecraft.client.resources.data.TextureMetadataSection) TextureMetadataSectionSerializer(net.minecraft.client.resources.data.TextureMetadataSectionSerializer) GlowingMetadataSectionSerializer(team.cqr.cqrepoured.client.resources.data.GlowingMetadataSectionSerializer) Texture(net.minecraft.client.renderer.texture.Texture) IResource(net.minecraft.resources.IResource) Tuple(net.minecraft.util.Tuple)

Example 3 with TextureMetadataSection

use of net.minecraft.client.resources.data.TextureMetadataSection in project ChocolateQuestRepoured by TeamChocoQuest.

the class InvisibilityTexture method load.

@Override
public void load(IResourceManager resourceManager) throws IOException {
    this.releaseId();
    try (IResource iresource = resourceManager.getResource(this.originalTextureLocation)) {
        NativeImage bufferedimage = NativeImage.read(TextureUtil.readResource(iresource.getInputStream()));
        // CQR Start
        PERLIN.setup(RANDOM.nextLong(), 4.0F);
        for (int x = 0; x < bufferedimage.getWidth(); x++) {
            for (int y = 0; y < bufferedimage.getHeight(); y++) {
                int argb = bufferedimage.getPixelRGBA(x, y);
                if ((argb >>> 24) <= 2) {
                    continue;
                }
                float f = PERLIN.getNoiseAt(x, y);
                bufferedimage.setPixelRGBA(x, y, ((int) (f * 255.0F) << 24) | (argb & 0x00FFFFFF));
            }
        }
        // CQR End
        boolean flag = false;
        boolean flag1 = false;
        // if (iresource.hasMetadata()) {
        try {
            TextureMetadataSection texturemetadatasection = iresource.getMetadata(TextureMetadataSection.SERIALIZER);
            if (texturemetadatasection != null) {
                flag = texturemetadatasection.isBlur();
                flag1 = texturemetadatasection.isClamp();
            }
        } catch (RuntimeException runtimeexception) {
            LOGGER.warn("Failed reading metadata of: {}", this.originalTextureLocation, runtimeexception);
        }
        // }
        TextureUtil.uploadTextureImageAllocate(this.getId(), bufferedimage, flag, flag1);
    }
}
Also used : NativeImage(net.minecraft.client.renderer.texture.NativeImage) TextureMetadataSection(net.minecraft.client.resources.data.TextureMetadataSection) IResource(net.minecraft.resources.IResource)

Example 4 with TextureMetadataSection

use of net.minecraft.client.resources.data.TextureMetadataSection 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)

Example 5 with TextureMetadataSection

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

the class GuiTextureLoader method loadTexture.

@Override
public void loadTexture(IResourceManager resourceManager) throws IOException {
    this.deleteGlTexture();
    IResource iresource = null;
    try {
        iresource = resourceManager.getResource(this.atlasTexture);
        BufferedImage bufferedImage = TextureUtil.readBufferedImage(iresource.getInputStream());
        boolean flag = false;
        boolean flag1 = false;
        if (iresource.hasMetadata()) {
            try {
                TextureMetadataSection texturemetadatasection = iresource.getMetadata("texture");
                if (texturemetadatasection != null) {
                    flag = texturemetadatasection.getTextureBlur();
                    flag1 = texturemetadatasection.getTextureClamp();
                }
            } catch (RuntimeException runtimeexception) {
                ACsGuiApi.log.warn("Failed reading metadata of: {}", this.atlasTexture, runtimeexception);
            }
        }
        TextureUtil.uploadTextureImageAllocate(this.getGlTextureId(), bufferedImage, flag, flag1);
        atlasWidth = bufferedImage.getWidth();
        atlasHeight = bufferedImage.getHeight();
    } catch (Exception e) {
        if (atlasWidth == 0 && atlasHeight == 0) {
            atlasWidth = atlasHeight = 100;
        }
        throw e;
    } finally {
        IOUtils.closeQuietly(iresource);
    }
}
Also used : TextureMetadataSection(net.minecraft.client.resources.data.TextureMetadataSection) IResource(net.minecraft.client.resources.IResource) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException)

Aggregations

TextureMetadataSection (net.minecraft.client.resources.data.TextureMetadataSection)7 BufferedImage (java.awt.image.BufferedImage)4 IResource (net.minecraft.client.resources.IResource)4 NativeImage (net.minecraft.client.renderer.texture.NativeImage)3 IResource (net.minecraft.resources.IResource)3 IOException (java.io.IOException)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)1 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Iterator (java.util.Iterator)1 Callable (java.util.concurrent.Callable)1 StitcherException (net.minecraft.client.renderer.StitcherException)1 SimpleTexture (net.minecraft.client.renderer.texture.SimpleTexture)1 Texture (net.minecraft.client.renderer.texture.Texture)1 AnimationMetadataSection (net.minecraft.client.resources.data.AnimationMetadataSection)1 TextureMetadataSectionSerializer (net.minecraft.client.resources.data.TextureMetadataSectionSerializer)1 CrashReport (net.minecraft.crash.CrashReport)1