    001package net.minecraft.client.gui;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import java.awt.image.BufferedImage;
    006import java.util.Iterator;
    007import net.minecraft.block.material.MapColor;
    008import net.minecraft.client.renderer.RenderEngine;
    009import net.minecraft.client.renderer.Tessellator;
    010import net.minecraft.client.settings.GameSettings;
    011import net.minecraft.entity.player.EntityPlayer;
    012import net.minecraft.world.storage.MapCoord;
    013import net.minecraft.world.storage.MapData;
    014import org.lwjgl.opengl.GL11;
    015
    016@SideOnly(Side.CLIENT)
    017public class MapItemRenderer
    018{
    019    private int[] intArray = new int[16384];
    020    private int bufferedImage;
    021    private GameSettings gameSettings;
    022    private FontRenderer fontRenderer;
    023
    024    public MapItemRenderer(FontRenderer par1FontRenderer, GameSettings par2GameSettings, RenderEngine par3RenderEngine)
    025    {
    026        this.gameSettings = par2GameSettings;
    027        this.fontRenderer = par1FontRenderer;
    028        this.bufferedImage = par3RenderEngine.allocateAndSetupTexture(new BufferedImage(128, 128, 2));
    029
    030        for (int i = 0; i < 16384; ++i)
    031        {
    032            this.intArray[i] = 0;
    033        }
    034    }
    035
    036    public void renderMap(EntityPlayer par1EntityPlayer, RenderEngine par2RenderEngine, MapData par3MapData)
    037    {
    038        for (int i = 0; i < 16384; ++i)
    039        {
    040            byte b0 = par3MapData.colors[i];
    041
    042            if (b0 / 4 == 0)
    043            {
    044                this.intArray[i] = (i + i / 128 & 1) * 8 + 16 << 24;
    045            }
    046            else
    047            {
    048                int j = MapColor.mapColorArray[b0 / 4].colorValue;
    049                int k = b0 & 3;
    050                short short1 = 220;
    051
    052                if (k == 2)
    053                {
    054                    short1 = 255;
    055                }
    056
    057                if (k == 0)
    058                {
    059                    short1 = 180;
    060                }
    061
    062                int l = (j >> 16 & 255) * short1 / 255;
    063                int i1 = (j >> 8 & 255) * short1 / 255;
    064                int j1 = (j & 255) * short1 / 255;
    065
    066                if (this.gameSettings.anaglyph)
    067                {
    068                    int k1 = (l * 30 + i1 * 59 + j1 * 11) / 100;
    069                    int l1 = (l * 30 + i1 * 70) / 100;
    070                    int i2 = (l * 30 + j1 * 70) / 100;
    071                    l = k1;
    072                    i1 = l1;
    073                    j1 = i2;
    074                }
    075
    076                this.intArray[i] = -16777216 | l << 16 | i1 << 8 | j1;
    077            }
    078        }
    079
    080        par2RenderEngine.createTextureFromBytes(this.intArray, 128, 128, this.bufferedImage);
    081        byte b1 = 0;
    082        byte b2 = 0;
    083        Tessellator tessellator = Tessellator.instance;
    084        float f = 0.0F;
    085        GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.bufferedImage);
    086        GL11.glEnable(GL11.GL_BLEND);
    087        GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
    088        GL11.glDisable(GL11.GL_ALPHA_TEST);
    089        tessellator.startDrawingQuads();
    090        tessellator.addVertexWithUV((double)((float)(b1 + 0) + f), (double)((float)(b2 + 128) - f), -0.009999999776482582D, 0.0D, 1.0D);
    091        tessellator.addVertexWithUV((double)((float)(b1 + 128) - f), (double)((float)(b2 + 128) - f), -0.009999999776482582D, 1.0D, 1.0D);
    092        tessellator.addVertexWithUV((double)((float)(b1 + 128) - f), (double)((float)(b2 + 0) + f), -0.009999999776482582D, 1.0D, 0.0D);
    093        tessellator.addVertexWithUV((double)((float)(b1 + 0) + f), (double)((float)(b2 + 0) + f), -0.009999999776482582D, 0.0D, 0.0D);
    094        tessellator.draw();
    095        GL11.glEnable(GL11.GL_ALPHA_TEST);
    096        GL11.glDisable(GL11.GL_BLEND);
    097        par2RenderEngine.func_98185_a();
    098        par2RenderEngine.func_98187_b("/misc/mapicons.png");
    099        int j2 = 0;
    100
    101        for (Iterator iterator = par3MapData.playersVisibleOnMap.values().iterator(); iterator.hasNext(); ++j2)
    102        {
    103            MapCoord mapcoord = (MapCoord)iterator.next();
    104            GL11.glPushMatrix();
    105            GL11.glTranslatef((float)b1 + (float)mapcoord.centerX / 2.0F + 64.0F, (float)b2 + (float)mapcoord.centerZ / 2.0F + 64.0F, -0.02F);
    106            GL11.glRotatef((float)(mapcoord.iconRotation * 360) / 16.0F, 0.0F, 0.0F, 1.0F);
    107            GL11.glScalef(4.0F, 4.0F, 3.0F);
    108            GL11.glTranslatef(-0.125F, 0.125F, 0.0F);
    109            float f1 = (float)(mapcoord.iconSize % 4 + 0) / 4.0F;
    110            float f2 = (float)(mapcoord.iconSize / 4 + 0) / 4.0F;
    111            float f3 = (float)(mapcoord.iconSize % 4 + 1) / 4.0F;
    112            float f4 = (float)(mapcoord.iconSize / 4 + 1) / 4.0F;
    113            tessellator.startDrawingQuads();
    114            tessellator.addVertexWithUV(-1.0D, 1.0D, (double)((float)j2 * 0.001F), (double)f1, (double)f2);
    115            tessellator.addVertexWithUV(1.0D, 1.0D, (double)((float)j2 * 0.001F), (double)f3, (double)f2);
    116            tessellator.addVertexWithUV(1.0D, -1.0D, (double)((float)j2 * 0.001F), (double)f3, (double)f4);
    117            tessellator.addVertexWithUV(-1.0D, -1.0D, (double)((float)j2 * 0.001F), (double)f1, (double)f4);
    118            tessellator.draw();
    119            GL11.glPopMatrix();
    120        }
    121
    122        GL11.glPushMatrix();
    123        GL11.glTranslatef(0.0F, 0.0F, -0.04F);
    124        GL11.glScalef(1.0F, 1.0F, 1.0F);
    125        GL11.glPopMatrix();
    126    }
    127}