Search in sources :

Example 36 with IResource

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

the class TextureAtlasSheet method load.

@Override
public boolean load(IResourceManager manager, ResourceLocation location, Function<ResourceLocation, TextureAtlasSprite> resourceGetter) {
    // Remove the index from the resource path so we can find the original texture.
    ResourceLocation fullLocation = new ResourceLocation(location.getNamespace(), location.getPath().replace("_" + index, ""));
    BufferedImage image;
    try (IResource resource = manager.getResource(fullLocation)) {
        image = ImageIO.read(resource.getInputStream());
    } catch (IOException ex) {
        Game.log().msg(Level.WARN, "Failed to load sub-texture from {0}: {1}", fullLocation.getPath(), ex.getLocalizedMessage());
        return true;
    }
    int mipmapLevels = Minecraft.getMinecraft().gameSettings.mipmapLevels;
    int size = image.getHeight() / rows;
    int x = index % columns;
    int y = index / columns;
    BufferedImage subImage;
    try {
        subImage = image.getSubimage(x * size, y * size, size, size);
    } catch (RasterFormatException ex) {
        Game.log().msg(Level.WARN, "Failed to load sub-texture from {0} - {1}x{2}: {3}", fullLocation.getPath(), image.getWidth(), image.getHeight(), ex.getLocalizedMessage());
        return true;
    }
    this.height = subImage.getHeight();
    this.width = subImage.getWidth();
    int[] rgbaData = new int[height * width];
    subImage.getRGB(0, 0, width, height, rgbaData, 0, width);
    int[][] imageData = new int[1 + mipmapLevels][];
    imageData[0] = rgbaData;
    framesTextureData.add(imageData);
    // Hack to use sheet textures for advancement backgrounds
    Game.log("models").msg(Level.INFO, "registering custom textures {0}", location);
    Minecraft.getMinecraft().getTextureManager().loadTexture(location, new Texture(subImage));
    return false;
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) IResource(net.minecraft.client.resources.IResource) RasterFormatException(java.awt.image.RasterFormatException)

Example 37 with IResource

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

the class ModelHelper method getReaderForResource.

public static Reader getReaderForResource(ResourceLocation location) throws IOException {
    ResourceLocation file = new ResourceLocation(location.getResourceDomain(), location.getResourcePath() + ".json");
    IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource(file);
    return new BufferedReader(new InputStreamReader(iresource.getInputStream(), Charsets.UTF_8));
}
Also used : InputStreamReader(java.io.InputStreamReader) ResourceLocation(net.minecraft.util.ResourceLocation) BufferedReader(java.io.BufferedReader) IResource(net.minecraft.client.resources.IResource)

Example 38 with IResource

use of net.minecraft.client.resources.IResource in project Galacticraft by micdoodle8.

the class OBJLoaderGC method loadModel.

@Override
public IModel loadModel(ResourceLocation modelLocation) throws IOException {
    IModel model = null;
    if (cache.containsKey(modelLocation)) {
        model = cache.get(modelLocation);
    } else {
        try {
            String prefix = modelLocation.getResourcePath().contains("models/") ? "" : "models/";
            ResourceLocation file = new ResourceLocation(modelLocation.getResourceDomain(), prefix + modelLocation.getResourcePath());
            IResource resource = manager.getResource(file);
            if (resource != null) {
                OBJModel.Parser parser = new OBJModel.Parser(resource, manager);
                try {
                    model = parser.parse().process(ImmutableMap.of("flip-v", "true"));
                } finally {
                    resource.getInputStream().close();
                    cache.put(modelLocation, model);
                }
            }
        } catch (IOException e) {
            throw e;
        }
    }
    if (model == null)
        return ModelLoaderRegistry.getMissingModel();
    return model;
}
Also used : IModel(net.minecraftforge.client.model.IModel) ResourceLocation(net.minecraft.util.ResourceLocation) IOException(java.io.IOException) OBJModel(net.minecraftforge.client.model.obj.OBJModel) 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