Search in sources :

Example 1 with MapRendererAccessor

use of meteordevelopment.meteorclient.mixin.MapRendererAccessor in project meteor-client by MeteorDevelopment.

the class SaveMapCommand method saveMap.

private void saveMap(ItemStack map, MapState state, String path, int scale) {
    // this is horrible code but it somehow works
    MapRenderer mapRenderer = mc.gameRenderer.getMapRenderer();
    MapRenderer.MapTexture texture = ((MapRendererAccessor) mapRenderer).invokeGetMapTexture(FilledMapItem.getMapId(map), state);
    int[] data = texture.texture.getImage().makePixelArray();
    BufferedImage image = new BufferedImage(128, 128, 2);
    image.setRGB(0, 0, image.getWidth(), image.getHeight(), data, 0, 128);
    BufferedImage scaledImage = new BufferedImage(scale, scale, 2);
    if (scale != 128) {
        Graphics2D g = scaledImage.createGraphics();
        g.setComposite(AlphaComposite.Src);
        g.drawImage(image, 0, 0, scale, scale, null);
        g.dispose();
    }
    try {
        ImageIO.write((scale == 128 ? image : scaledImage), "png", new File(path));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : MapRendererAccessor(meteordevelopment.meteorclient.mixin.MapRendererAccessor) MapRenderer(net.minecraft.client.render.MapRenderer) IOException(java.io.IOException) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Aggregations

BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 IOException (java.io.IOException)1 MapRendererAccessor (meteordevelopment.meteorclient.mixin.MapRendererAccessor)1 MapRenderer (net.minecraft.client.render.MapRenderer)1