    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 var4 = 0; var4 < 16384; ++var4)
    031        {
    032            this.intArray[var4] = 0;
    033        }
    034    }
    035
    036    public void renderMap(EntityPlayer par1EntityPlayer, RenderEngine par2RenderEngine, MapData par3MapData)
    037    {
    038        for (int var4 = 0; var4 < 16384; ++var4)
    039        {
    040            byte var5 = par3MapData.colors[var4];
    041
    042            if (var5 / 4 == 0)
    043            {
    044                this.intArray[var4] = (var4 + var4 / 128 & 1) * 8 + 16 << 24;
    045            }
    046            else
    047            {
    048                int var6 = MapColor.mapColorArray[var5 / 4].colorValue;
    049                int var7 = var5 & 3;
    050                short var8 = 220;
    051
    052                if (var7 == 2)
    053                {
    054                    var8 = 255;
    055                }
    056
    057                if (var7 == 0)
    058                {
    059                    var8 = 180;
    060                }
    061
    062                int var9 = (var6 >> 16 & 255) * var8 / 255;
    063                int var10 = (var6 >> 8 & 255) * var8 / 255;
    064                int var11 = (var6 & 255) * var8 / 255;
    065
    066                if (this.gameSettings.anaglyph)
    067                {
    068                    int var12 = (var9 * 30 + var10 * 59 + var11 * 11) / 100;
    069                    int var13 = (var9 * 30 + var10 * 70) / 100;
    070                    int var14 = (var9 * 30 + var11 * 70) / 100;
    071                    var9 = var12;
    072                    var10 = var13;
    073                    var11 = var14;
    074                }
    075
    076                this.intArray[var4] = -16777216 | var9 << 16 | var10 << 8 | var11;
    077            }
    078        }
    079
    080        par2RenderEngine.createTextureFromBytes(this.intArray, 128, 128, this.bufferedImage);
    081        byte var15 = 0;
    082        byte var16 = 0;
    083        Tessellator var17 = Tessellator.instance;
    084        float var18 = 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        var17.startDrawingQuads();
    090        var17.addVertexWithUV((double)((float)(var15 + 0) + var18), (double)((float)(var16 + 128) - var18), -0.009999999776482582D, 0.0D, 1.0D);
    091        var17.addVertexWithUV((double)((float)(var15 + 128) - var18), (double)((float)(var16 + 128) - var18), -0.009999999776482582D, 1.0D, 1.0D);
    092        var17.addVertexWithUV((double)((float)(var15 + 128) - var18), (double)((float)(var16 + 0) + var18), -0.009999999776482582D, 1.0D, 0.0D);
    093        var17.addVertexWithUV((double)((float)(var15 + 0) + var18), (double)((float)(var16 + 0) + var18), -0.009999999776482582D, 0.0D, 0.0D);
    094        var17.draw();
    095        GL11.glEnable(GL11.GL_ALPHA_TEST);
    096        GL11.glDisable(GL11.GL_BLEND);
    097        par2RenderEngine.bindTexture(par2RenderEngine.getTexture("/misc/mapicons.png"));
    098        int var19 = 0;
    099
    100        for (Iterator var20 = par3MapData.playersVisibleOnMap.values().iterator(); var20.hasNext(); ++var19)
    101        {
    102            MapCoord var21 = (MapCoord)var20.next();
    103            GL11.glPushMatrix();
    104            GL11.glTranslatef((float)var15 + (float)var21.centerX / 2.0F + 64.0F, (float)var16 + (float)var21.centerZ / 2.0F + 64.0F, -0.02F);
    105            GL11.glRotatef((float)(var21.iconRotation * 360) / 16.0F, 0.0F, 0.0F, 1.0F);
    106            GL11.glScalef(4.0F, 4.0F, 3.0F);
    107            GL11.glTranslatef(-0.125F, 0.125F, 0.0F);
    108            float var23 = (float)(var21.iconSize % 4 + 0) / 4.0F;
    109            float var22 = (float)(var21.iconSize / 4 + 0) / 4.0F;
    110            float var24 = (float)(var21.iconSize % 4 + 1) / 4.0F;
    111            float var25 = (float)(var21.iconSize / 4 + 1) / 4.0F;
    112            var17.startDrawingQuads();
    113            var17.addVertexWithUV(-1.0D, 1.0D, (double)((float)var19 * 0.001F), (double)var23, (double)var22);
    114            var17.addVertexWithUV(1.0D, 1.0D, (double)((float)var19 * 0.001F), (double)var24, (double)var22);
    115            var17.addVertexWithUV(1.0D, -1.0D, (double)((float)var19 * 0.001F), (double)var24, (double)var25);
    116            var17.addVertexWithUV(-1.0D, -1.0D, (double)((float)var19 * 0.001F), (double)var23, (double)var25);
    117            var17.draw();
    118            GL11.glPopMatrix();
    119        }
    120
    121        GL11.glPushMatrix();
    122        GL11.glTranslatef(0.0F, 0.0F, -0.04F);
    123        GL11.glScalef(1.0F, 1.0F, 1.0F);
    124        GL11.glPopMatrix();
    125    }
    126}