Beispiel #1
0
        public void WriteWorldSave(string path, int playerPosX, int playerPosZ)
        {
            Directory.CreateDirectory(path);

            int y = GetRegionAt(playerPosX, playerPosZ).GetChunk(playerPosX % 512, playerPosZ % 512, false).GetHighestBlock(playerPosX % 16, playerPosZ % 16);

            levelDat = CreateLevelDAT(playerPosX, y + 1, playerPosZ, true);

            List <byte> levelDATBytes = new List <byte>();

            levelDat.WriteToBytes(levelDATBytes, false);
            var compressedLevelDAT = GZipStream.CompressBuffer(levelDATBytes.ToArray());

            File.WriteAllBytes(Path.Combine(path, "level.dat"), compressedLevelDAT);

            Directory.CreateDirectory(Path.Combine(path, "region"));

            var options = new ParallelOptions()
            {
                MaxDegreeOfParallelism = 4
            };

            Parallel.ForEach(regions, options, (KeyValuePair <RegionLocation, Region> region) =>
            {
                string name = $"r.{region.Key.x}.{region.Key.z}.mca";
                using (var stream = new FileStream(Path.Combine(path, "region", name), FileMode.Create))
                {
                    RegionSerializer.WriteRegionToStream(region.Value, stream, gameVersion);
                }
            });
        }
        public void Run()
        {
            MCUtilsConsole.WriteLine("Size of block patches (1-4):");
            size = int.Parse(MCUtilsConsole.GetInput());
            size = Math.Max(1, Math.Min(4, size));
            MCUtilsConsole.WriteLine("Enter path to output file:");
            string savepath = GetFilePath(true);

            MCUtilsConsole.WriteLine("Starting...");
            region = new Region(0, 0);
            FillWithRandomBlocks();
            MCUtilsConsole.WriteLine("Writing file...");
            FileStream stream = new FileStream(savepath, FileMode.Create);

            RegionSerializer.WriteRegionToStream(region, stream, Version.DefaultVersion);
            stream.Close();
            MCUtilsConsole.WriteLine("Done");
        }
		public void Run()
		{
			MCUtilsConsole.WriteLine("Enter path to region file 1:");
			string r1 = GetFilePath(false);
			if (r1 == null) return;
			MCUtilsConsole.WriteLine("Enter path to region file 2:");
			string r2 = GetFilePath(false);
			if (r2 == null) return;
			MCUtilsConsole.WriteLine("Enter path to map image:");
			string map = GetFilePath(false);
			if (map == null) return;
			MCUtilsConsole.WriteLine("Enter path to output file:");
			string savepath = GetFilePath(true);
			MCUtilsConsole.WriteLine("Starting merge...");
			Region region1;
			Region region2;
			try
			{
				region1 = RegionLoader.LoadRegion(r1);
				region2 = RegionLoader.LoadRegion(r2);
			}
			catch (Exception e)
			{
				MCUtilsConsole.WriteError("Failed to open region file(s):");
				MCUtilsConsole.WriteError(e.ToString());
				return;
			}
			Bitmap mask = new Bitmap(map);
			var merger = new RegionMerger(region1, region2, mask);
			MCUtilsConsole.WriteLine("Merging ...");
			var mergedRegion = merger.Merge();
			MCUtilsConsole.WriteLine("Writing file...");
			FileStream stream = new FileStream(savepath, FileMode.Create);
			RegionSerializer.WriteRegionToStream(mergedRegion, stream, Version.DefaultVersion);
			stream.Close();
			MCUtilsConsole.WriteLine("Done");
		}
Beispiel #4
0
 public void WriteRegionFile(FileStream stream, int regionPosX, int regionPosZ)
 {
     RegionSerializer.WriteRegionToStream(regions[new RegionLocation(regionPosX, regionPosZ)], stream, gameVersion);
 }
Beispiel #5
0
        public void Run()
        {
            MCUtilsConsole.WriteLine("Enter path to world 1's region files:");
            world1Path = GetFilePath(true);
            if (world1Path == null)
            {
                return;
            }
            MCUtilsConsole.WriteLine("Enter path to world 2's region files:");
            world2Path = GetFilePath(true);
            if (world2Path == null)
            {
                return;
            }

            MCUtilsConsole.WriteLine("Enter the lower coordinate for the merge (inclusive):");
            lowerBound = ParseCoordinates(MCUtilsConsole.GetInput());
            MCUtilsConsole.WriteLine("Enter the upper coordinate for the merge (inclusive):");
            upperBound = ParseCoordinates(MCUtilsConsole.GetInput());

            int sizeX = upperBound.x - lowerBound.x + 1;
            int sizeZ = upperBound.z - lowerBound.z + 1;

            MCUtilsConsole.WriteLine($"Enter path to map image (Must be {sizeX * 512}x{sizeZ * 512} or {sizeX * 32}x{sizeZ * 32}:");
            string map = GetFilePath(false);

            if (map == null)
            {
                return;
            }
            Bitmap worldMergeMap = new Bitmap(map);
            byte   mergeMode     = 0;

            if (worldMergeMap.Width == sizeX * 512 && worldMergeMap.Height == sizeZ * 512)
            {
                mergeMode = 1;
            }
            if (worldMergeMap.Width == sizeX * 32 && worldMergeMap.Height == sizeZ * 32)
            {
                mergeMode = 2;
            }
            if (mergeMode == 0)
            {
                MCUtilsConsole.WriteError("Map was not the correct size!");
                return;
            }

            MCUtilsConsole.WriteLine("Enter path to output file:");
            outputPath = GetFilePath(true);

            List <RegionRecord> records = new List <RegionRecord>();

            for (int rz = lowerBound.z; rz <= upperBound.z; rz++)
            {
                for (int rx = lowerBound.x; rx <= upperBound.x; rx++)
                {
                    records.Add(new RegionRecord(this, rx, rz));
                }
            }

            int w1only    = 0;
            int w2only    = 0;
            int mergeable = 0;

            foreach (var r in records)
            {
                if (r.CanMerge)
                {
                    mergeable++;
                }
                else
                {
                    if (r.existsInWorld1)
                    {
                        w1only++;
                    }
                    else if (r.existsInWorld2)
                    {
                        w2only++;
                    }
                }
            }

            if (w1only > 0)
            {
                MCUtilsConsole.WriteWarning($"There are {w1only} regions that only exist in world 1.");
            }
            if (w2only > 0)
            {
                MCUtilsConsole.WriteWarning($"There are {w2only} regions that only exist in world 2.");
            }
            MCUtilsConsole.WriteLine($"{mergeable} out of {records.Count} can be merged. Press any key to start.");
            Console.ReadKey();

            MCUtilsConsole.WriteLine("Starting world merge...");
            foreach (var r in records)
            {
                int    localX  = r.loc.x - lowerBound.x;
                int    localZ  = r.loc.z - lowerBound.z;
                int    scale   = mergeMode == 1 ? 512 : 32;
                Bitmap section = worldMergeMap.Clone(new Rectangle(localX * scale, localZ * scale, scale, scale), worldMergeMap.PixelFormat);

                MCUtilsConsole.WriteLine($"Merging {r.loc.x}.{r.loc.z}.mca ...");
                var region1      = RegionLoader.LoadRegion(Path.Combine(world1Path, r.filename));
                var region2      = RegionLoader.LoadRegion(Path.Combine(world2Path, r.filename));
                var merger       = new RegionMerger(region1, region2, section);
                var mergedRegion = merger.Merge();

                MCUtilsConsole.WriteLine("Writing file...");
                FileStream stream = new FileStream(Path.Combine(outputPath, r.filename), FileMode.Create);
                RegionSerializer.WriteRegionToStream(mergedRegion, stream, Version.DefaultVersion);
                stream.Close();
            }
        }