Search in sources :

Example 1 with TextureMetadataSectionSerializer

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

Aggregations

NativeImage (net.minecraft.client.renderer.texture.NativeImage)1 Texture (net.minecraft.client.renderer.texture.Texture)1 TextureMetadataSection (net.minecraft.client.resources.data.TextureMetadataSection)1 TextureMetadataSectionSerializer (net.minecraft.client.resources.data.TextureMetadataSectionSerializer)1 IResource (net.minecraft.resources.IResource)1 Tuple (net.minecraft.util.Tuple)1 GlowingMetadataSection (team.cqr.cqrepoured.client.resources.data.GlowingMetadataSection)1 GlowingMetadataSectionSerializer (team.cqr.cqrepoured.client.resources.data.GlowingMetadataSectionSerializer)1