Search in sources :

Example 6 with TextureMetadataSection

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

the class ThreadedTexture method loadTexture.

public void loadTexture(IResourceManager resourceManager) throws IOException {
    IResource iresource = null;
    try {
        iresource = resourceManager.getResource(this.textureLocation);
        BufferedImage bufferedimage = TextureUtil.readBufferedImage(iresource.getInputStream());
        flag = false;
        flag1 = false;
        if (iresource.hasMetadata()) {
            try {
                TextureMetadataSection texturemetadatasection = iresource.getMetadata("texture");
                if (texturemetadatasection != null) {
                    flag = texturemetadatasection.getTextureBlur();
                    flag1 = texturemetadatasection.getTextureClamp();
                }
            } catch (RuntimeException runtimeexception) {
                LOGGER.warn("Failed reading metadata of: {}", this.textureLocation, runtimeexception);
            }
        }
        imageData = bufferedimage;
    } finally {
        IOUtils.closeQuietly(iresource);
    }
}
Also used : TextureMetadataSection(net.minecraft.client.resources.data.TextureMetadataSection) IResource(net.minecraft.client.resources.IResource) BufferedImage(java.awt.image.BufferedImage)

Example 7 with TextureMetadataSection

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

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