Bricklayer.Client.World.Map.SetMinimapColors C# (CSharp) Method

SetMinimapColors() public method

Sets block's default colors from their image for use with the minimap
public SetMinimapColors ( ) : void
return void
        public void SetMinimapColors()
        {
            Texture2D texture = tileSheet;
            Color[] data = new Color[texture.Width * texture.Height];
            texture.GetData<Color>(data); //Get data

            for (int i = 0; i < BlockType.BlockList.Count; i++)
            {
                BlockType block = BlockType.BlockList[i];
                int r = 0;
                int g = 0;
                int b = 0;
                int a = 0;
                int amount = 0;

                Rectangle source = new Rectangle(block.Source.X, 4, Tile.Width, Tile.Height);
                for (int c = 0; c < data.Length; c++) //Foreach colored pixel; Get RGB values
                {
                    int x = c % texture.Width;
                    int y = (c - x) / texture.Width;

                    if (block.Source.Contains(new Point(x, y)))
                    {
                        Color color = data[c];
                        if (color.A > 0)
                        {
                            r += color.R;
                            g += color.G;
                            b += color.B;
                            amount++;
                        }
                    }
                }
                //Set the block's minimap color based on the average color of the tile
                if (amount > 0)
                    block.Color = new Color(r / amount, g / amount, b / amount); //Calculate average
                else
                    block.Color = Color.Transparent;
            }
        }