ChunktoAbsolute() public méthode

public ChunktoAbsolute ( ) : void
Résultat void
Exemple #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);
                        }
                    }
                }
            }
        }
Exemple #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);
                    }
                }
            }
        }
Exemple #3
0
        private Bitmap RenderRegionBiomes(RegionFile region, Bitmap b, int offsetX, int offsetY)
        {
            foreach (Chunk c in region.Chunks)
            {
                if (c == null || c.Root == null)
                    continue;
                Coord chunkOffset = new Coord(c.Coords);
                chunkOffset.ChunktoRegionRelative();
                chunkOffset.ChunktoAbsolute();
                RenderChunkBiomes(c, b, offsetX + chunkOffset.X, offsetY + chunkOffset.Z);
            }

            return b;
        }
Exemple #4
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);
                            }
                        }
                    }
                }
            }
        }
Exemple #5
0
        private static void RenderRegionTerrain(RegionFile region, int chunkStartX, int chunkEndX, int chunkStartZ, int chunkEndZ, int offsetX, int offsetY, Bitmap map)
        {
            if (signal != null || mutex != null || taskCount > 0)
                throw new Exception("RenderRegionTerrain re-entered, shouldn't be possible.");

            signal = new ManualResetEvent(false);
            taskCount = (chunkEndX - chunkStartX + 1) * (chunkEndZ - chunkStartZ + 1);
            mutex = new Mutex();

            for (int x = chunkStartX; x <= chunkEndX; x++)
            {
                for (int z = chunkStartZ; z <= chunkEndZ; z++)
                {
                    Chunk c = region.Chunks[x, z];
                    if (c == null || c.Root == null)
                    {
                        if (Interlocked.Decrement(ref taskCount) == 0)
                            signal.Set();
                        continue;
                    }
                    Coord chunkOffset = new Coord(c.Coords);
                    chunkOffset.ChunktoRegionRelative();
                    chunkOffset = new Coord(chunkOffset.X - chunkStartX, chunkOffset.Z - chunkStartZ);
                    chunkOffset.ChunktoAbsolute();
                    chunkOffset.Add(offsetX, offsetY);

                    ThreadPool.QueueUserWorkItem(RenderChunkTerrain, new Object[]{c, map, chunkOffset.X, chunkOffset.Z});
                }
            }

            signal.WaitOne();
            signal.Dispose();
            signal = null;
            mutex.WaitOne();
            mutex.ReleaseMutex();
            mutex.Dispose();
            mutex = null;
        }
Exemple #6
0
        private static void RenderRegionChunkstobePopulated(RegionFile region, int chunkStartX, int chunkEndX, int chunkStartZ, int chunkEndZ, int offsetX, int offsetY, Bitmap populate)
        {
            using (Graphics g = Graphics.FromImage(populate))
            {
                Brush brush = new SolidBrush(Color.Yellow);
                for (int x = chunkStartX; x <= chunkEndX; x++)
                {
                    for (int z = chunkStartZ; z <= chunkEndZ; z++)
                    {
                        Chunk c = region.Chunks[x, z];
                        if (c == null || c.Root == null)
                            continue;
                        Coord chunkOffset = new Coord(c.Coords);
                        chunkOffset.ChunktoRegionRelative();
                        chunkOffset = new Coord(chunkOffset.X - chunkStartX, chunkOffset.Z - chunkStartZ);
                        chunkOffset.ChunktoAbsolute();
                        chunkOffset.Add(offsetX, offsetY);

                        RenderChunktobePopulated(c, g, brush, chunkOffset.X, chunkOffset.Z);
                    }
                }
                brush.Dispose();
            }
        }
Exemple #7
0
        private static void RenderRegionBiomes(RegionFile region, int chunkStartX, int chunkEndX, int chunkStartZ, int chunkEndZ, int offsetX, int offsetY, Bitmap biomes, String[,] toolTips)
        {
            for (int x = chunkStartX; x <= chunkEndX; x++)
            {
                for (int z = chunkStartZ; z <= chunkEndZ; z++)
                {
                    Chunk c = region.Chunks[x, z];
                    if (c == null || c.Root == null)
                        continue;
                    Coord chunkOffset = new Coord(c.Coords);
                    chunkOffset.ChunktoRegionRelative();
                    chunkOffset = new Coord(chunkOffset.X - chunkStartX, chunkOffset.Z - chunkStartZ);
                    chunkOffset.ChunktoAbsolute();
                    chunkOffset.Add(offsetX, offsetY);

                    RenderChunkBiomes(c, biomes, toolTips, chunkOffset.X, chunkOffset.Z);
                }
            }
        }