Search in sources :

Example 1 with IResource

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

the class AnimationStateMachine method load.

/**
     * Load a new instance if AnimationStateMachine at specified location, with specified custom parameters.
     */
@SideOnly(Side.CLIENT)
public static IAnimationStateMachine load(IResourceManager manager, ResourceLocation location, ImmutableMap<String, ITimeValue> customParameters) {
    try {
        ClipResolver clipResolver = new ClipResolver();
        ParameterResolver parameterResolver = new ParameterResolver(customParameters);
        Clips.CommonClipTypeAdapterFactory.INSTANCE.setClipResolver(clipResolver);
        TimeValues.CommonTimeValueTypeAdapterFactory.INSTANCE.setValueResolver(parameterResolver);
        IResource resource = manager.getResource(location);
        AnimationStateMachine asm = asmGson.fromJson(new InputStreamReader(resource.getInputStream(), "UTF-8"), AnimationStateMachine.class);
        clipResolver.asm = asm;
        parameterResolver.asm = asm;
        asm.initialize();
        //System.out.println(location + ": " + json);
        return asm;
    } catch (IOException e) {
        FMLLog.log(Level.ERROR, e, "Exception loading Animation State Machine %s, skipping", location);
        return missing;
    } catch (JsonParseException e) {
        FMLLog.log(Level.ERROR, e, "Exception loading Animation State Machine %s, skipping", location);
        return missing;
    } finally {
        Clips.CommonClipTypeAdapterFactory.INSTANCE.setClipResolver(null);
        TimeValues.CommonTimeValueTypeAdapterFactory.INSTANCE.setValueResolver(null);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) IResource(net.minecraft.client.resources.IResource) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 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) {
    // Remove the index from the resource path so we can find the original texture.
    location = new ResourceLocation(location.getResourceDomain(), location.getResourcePath().replace("_" + index, ""));
    BufferedImage image;
    IResource resource = null;
    try {
        resource = manager.getResource(location);
        image = ImageIO.read(resource.getInputStream());
    } catch (IOException ex) {
        Game.log(Level.WARN, "Failed to load sub-texture from {0}: {1}", location.getResourcePath(), ex.getLocalizedMessage());
        return true;
    } finally {
        if (resource != null)
            try {
                resource.getInputStream().close();
            } catch (IOException ignored) {
            }
    }
    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(Level.WARN, "Failed to load sub-texture from {0} - {1}x{2}: {3}", location.getResourcePath(), 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);
    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 3 with IResource

use of net.minecraft.client.resources.IResource in project Charset by CharsetMC.

the class SplashTextHandler method addTexts.

public void addTexts(List<String> splashes, ResourceLocation loc) {
    IResource resource = null;
    try {
        resource = Minecraft.getMinecraft().getResourceManager().getResource(loc);
        BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(resource.getInputStream(), Charsets.UTF_8));
        String s;
        while ((s = bufferedreader.readLine()) != null) {
            if (s.length() == 0 || s.charAt(0) == '#')
                continue;
            s = s.trim();
            if (!s.isEmpty()) {
                splashes.add(s);
            }
        }
    } catch (IOException e) {
    } finally {
        IOUtils.closeQuietly(resource);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) IResource(net.minecraft.client.resources.IResource)

Example 4 with IResource

use of net.minecraft.client.resources.IResource in project Charset by CharsetMC.

the class CommandImg method call.

@Override
public void call(ITypesetter out, ITokenizer tokenizer) throws TruthError {
    String imgName = tokenizer.getParameter("domain:path/to/image.png");
    String scaleOrWidth = tokenizer.getOptionalParameter();
    String heightS = tokenizer.getOptionalParameter();
    ResourceLocation rl = new ResourceLocation(imgName);
    try {
        Minecraft mc = Minecraft.getMinecraft();
        IResource r = mc.getResourceManager().getResource(rl);
        if (r == null) {
            throw new TruthError("Not found: " + imgName);
        }
    } catch (Throwable e) {
        e.printStackTrace();
        throw new TruthError(e.getMessage());
    }
    WordImage img;
    if (heightS != null) {
        int width = Integer.parseInt(scaleOrWidth);
        int height = Integer.parseInt(heightS);
        img = new WordImage(rl, width, height);
    } else {
        img = new WordImage(rl);
        if (scaleOrWidth != null) {
            img.scale(Double.parseDouble(scaleOrWidth));
        }
    }
    if (out.hasFixedWidth()) {
        img.fitToPage(out.getWidth(), Integer.MAX_VALUE);
    }
    out.write(img);
}
Also used : TruthError(pl.asie.charset.module.tablet.format.api.TruthError) ResourceLocation(net.minecraft.util.ResourceLocation) WordImage(pl.asie.charset.module.tablet.format.words.WordImage) Minecraft(net.minecraft.client.Minecraft) IResource(net.minecraft.client.resources.IResource)

Example 5 with IResource

use of net.minecraft.client.resources.IResource in project Charset by CharsetMC.

the class WordImage method autosize.

private void autosize() {
    Pair<Integer, Integer> cached = size_cache.get(resource);
    if (cached != null) {
        width = cached.getLeft();
        height = cached.getRight();
        return;
    }
    IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
    try {
        IResource iresource = resourceManager.getResource(resource);
        BufferedImage bufferedimage = TextureUtil.readBufferedImage(iresource.getInputStream());
        this.width = bufferedimage.getWidth();
        this.height = bufferedimage.getHeight();
        size_cache.put(resource, Pair.of(width, height));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : IResourceManager(net.minecraft.client.resources.IResourceManager) IOException(java.io.IOException) IResource(net.minecraft.client.resources.IResource) BufferedImage(java.awt.image.BufferedImage)

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