RegiontoChunk() public method

public RegiontoChunk ( ) : void
return void
Esempio n. 1
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);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public static void AddorRemoveBiomesSelection(RegionFile region, Bitmap b, Color selectionColor, byte biome, bool add)
        {
            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();

                byte[] biomes = (byte[])c.Root["Level"]["Biomes"];

                for (int z = 0; z < 16; z++)
                {
                    for (int x = 0; x < 16; x++)
                    {
                        if(biome == biomes[x + z * 16])
                            b.SetPixel(OFFSETX + chunkOffset.X + x, OFFSETY + chunkOffset.Z + z, add ? selectionColor : Color.Transparent);
                    }
                }
            }
        }
Esempio n. 3
0
        private static void Replace(RegionFile region, Bitmap selection, Color selectionColor, byte search, BiomeUtil replace)
        {
            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();

                Coord chunkAbs = new Coord(c.Coords);
                chunkAbs.ChunktoAbsolute();

                byte[] biomes = (byte[])c.Root["Level"]["Biomes"];

                for (int z = 0; z < 16; z++)
                {
                    for (int x = 0; x < 16; x++)
                    {
                        if (selection == null || (selection.GetPixel(OFFSETX + chunkOffset.X + x, OFFSETY + chunkOffset.Z + z).ToArgb() == selectionColor.ToArgb()))
                        {
                            if (biomes[x + z * 16] == search)
                            {
                                biomes[x + z * 16] = (byte)replace.GetBiome(chunkAbs.X + x, chunkAbs.Z + z);
                            }
                        }
                    }
                }
            }
        }