示例#1
0
        public void RecordBiomeState(RegionFile region, String description)
        {
            BiomeAction action = new BiomeAction(description);

            for (int chunkX = 0; chunkX < 32; chunkX++)
            {
                for (int chunkZ = 0; chunkZ < 32; chunkZ++)
                {
                    Chunk c = region.Chunks[chunkX, chunkZ];
                    if (c == null || c.Root == null)
                    {
                        continue;
                    }

                    //first point of accessing chunk's biomes, make sure it exists
                    TAG_Compound level = (TAG_Compound)c.Root["Level"];
                    byte[]       biomes;
                    if (level.Payload.ContainsKey("Biomes"))
                    {
                        biomes = (byte[])level["Biomes"];
                    }
                    else
                    {
                        biomes = new byte[256];
                        for (int i = 0; i < biomes.Length; i++)
                        {
                            biomes[i] = (byte)Biome.Unspecified;
                        }
                        level.Payload.Add("Biomes", new TAG_Byte_Array(biomes, "Biomes"));
                    }

                    action.Chunks.Add(new ChunkState(chunkX, chunkZ, (byte[])biomes.Clone()));
                }
            }
            Add(action);
            OnChange();
        }
示例#2
0
        private void RenderChunk(Chunk c, Bitmap b, int offsetX, int offsetY)
        {
            int[]          heightmap = (int[])c.Root["Level"]["HeightMap"];
            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;
            }

            //chunk exists but all blocks are air
            if (highest < 0)
            {
                return;
            }

            highest = ((highest + 1) * 16) - 1;
            if (highest > UpperLimit)
            {
                highest = UpperLimit;
            }
            if (highest < LowerLimit)
            {
                highest = LowerLimit;
            }

            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 = GetHeight(sections, x, z, highest, LowerLimit, Only, Exclude);
                    if (y < LowerLimit)
                    {
                        continue;
                    }
                    byte id, data;
                    GetBlock(sections, x, y, z, out id, out data);
                    byte biome = 255;
                    if (ConsiderBiomes && biomes != null)
                    {
                        biome = ((byte[])biomes)[x + z * 16];
                    }

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

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

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

                    b.SetPixel(offsetX + x, offsetY + z, color);
                }
            }
        }
示例#3
0
        public static void AddorRemoveBlocksSelection(RegionFile region, Bitmap b, Color selectionColor, int[] blockIds, bool add)
        {
            if (blockIds == null || blockIds.Length == 0)
            {
                return;
            }

            List <int> ids = new List <int>(blockIds);

            foreach (Chunk c in region.Chunks)
            {
                if (c.Root == null)
                {
                    continue;
                }
                Coord chunkOffset = new Coord(region.Coords);
                chunkOffset.RegiontoChunk();
                chunkOffset = new Coord(c.Coords.X - chunkOffset.X, c.Coords.Z - chunkOffset.Z);
                chunkOffset.ChunktoAbsolute();

                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;
                }

                //chunk exists but all blocks are air
                if (highest < 0)
                {
                    return;
                }

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

                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;
                        }

                        if (ids.Contains(GetBlock(sections, x, y, z)))
                        {
                            b.SetPixel(OFFSETX + chunkOffset.X + x, OFFSETY + chunkOffset.Z + z, add ? selectionColor : Color.Transparent);
                        }
                    }
                }
            }
        }
示例#4
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();
            }
        }
示例#5
0
文件: Block.cs 项目: Micalobia/Cript
 public Block(string blockID, TAG_Compound blockTag)
 {
     BlockID     = blockID;
     BlockTag    = blockTag;
     BlockStates = new Dictionary <string, object>();
 }