BiomePainter.ColorPalette.Lookup C# (CSharp) Method

Lookup() public static method

public static Lookup ( int block, int data, byte biome ) : Color
block int
data int
biome byte
return Color
        public static Color Lookup(int block, int data, byte biome)
        {
            if (blockTable == null)
                LoadBlockTable();

            String idDataBiome = String.Format("{0}:{1}b{2}", block, data, biome);
            String idData = String.Format("{0}:{1}", block, data);
            String idBiome = String.Format("{0}b{1}", block, biome);
            String id = block.ToString();

            if (biome != (byte)Biome.Unspecified && blockTable.ContainsKey(idDataBiome))
                return blockTable[idDataBiome];
            else if (blockTable.ContainsKey(idData))
                return blockTable[idData];
            else if (biome != (byte)Biome.Unspecified && blockTable.ContainsKey(idBiome))
                return blockTable[idBiome];
            else if (blockTable.ContainsKey(id))
                return blockTable[id];
            else
                return Color.FromArgb(0xc3, 0x74, 0xe9); //magenta
        }

Usage Example

示例#1
0
        private static void RenderChunkTerrain(Object state)
        {
            Object[] parameters = (Object[])state;

            Chunk  c       = (Chunk)parameters[0];
            Bitmap b       = (Bitmap)parameters[1];
            int    offsetX = (int)parameters[2];
            int    offsetY = (int)parameters[3];

            TAG_Compound[] sections = new TAG_Compound[16];
            int            highest  = -1;

            foreach (TAG t in (TAG[])c.Root["Level"]["Sections"])
            {
                byte index = (byte)t["Y"];
                if (index > highest)
                {
                    highest = index;
                }
                sections[index] = (TAG_Compound)t;
            }

            if (c.ManualHeightmap == null)
            {
                c.ManualHeightmap = new int[256];
                for (int i = 0; i < c.ManualHeightmap.Length; i++)
                {
                    c.ManualHeightmap[i] = -1;
                }
            }

            //chunk exists but all blocks are air
            if (highest < 0)
            {
                if (Interlocked.Decrement(ref taskCount) == 0)
                {
                    signal.Set();
                }
                return;
            }

            Color[,] pixels = new Color[16, 16];

            highest = ((highest + 1) * 16) - 1;

            TAG biomes = null;

            c.Root["Level"].TryGetValue("Biomes", out biomes);

            for (int z = 0; z < 16; z++)
            {
                for (int x = 0; x < 16; x++)
                {
                    int y;
                    if (c.ManualHeightmap[x + z * 16] >= 0)
                    {
                        y = c.ManualHeightmap[x + z * 16];
                    }
                    else
                    {
                        y = GetHeight(sections, x, z, highest);
                        c.ManualHeightmap[x + z * 16] = y;
                    }

                    if (y < 0)
                    {
                        continue;
                    }
                    byte id, data;
                    GetBlock(sections, x, y, z, out id, out data);
                    byte biome = (byte)Biome.Unspecified;
                    if (biomes != null && Settings.BiomeFoliage)
                    {
                        biome = ((byte[])biomes)[x + z * 16];
                    }

                    Color color = ColorPalette.Lookup(id, data, biome);

                    if (Settings.Transparency)
                    {
                        y--;
                        while (color.A < 255 && y >= 0)
                        {
                            GetBlock(sections, x, y, z, out id, out data);
                            Color c2 = ColorPalette.Lookup(id, data, biome);
                            color = Blend(color, c2);
                            y--;
                        }
                    }
                    else
                    {
                        color = Color.FromArgb(255, color.R, color.G, color.B);
                    }

                    //brighten/darken by height; arbitrary value, but /seems/ to look okay
                    color = AddtoColor(color, (int)(y / 1.7 - 42));

                    pixels[x, z] = color;
                }
            }

            mutex.WaitOne();
            for (int z = 0; z < 16; z++)
            {
                for (int x = 0; x < 16; x++)
                {
                    b.SetPixel(offsetX + x, offsetY + z, pixels[x, z]);
                }
            }
            mutex.ReleaseMutex();

            if (Interlocked.Decrement(ref taskCount) == 0)
            {
                signal.Set();
            }
        }