    001    package net.minecraft.src;
    002
    003    import java.util.Iterator;
    004
    005    public class MapInfo
    006    {
    007        /** Reference for EntityPlayer object in MapInfo */
    008        public final EntityPlayer entityplayerObj;
    009        public int[] field_76209_b;
    010        public int[] field_76210_c;
    011
    012        /**
    013         * updated by x = mod(x*11,128) +1  x-1 is used to index field_76209_b and field_76210_c
    014         */
    015        private int currentRandomNumber;
    016        private int ticksUntilPlayerLocationMapUpdate;
    017
    018        /**
    019         * a cache of the result from getPlayersOnMap so that it is not resent when nothing changes
    020         */
    021        private byte[] lastPlayerLocationOnMap;
    022        public int field_82569_d;
    023        private boolean field_82570_i;
    024
    025        /** reference in MapInfo to MapData object */
    026        final MapData mapDataObj;
    027
    028        public MapInfo(MapData par1MapData, EntityPlayer par2EntityPlayer)
    029        {
    030            this.mapDataObj = par1MapData;
    031            this.field_76209_b = new int[128];
    032            this.field_76210_c = new int[128];
    033            this.currentRandomNumber = 0;
    034            this.ticksUntilPlayerLocationMapUpdate = 0;
    035            this.field_82570_i = false;
    036            this.entityplayerObj = par2EntityPlayer;
    037
    038            for (int var3 = 0; var3 < this.field_76209_b.length; ++var3)
    039            {
    040                this.field_76209_b[var3] = 0;
    041                this.field_76210_c[var3] = 127;
    042            }
    043        }
    044
    045        /**
    046         * returns a 1+players*3 array, of x,y, and color . the name of this function may be partially wrong, as there is a
    047         * second branch to the code here
    048         */
    049        public byte[] getPlayersOnMap(ItemStack par1ItemStack)
    050        {
    051            byte[] var2;
    052
    053            if (!this.field_82570_i)
    054            {
    055                var2 = new byte[] {(byte)2, this.mapDataObj.scale};
    056                this.field_82570_i = true;
    057                return var2;
    058            }
    059            else
    060            {
    061                int var3;
    062                int var10;
    063
    064                if (--this.ticksUntilPlayerLocationMapUpdate < 0)
    065                {
    066                    this.ticksUntilPlayerLocationMapUpdate = 4;
    067                    var2 = new byte[this.mapDataObj.playersVisibleOnMap.size() * 3 + 1];
    068                    var2[0] = 1;
    069                    var3 = 0;
    070
    071                    for (Iterator var4 = this.mapDataObj.playersVisibleOnMap.values().iterator(); var4.hasNext(); ++var3)
    072                    {
    073                        MapCoord var5 = (MapCoord)var4.next();
    074                        var2[var3 * 3 + 1] = (byte)(var5.iconSize << 4 | var5.iconRotation & 15);
    075                        var2[var3 * 3 + 2] = var5.centerX;
    076                        var2[var3 * 3 + 3] = var5.centerZ;
    077                    }
    078
    079                    boolean var9 = !par1ItemStack.func_82839_y();
    080
    081                    if (this.lastPlayerLocationOnMap != null && this.lastPlayerLocationOnMap.length == var2.length)
    082                    {
    083                        for (var10 = 0; var10 < var2.length; ++var10)
    084                        {
    085                            if (var2[var10] != this.lastPlayerLocationOnMap[var10])
    086                            {
    087                                var9 = false;
    088                                break;
    089                            }
    090                        }
    091                    }
    092                    else
    093                    {
    094                        var9 = false;
    095                    }
    096
    097                    if (!var9)
    098                    {
    099                        this.lastPlayerLocationOnMap = var2;
    100                        return var2;
    101                    }
    102                }
    103
    104                for (int var8 = 0; var8 < 1; ++var8)
    105                {
    106                    var3 = this.currentRandomNumber++ * 11 % 128;
    107
    108                    if (this.field_76209_b[var3] >= 0)
    109                    {
    110                        int var11 = this.field_76210_c[var3] - this.field_76209_b[var3] + 1;
    111                        var10 = this.field_76209_b[var3];
    112                        byte[] var6 = new byte[var11 + 3];
    113                        var6[0] = 0;
    114                        var6[1] = (byte)var3;
    115                        var6[2] = (byte)var10;
    116
    117                        for (int var7 = 0; var7 < var6.length - 3; ++var7)
    118                        {
    119                            var6[var7 + 3] = this.mapDataObj.colors[(var7 + var10) * 128 + var3];
    120                        }
    121
    122                        this.field_76210_c[var3] = -1;
    123                        this.field_76209_b[var3] = -1;
    124                        return var6;
    125                    }
    126                }
    127
    128                return null;
    129            }
    130        }
    131    }