    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.awt.image.BufferedImage;
    006    import java.util.Iterator;
    007    import org.lwjgl.opengl.GL11;
    008
    009    @SideOnly(Side.CLIENT)
    010    public class MapItemRenderer
    011    {
    012        private int[] intArray = new int[16384];
    013        private int bufferedImage;
    014        private GameSettings gameSettings;
    015        private FontRenderer fontRenderer;
    016
    017        public MapItemRenderer(FontRenderer par1FontRenderer, GameSettings par2GameSettings, RenderEngine par3RenderEngine)
    018        {
    019            this.gameSettings = par2GameSettings;
    020            this.fontRenderer = par1FontRenderer;
    021            this.bufferedImage = par3RenderEngine.allocateAndSetupTexture(new BufferedImage(128, 128, 2));
    022
    023            for (int var4 = 0; var4 < 16384; ++var4)
    024            {
    025                this.intArray[var4] = 0;
    026            }
    027        }
    028
    029        public void renderMap(EntityPlayer par1EntityPlayer, RenderEngine par2RenderEngine, MapData par3MapData)
    030        {
    031            for (int var4 = 0; var4 < 16384; ++var4)
    032            {
    033                byte var5 = par3MapData.colors[var4];
    034
    035                if (var5 / 4 == 0)
    036                {
    037                    this.intArray[var4] = (var4 + var4 / 128 & 1) * 8 + 16 << 24;
    038                }
    039                else
    040                {
    041                    int var6 = MapColor.mapColorArray[var5 / 4].colorValue;
    042                    int var7 = var5 & 3;
    043                    short var8 = 220;
    044
    045                    if (var7 == 2)
    046                    {
    047                        var8 = 255;
    048                    }
    049
    050                    if (var7 == 0)
    051                    {
    052                        var8 = 180;
    053                    }
    054
    055                    int var9 = (var6 >> 16 & 255) * var8 / 255;
    056                    int var10 = (var6 >> 8 & 255) * var8 / 255;
    057                    int var11 = (var6 & 255) * var8 / 255;
    058
    059                    if (this.gameSettings.anaglyph)
    060                    {
    061                        int var12 = (var9 * 30 + var10 * 59 + var11 * 11) / 100;
    062                        int var13 = (var9 * 30 + var10 * 70) / 100;
    063                        int var14 = (var9 * 30 + var11 * 70) / 100;
    064                        var9 = var12;
    065                        var10 = var13;
    066                        var11 = var14;
    067                    }
    068
    069                    this.intArray[var4] = -16777216 | var9 << 16 | var10 << 8 | var11;
    070                }
    071            }
    072
    073            par2RenderEngine.createTextureFromBytes(this.intArray, 128, 128, this.bufferedImage);
    074            byte var15 = 0;
    075            byte var16 = 0;
    076            Tessellator var17 = Tessellator.instance;
    077            float var18 = 0.0F;
    078            GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.bufferedImage);
    079            GL11.glEnable(GL11.GL_BLEND);
    080            GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
    081            GL11.glDisable(GL11.GL_ALPHA_TEST);
    082            var17.startDrawingQuads();
    083            var17.addVertexWithUV((double)((float)(var15 + 0) + var18), (double)((float)(var16 + 128) - var18), -0.009999999776482582D, 0.0D, 1.0D);
    084            var17.addVertexWithUV((double)((float)(var15 + 128) - var18), (double)((float)(var16 + 128) - var18), -0.009999999776482582D, 1.0D, 1.0D);
    085            var17.addVertexWithUV((double)((float)(var15 + 128) - var18), (double)((float)(var16 + 0) + var18), -0.009999999776482582D, 1.0D, 0.0D);
    086            var17.addVertexWithUV((double)((float)(var15 + 0) + var18), (double)((float)(var16 + 0) + var18), -0.009999999776482582D, 0.0D, 0.0D);
    087            var17.draw();
    088            GL11.glEnable(GL11.GL_ALPHA_TEST);
    089            GL11.glDisable(GL11.GL_BLEND);
    090            par2RenderEngine.bindTexture(par2RenderEngine.getTexture("/misc/mapicons.png"));
    091            int var19 = 0;
    092
    093            for (Iterator var20 = par3MapData.playersVisibleOnMap.values().iterator(); var20.hasNext(); ++var19)
    094            {
    095                MapCoord var21 = (MapCoord)var20.next();
    096                GL11.glPushMatrix();
    097                GL11.glTranslatef((float)var15 + (float)var21.centerX / 2.0F + 64.0F, (float)var16 + (float)var21.centerZ / 2.0F + 64.0F, -0.02F);
    098                GL11.glRotatef((float)(var21.iconRotation * 360) / 16.0F, 0.0F, 0.0F, 1.0F);
    099                GL11.glScalef(4.0F, 4.0F, 3.0F);
    100                GL11.glTranslatef(-0.125F, 0.125F, 0.0F);
    101                float var23 = (float)(var21.iconSize % 4 + 0) / 4.0F;
    102                float var22 = (float)(var21.iconSize / 4 + 0) / 4.0F;
    103                float var24 = (float)(var21.iconSize % 4 + 1) / 4.0F;
    104                float var25 = (float)(var21.iconSize / 4 + 1) / 4.0F;
    105                var17.startDrawingQuads();
    106                var17.addVertexWithUV(-1.0D, 1.0D, (double)((float)var19 * 0.001F), (double)var23, (double)var22);
    107                var17.addVertexWithUV(1.0D, 1.0D, (double)((float)var19 * 0.001F), (double)var24, (double)var22);
    108                var17.addVertexWithUV(1.0D, -1.0D, (double)((float)var19 * 0.001F), (double)var24, (double)var25);
    109                var17.addVertexWithUV(-1.0D, -1.0D, (double)((float)var19 * 0.001F), (double)var23, (double)var25);
    110                var17.draw();
    111                GL11.glPopMatrix();
    112            }
    113
    114            GL11.glPushMatrix();
    115            GL11.glTranslatef(0.0F, 0.0F, -0.04F);
    116            GL11.glScalef(1.0F, 1.0F, 1.0F);
    117            GL11.glPopMatrix();
    118        }
    119    }