Search in sources :

Example 1 with NativeImage

use of net.minecraft.client.renderer.texture.NativeImage 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 2 with NativeImage

use of net.minecraft.client.renderer.texture.NativeImage in project RGBBlocks by PlatinPython.

the class RGBBlocksPack method generateImage.

public Optional<Pair<NativeImage, Optional<Callable<InputStream>>>> generateImage(ResourceLocation modLocation, ResourceLocation vanillaLocation, IResourceManager manager) {
    ResourceLocation parentFile = makeTextureID(vanillaLocation);
    try (InputStream inputStream = manager.getResource(parentFile).getInputStream()) {
        NativeImage image = NativeImage.read(inputStream);
        NativeImage transformedImage = this.transformImage(image);
        ResourceLocation metadata = getMetadataLocation(parentFile);
        Optional<Callable<InputStream>> metadataLookup = Optional.empty();
        if (manager.hasResource(metadata)) {
            BufferedReader bufferedReader = null;
            JsonObject metadataJson = null;
            try (InputStream metadataStream = manager.getResource(metadata).getInputStream()) {
                bufferedReader = new BufferedReader(new InputStreamReader(metadataStream, StandardCharsets.UTF_8));
                metadataJson = JSONUtils.parse(bufferedReader);
            } finally {
                IOUtils.closeQuietly(bufferedReader);
            }
            if (metadataJson != null) {
                JsonObject metaDataJsonForLambda = metadataJson;
                metadataLookup = Optional.of(() -> new ByteArrayInputStream(metaDataJsonForLambda.toString().getBytes()));
            }
        }
        return Optional.of(Pair.of(transformedImage, metadataLookup));
    } catch (IOException e) {
        e.printStackTrace();
        return Optional.empty();
    }
}
Also used : NativeImage(net.minecraft.client.renderer.texture.NativeImage) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ResourceLocation(net.minecraft.util.ResourceLocation) BufferedReader(java.io.BufferedReader) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) Callable(java.util.concurrent.Callable)

Example 3 with NativeImage

use of net.minecraft.client.renderer.texture.NativeImage 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 NativeImage

use of net.minecraft.client.renderer.texture.NativeImage in project ChocolateQuestRepoured by TeamChocoQuest.

the class CubemapTexture method load.

private void load(IResourceManager resourceManager, ResourceLocation location, int target) throws IOException {
    try (IResource iresource = resourceManager.getResource(location)) {
        NativeImage bufferedimage = NativeImage.read(TextureUtil.readResource(iresource.getInputStream()));
        int w = bufferedimage.getWidth();
        int h = bufferedimage.getHeight();
        IntBuffer data = ByteBuffer.allocateDirect(w * h * 4).order(ByteOrder.nativeOrder()).asIntBuffer();
        data.put(bufferedimage.getRGB(0, 0, w, h, new int[w * h], 0, w));
        data.flip();
        GL11.glTexImage2D(target, 0, GL11.GL_RGBA8, w, h, 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, data);
    }
}
Also used : NativeImage(net.minecraft.client.renderer.texture.NativeImage) IntBuffer(java.nio.IntBuffer) IResource(net.minecraft.resources.IResource)

Example 5 with NativeImage

use of net.minecraft.client.renderer.texture.NativeImage in project iChunUtil by iChun.

the class Project method getNativeImageResourceLocation.

@OnlyIn(Dist.CLIENT)
public ResourceLocation getNativeImageResourceLocation() {
    if (textureBytes != null) {
        if (nativeImageTexture == null) {
            try (NativeImage image = NativeImage.read(new ByteArrayInputStream(textureBytes))) {
                nativeImageTexture = new NativeImageTexture(image);
                Minecraft.getInstance().getTextureManager().loadTexture(nativeImageTexture.getResourceLocation(), nativeImageTexture);
            } catch (IOException e) {
                iChunUtil.LOGGER.error("Failed to read NativeImage for project: " + name);
                e.printStackTrace();
            }
        }
        return nativeImageTexture.getResourceLocation();
    }
    return null;
}
Also used : NativeImageTexture(me.ichun.mods.ichunutil.client.render.NativeImageTexture) NativeImage(net.minecraft.client.renderer.texture.NativeImage) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Aggregations

NativeImage (net.minecraft.client.renderer.texture.NativeImage)7 IResource (net.minecraft.resources.IResource)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 TextureMetadataSection (net.minecraft.client.resources.data.TextureMetadataSection)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 Callable (java.util.concurrent.Callable)2 JsonObject (com.google.gson.JsonObject)1 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 IntBuffer (java.nio.IntBuffer)1 HashMap (java.util.HashMap)1 NativeImageTexture (me.ichun.mods.ichunutil.client.render.NativeImageTexture)1 SimpleTexture (net.minecraft.client.renderer.texture.SimpleTexture)1 Texture (net.minecraft.client.renderer.texture.Texture)1 TextureMetadataSectionSerializer (net.minecraft.client.resources.data.TextureMetadataSectionSerializer)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1