    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 i = 0; i < this.field_76209_b.length; ++i)
    041        {
    042            this.field_76209_b[i] = 0;
    043            this.field_76210_c[i] = 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[] abyte;
    054
    055        if (!this.field_82570_i)
    056        {
    057            abyte = new byte[] {(byte)2, this.mapDataObj.scale};
    058            this.field_82570_i = true;
    059            return abyte;
    060        }
    061        else
    062        {
    063            int i;
    064            int j;
    065
    066            if (--this.ticksUntilPlayerLocationMapUpdate < 0)
    067            {
    068                this.ticksUntilPlayerLocationMapUpdate = 4;
    069                abyte = new byte[this.mapDataObj.playersVisibleOnMap.size() * 3 + 1];
    070                abyte[0] = 1;
    071                i = 0;
    072
    073                for (Iterator iterator = this.mapDataObj.playersVisibleOnMap.values().iterator(); iterator.hasNext(); ++i)
    074                {
    075                    MapCoord mapcoord = (MapCoord)iterator.next();
    076                    abyte[i * 3 + 1] = (byte)(mapcoord.iconSize << 4 | mapcoord.iconRotation & 15);
    077                    abyte[i * 3 + 2] = mapcoord.centerX;
    078                    abyte[i * 3 + 3] = mapcoord.centerZ;
    079                }
    080
    081                boolean flag = !par1ItemStack.isOnItemFrame();
    082
    083                if (this.lastPlayerLocationOnMap != null && this.lastPlayerLocationOnMap.length == abyte.length)
    084                {
    085                    for (j = 0; j < abyte.length; ++j)
    086                    {
    087                        if (abyte[j] != this.lastPlayerLocationOnMap[j])
    088                        {
    089                            flag = false;
    090                            break;
    091                        }
    092                    }
    093                }
    094                else
    095                {
    096                    flag = false;
    097                }
    098
    099                if (!flag)
    100                {
    101                    this.lastPlayerLocationOnMap = abyte;
    102                    return abyte;
    103                }
    104            }
    105
    106            for (int k = 0; k < 1; ++k)
    107            {
    108                i = this.currentRandomNumber++ * 11 % 128;
    109
    110                if (this.field_76209_b[i] >= 0)
    111                {
    112                    int l = this.field_76210_c[i] - this.field_76209_b[i] + 1;
    113                    j = this.field_76209_b[i];
    114                    byte[] abyte1 = new byte[l + 3];
    115                    abyte1[0] = 0;
    116                    abyte1[1] = (byte)i;
    117                    abyte1[2] = (byte)j;
    118
    119                    for (int i1 = 0; i1 < abyte1.length - 3; ++i1)
    120                    {
    121                        abyte1[i1 + 3] = this.mapDataObj.colors[(i1 + j) * 128 + i];
    122                    }
    123
    124                    this.field_76210_c[i] = -1;
    125                    this.field_76209_b[i] = -1;
    126                    return abyte1;
    127                }
    128            }
    129
    130            return null;
    131        }
    132    }
    133}