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