Search in sources :

Example 21 with IResource

use of net.minecraft.client.resources.IResource in project BuildCraft by BuildCraft.

the class SpriteFluidFrozen method load.

@Override
public boolean load(IResourceManager manager, ResourceLocation location, Function<ResourceLocation, TextureAtlasSprite> textureGetter) {
    location = SpriteUtil.transformLocation(srcLocation);
    TextureAtlasSprite src = Minecraft.getMinecraft().getTextureMapBlocks().getTextureExtry(srcLocation.toString());
    if (src == null) {
        BCLog.logger.warn("[lib.fluid] Failed to create a frozen sprite of " + srcLocation.toString() + " as the source sprite wasn't able to be loaded!");
        return true;
    }
    if (src.getFrameCount() <= 0) {
        if (src.hasCustomLoader(manager, location)) {
            src.load(manager, location, textureGetter);
        } else {
            try {
                PngSizeInfo pngsizeinfo = PngSizeInfo.makeFromResource(manager.getResource(location));
                try (IResource resource = manager.getResource(location)) {
                    src.loadSprite(pngsizeinfo, resource.getMetadata("animation") != null);
                    src.loadSpriteFrames(resource, Minecraft.getMinecraft().gameSettings.mipmapLevels + 1);
                }
            } catch (IOException io) {
                io.printStackTrace();
            }
        }
    }
    if (src.getFrameCount() > 0) {
        int widthOld = src.getIconWidth();
        int heightOld = src.getIconHeight();
        width = widthOld * 2;
        height = heightOld * 2;
        int[][] srcData = src.getFrameTextureData(0);
        data = new int[Minecraft.getMinecraft().gameSettings.mipmapLevels + 1][];
        for (int m = 0; m < data.length; m++) {
            data[m] = new int[width * height / (m + 1) / (m + 1)];
        }
        int[] relData = srcData[0];
        if (relData.length < (width * height / 4)) {
            Arrays.fill(data[0], 0xFF_FF_FF_00);
        } else {
            for (int x = 0; x < width; x++) {
                int fx = (x % widthOld) * heightOld;
                for (int y = 0; y < height; y++) {
                    int fy = y % heightOld;
                    data[0][x * height + y] = relData[fx + fy];
                }
            }
        }
    } else {
        // Urm... idk
        BCLog.logger.warn("[lib.fluid] Failed to create a frozen sprite of " + src.getIconName() + " as the source sprite didn't have any frames!");
        return true;
    }
    return false;
}
Also used : TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) PngSizeInfo(net.minecraft.client.renderer.texture.PngSizeInfo) IOException(java.io.IOException) IResource(net.minecraft.client.resources.IResource)

Example 22 with IResource

use of net.minecraft.client.resources.IResource in project BuildCraft by BuildCraft.

the class AtlasSpriteSwappable method loadSprite.

public static TextureAtlasSprite loadSprite(IResourceManager manager, String name, ResourceLocation location, boolean careIfMissing) {
    // Load the initial variant
    TextureAtlasSprite sprite = makeAtlasSprite(new ResourceLocation(name));
    try {
        // Copied almost directly from TextureMap.
        PngSizeInfo pngsizeinfo = PngSizeInfo.makeFromResource(manager.getResource(location));
        try (IResource iresource = manager.getResource(location)) {
            boolean flag = iresource.getMetadata("animation") != null;
            sprite.loadSprite(pngsizeinfo, flag);
            sprite.loadSpriteFrames(iresource, Minecraft.getMinecraft().gameSettings.mipmapLevels + 1);
            return sprite;
        }
    } catch (IOException io) {
        if (careIfMissing) {
            // Do the same as forge - track the missing texture for later rather than printing out the error.
            FMLClientHandler.instance().trackMissingTexture(location);
        }
        return null;
    }
}
Also used : TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ResourceLocation(net.minecraft.util.ResourceLocation) PngSizeInfo(net.minecraft.client.renderer.texture.PngSizeInfo) IOException(java.io.IOException) IResource(net.minecraft.client.resources.IResource)

Example 23 with IResource

use of net.minecraft.client.resources.IResource in project BuildCraft by BuildCraft.

the class MetadataLoader method getData.

/**
 * @param samePack If true, then only the data
 * @return
 */
@Nullable
public static DataMetadataSection getData(ResourceLocation location, boolean samePack) {
    IResourceManager resManager = Minecraft.getMinecraft().getResourceManager();
    register();
    try {
        List<IResource> resources = resManager.getAllResources(location);
        DataMetadataSection section = null;
        for (IResource resource : resources) {
            section = resource.getMetadata(DataMetadataSection.SECTION_NAME);
            if (section != null || samePack) {
                break;
            }
        }
        for (IResource res : resources) {
            try {
                res.close();
            } catch (IOException io) {
                io.printStackTrace();
            }
        }
        return section;
    } catch (FileNotFoundException fnfe) {
        // That's fine
        return null;
    } catch (IOException e) {
        // That's not fine
        e.printStackTrace();
        return null;
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IResourceManager(net.minecraft.client.resources.IResourceManager) IOException(java.io.IOException) IResource(net.minecraft.client.resources.IResource) Nullable(javax.annotation.Nullable)

Example 24 with IResource

use of net.minecraft.client.resources.IResource in project RebornCore by TechReborn.

the class InputStreamTexture method loadTexture.

public void loadTexture(IResourceManager resourceManager) throws IOException {
    this.deleteGlTexture();
    if (image == null) {
        IResource iresource = null;
        try {
            iresource = new IResource() {

                @Override
                public ResourceLocation getResourceLocation() {
                    return new ResourceLocation("reborncore:loaded/" + name);
                }

                @Override
                public InputStream getInputStream() {
                    return textureLocation;
                }

                @Override
                public boolean hasMetadata() {
                    return false;
                }

                @Override
                public <T extends IMetadataSection> T getMetadata(String sectionName) {
                    return null;
                }

                @Override
                public String getResourcePackName() {
                    return "reborncore";
                }

                @Override
                public void close() throws IOException {
                }
            };
            image = TextureUtil.readBufferedImage(iresource.getInputStream());
        } finally {
            IOUtils.closeQuietly(iresource);
        }
    }
    TextureUtil.uploadTextureImageAllocate(this.getGlTextureId(), image, false, false);
}
Also used : InputStream(java.io.InputStream) ResourceLocation(net.minecraft.util.ResourceLocation) IOException(java.io.IOException) IResource(net.minecraft.client.resources.IResource)

Example 25 with IResource

use of net.minecraft.client.resources.IResource in project RebornCore by TechReborn.

the class FileSystemTexture method loadTexture.

public void loadTexture(IResourceManager resourceManager) throws IOException {
    this.deleteGlTexture();
    if (image == null) {
        IResource iresource = null;
        try {
            iresource = new IResource() {

                FileInputStream stream;

                @Override
                public ResourceLocation getResourceLocation() {
                    return new ResourceLocation("reborncore:loaded/" + textureLocation.getName());
                }

                @Override
                public InputStream getInputStream() {
                    if (stream == null) {
                        try {
                            stream = new FileInputStream(textureLocation);
                        } catch (FileNotFoundException e) {
                            e.printStackTrace();
                        }
                    }
                    return stream;
                }

                @Override
                public boolean hasMetadata() {
                    return false;
                }

                @Override
                public <T extends IMetadataSection> T getMetadata(String sectionName) {
                    return null;
                }

                @Override
                public String getResourcePackName() {
                    return "reborncore";
                }

                @Override
                public void close() throws IOException {
                    if (stream != null) {
                        stream.close();
                    }
                }
            };
            image = TextureUtil.readBufferedImage(iresource.getInputStream());
        } finally {
            IOUtils.closeQuietly(iresource);
        }
    }
    TextureUtil.uploadTextureImageAllocate(this.getGlTextureId(), image, false, false);
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) IResource(net.minecraft.client.resources.IResource)

Aggregations

IResource (net.minecraft.client.resources.IResource)38 IOException (java.io.IOException)23 ResourceLocation (net.minecraft.util.ResourceLocation)21 InputStreamReader (java.io.InputStreamReader)12 BufferedImage (java.awt.image.BufferedImage)9 IResourceManager (net.minecraft.client.resources.IResourceManager)8 BufferedReader (java.io.BufferedReader)6 JsonObject (com.google.gson.JsonObject)3 FileNotFoundException (java.io.FileNotFoundException)3 InputStream (java.io.InputStream)3 Nullable (javax.annotation.Nullable)3 PngSizeInfo (net.minecraft.client.renderer.texture.PngSizeInfo)3 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)3 IModel (net.minecraftforge.client.model.IModel)3 JsonElement (com.google.gson.JsonElement)2 RasterFormatException (java.awt.image.RasterFormatException)2 Minecraft (net.minecraft.client.Minecraft)2 CrashReport (net.minecraft.crash.CrashReport)2 CrashReportCategory (net.minecraft.crash.CrashReportCategory)2 ReportedException (net.minecraft.util.ReportedException)2