Search in sources :

Example 6 with NativeImage

use of net.minecraft.client.renderer.texture.NativeImage in project MCMOD-Industria by M-Marvin.

the class AnimatedTexture method load.

public void load(IResourceManager manager) throws IOException {
    SimpleTexture.TextureData simpletexture$texturedata = this.getTextureImage(manager);
    simpletexture$texturedata.throwIfError();
    TextureMetadataSection texturemetadatasection = simpletexture$texturedata.getTextureMetadata();
    boolean flag;
    boolean flag1;
    if (texturemetadatasection != null) {
        flag = texturemetadatasection.isBlur();
        flag1 = texturemetadatasection.isClamp();
    } else {
        flag = false;
        flag1 = false;
    }
    NativeImage nativeimage = simpletexture$texturedata.getImage();
    if (!RenderSystem.isOnRenderThreadOrInit()) {
        RenderSystem.recordRenderCall(() -> {
            this.loadImage(nativeimage, flag, flag1);
        });
    } else {
        this.loadImage(nativeimage, flag, flag1);
    }
    this.size = simpletexture$texturedata.getImage().getWidth();
    this.textureHeight = simpletexture$texturedata.getImage().getHeight();
    ResourceLocation metadataFile = new ResourceLocation(this.location.getNamespace(), this.location.getPath() + ".mcmeta");
    try {
        IResource metadataResource = manager.getResource(metadataFile);
        InputStreamReader inputStreamReader = new InputStreamReader(metadataResource.getInputStream());
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        StringBuffer stringBuffer = new StringBuffer();
        String string;
        while ((string = bufferedReader.readLine()) != null) {
            stringBuffer.append(string);
        }
        CompoundNBT metadataNBT = JsonToNBT.parseTag(stringBuffer.toString());
        CompoundNBT animation = metadataNBT.getCompound("animation");
        this.frameTime = animation.getInt("frametime");
        if (animation.contains("frames")) {
            ListNBT arr = animation.getList("frames", 3);
            frames = new int[arr.size()];
            for (int i = 0; i < arr.size(); i++) {
                this.frames[i] = arr.getInt(i);
            }
        } else {
            int height = simpletexture$texturedata.getImage().getHeight();
            int frameCount = height / size;
            frames = new int[frameCount];
            for (int i = 0; i < frameCount; i++) {
                this.frames[i] = i;
            }
        }
    } catch (CommandSyntaxException | FileNotFoundException e) {
        this.frames = new int[] { 0 };
        this.frameTime = 1;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) CompoundNBT(net.minecraft.nbt.CompoundNBT) TextureMetadataSection(net.minecraft.client.resources.data.TextureMetadataSection) FileNotFoundException(java.io.FileNotFoundException) SimpleTexture(net.minecraft.client.renderer.texture.SimpleTexture) ListNBT(net.minecraft.nbt.ListNBT) NativeImage(net.minecraft.client.renderer.texture.NativeImage) ResourceLocation(net.minecraft.util.ResourceLocation) BufferedReader(java.io.BufferedReader) IResource(net.minecraft.resources.IResource) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException)

Example 7 with NativeImage

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

the class RGBBlocksPack method gatherTextureData.

protected void gatherTextureData(IResourceManager manager, IProfiler profiler) {
    Map<ResourceLocation, Callable<InputStream>> resourceStreams = new HashMap<>();
    textures.forEach((modLocation, vanillaLocation) -> {
        generateImage(modLocation, vanillaLocation, Minecraft.getInstance().getResourceManager()).ifPresent(pair -> {
            NativeImage image = pair.getFirst();
            ResourceLocation textureID = makeTextureID(modLocation);
            resourceStreams.put(textureID, () -> new ByteArrayInputStream(image.asByteArray()));
            pair.getSecond().ifPresent(metadataGetter -> resourceStreams.put(getMetadataLocation(textureID), metadataGetter));
        });
    });
    this.resources = resourceStreams;
}
Also used : NativeImage(net.minecraft.client.renderer.texture.NativeImage) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) ResourceLocation(net.minecraft.util.ResourceLocation) Callable(java.util.concurrent.Callable)

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