Ejemplo n.º 1
0
        public override void ProcessRegion(World world, MCUtils.Region reg, int rx, int rz, int pass)
        {
            ConsoleOutput.WriteLine($"Starting merge for region [{rx},{rz}] ...");
            int scale = chunkMode ? 32 : 512;

            bool[,] fraction;
            lock (mask)
            {
                fraction = GetSubMask((rx - upperLeftCornerRegionX) * scale, (rz - upperLeftCornerRegionZ) * scale, scale, scale);
            }
            string otherRegionName = otherRegionPrefix + $"r.{rx}.{rz}.mca";
            var    filename        = Path.Combine(otherRegionFolder, otherRegionName);

            if (File.Exists(filename))
            {
                var otherRegion  = RegionImporter.OpenRegionFile(filename);
                var merger       = new RegionMerger(otherRegion, reg, fraction);
                var mergedRegion = merger.Merge();
                for (int x = 0; x < 32; x++)
                {
                    for (int z = 0; z < 32; z++)
                    {
                        reg.chunks[x, z] = mergedRegion.chunks[x, z];
                    }
                }
            }
            else
            {
                ConsoleOutput.WriteWarning($"Merge region '{otherRegionName}' was not found, no merging was done");
            }
        }
Ejemplo n.º 2
0
        public static Region LoadRegion(string filepath, bool loadOrphanChunks = false)
        {
            RegionData rd;

            using (var stream = File.Open(filepath, FileMode.Open))
            {
                rd = new RegionData(stream, filepath);
            }
            Region region = new Region(rd.regionX, rd.regionZ);

            //TODO: make parallel after testing
            for (int i = 0; i < 1024; i++)
            {
                if (rd.compressedChunks[i] != null)
                {
                    var cd = rd.compressedChunks[i];
                    using (var chunkStream = CreateZLibDecompressionStream(cd.compressedChunk))
                    {
                        region.chunks[i % 32, i / 32] = new ChunkData(region, new NBTContent(chunkStream));
                    }
                }
            }
            return(region);
        }
Ejemplo n.º 3
0
        public static Bitmap GetSurfaceMap(string filepath, HeightmapType surfaceType, bool mcMapShading)
        {
            Region r  = LoadRegion(filepath);
            var    hm = r.GetHeightmapFromNBT(surfaceType);

            for (int z = 0; z < 512; z++)
            {
                for (int x = 0; x < 512; x++)
                {
                    short y = hm[x, z];
                    while (!Blocks.IsBlockForMap(r.GetBlock(x, y, z), surfaceType) && y > 0)
                    {
                        y--;
                    }
                    hm[x, z] = y;
                }
            }
            Bitmap bmp = new Bitmap(512, 512, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            for (int z = 0; z < 512; z++)
            {
                for (int x = 0; x < 512; x++)
                {
                    int y     = hm[x, z];
                    var block = r.GetBlock(x, y, z);
                    if (block.IsAir && y > 0)
                    {
                        throw new ArgumentException("the mapped block was air.");
                    }
                    int shade = 0;

                    if (mcMapShading && z > 0)
                    {
                        if (block.IsWater)
                        {
                            //Water dithering
                            var depth = r.GetWaterDepth(x, y, z);
                            if (depth < 8)
                            {
                                shade = 1;
                            }
                            else if (depth < 16)
                            {
                                shade = 0;
                            }
                            else
                            {
                                shade = -1;
                            }
                            if (depth % 8 >= 4 && shade > -1)
                            {
                                if (x % 2 == z % 2)
                                {
                                    shade--;
                                }
                            }
                        }
                        else
                        {
                            int above = hm[x, z - 1];
                            if (above > y)
                            {
                                shade = -1;
                            }
                            else if (above < y)
                            {
                                shade = 1;
                            }
                        }
                    }
                    bmp.SetPixel(x, z, Blocks.GetMapColor(block, shade));
                }
            }
            return(bmp);
        }
Ejemplo n.º 4
0
        public void ProcessRegion(World world, MCUtils.Region reg, int rx, int rz, int pass)
        {
            var gen = generators[pass];

            gen.ProcessRegion(world, reg, rx, rz, 0);
        }