use of mathax.client.mixin.MapRendererAccessor in project Client by MatHax.
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();
}
}
Aggregations