Search in sources :

Example 1 with MapRenderer

use of net.minecraft.client.render.MapRenderer in project Skyblocker by LifeIsAParadox.

the class DungeonMap method render.

public static void render(MatrixStack matrices) {
    MinecraftClient client = MinecraftClient.getInstance();
    if (client.player == null && client.world == null)
        return;
    ItemStack item = client.player.getInventory().main.get(8);
    NbtCompound tag = item.getNbt();
    if (tag != null && tag.contains("map")) {
        String tag2 = tag.asString();
        tag2 = StringUtils.substringBetween(tag2, "map:", "}");
        int mapid = Integer.parseInt(tag2);
        VertexConsumerProvider.Immediate vertices = client.getBufferBuilders().getEffectVertexConsumers();
        MapRenderer map = client.gameRenderer.getMapRenderer();
        MapState state = FilledMapItem.getMapState(mapid, client.world);
        if (state == null)
            return;
        matrices.push();
        matrices.translate(2, 2, 0);
        matrices.scale(1, 1, 0);
        map.draw(matrices, vertices, mapid, state, false, 15728880);
        vertices.draw();
        matrices.pop();
    }
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) MapRenderer(net.minecraft.client.render.MapRenderer) MinecraftClient(net.minecraft.client.MinecraftClient) MapState(net.minecraft.item.map.MapState) ItemStack(net.minecraft.item.ItemStack) VertexConsumerProvider(net.minecraft.client.render.VertexConsumerProvider)

Example 2 with MapRenderer

use of net.minecraft.client.render.MapRenderer 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)

Example 3 with MapRenderer

use of net.minecraft.client.render.MapRenderer 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();
    }
}
Also used : MapRendererAccessor(mathax.client.mixin.MapRendererAccessor) MapRenderer(net.minecraft.client.render.MapRenderer) IOException(java.io.IOException) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Aggregations

MapRenderer (net.minecraft.client.render.MapRenderer)3 BufferedImage (java.awt.image.BufferedImage)2 File (java.io.File)2 IOException (java.io.IOException)2 MapRendererAccessor (mathax.client.mixin.MapRendererAccessor)1 MapRendererAccessor (meteordevelopment.meteorclient.mixin.MapRendererAccessor)1 MinecraftClient (net.minecraft.client.MinecraftClient)1 VertexConsumerProvider (net.minecraft.client.render.VertexConsumerProvider)1 ItemStack (net.minecraft.item.ItemStack)1 MapState (net.minecraft.item.map.MapState)1 NbtCompound (net.minecraft.nbt.NbtCompound)1