2011-06-02 20:08:06 +00:00
|
|
|
|
using System;
|
|
|
|
|
using Substrate;
|
2011-07-24 20:03:47 +00:00
|
|
|
|
using Substrate.Core;
|
|
|
|
|
using Substrate.Nbt;
|
2012-04-29 00:35:57 +00:00
|
|
|
|
using System.IO;
|
2011-06-02 20:08:06 +00:00
|
|
|
|
|
|
|
|
|
// This example will convert worlds between alpha and beta format.
|
|
|
|
|
// This will convert chunks to and from region format, and copy level.dat
|
|
|
|
|
// Other data, like players and other dims, will not be handled.
|
|
|
|
|
|
|
|
|
|
namespace Convert
|
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
|
|
|
|
static void Main (string[] args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Length != 3) {
|
2012-04-29 00:35:57 +00:00
|
|
|
|
Console.WriteLine("Usage: Convert <world> <dest> <alpha|beta|anvil>");
|
2011-06-02 20:08:06 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string src = args[0];
|
|
|
|
|
string dst = args[1];
|
|
|
|
|
string srctype = args[2];
|
|
|
|
|
|
2012-04-29 00:35:57 +00:00
|
|
|
|
if (!Directory.Exists(dst))
|
|
|
|
|
Directory.CreateDirectory(dst);
|
|
|
|
|
|
2011-06-02 20:08:06 +00:00
|
|
|
|
// Open source and destrination worlds depending on conversion type
|
2012-04-29 00:35:57 +00:00
|
|
|
|
NbtWorld srcWorld = NbtWorld.Open(src);
|
2011-07-24 20:03:47 +00:00
|
|
|
|
NbtWorld dstWorld;
|
2012-04-29 00:35:57 +00:00
|
|
|
|
switch (srctype) {
|
|
|
|
|
case "alpha": dstWorld = AlphaWorld.Create(dst); break;
|
|
|
|
|
case "beta": dstWorld = BetaWorld.Create(dst); break;
|
|
|
|
|
case "anvil": dstWorld = AnvilWorld.Create(dst); break;
|
|
|
|
|
default: throw new Exception("Invalid conversion type");
|
2011-06-02 20:08:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Grab chunk managers to copy chunks
|
|
|
|
|
IChunkManager cmsrc = srcWorld.GetChunkManager();
|
|
|
|
|
IChunkManager cmdst = dstWorld.GetChunkManager();
|
|
|
|
|
|
|
|
|
|
// Copy each chunk from source to dest
|
|
|
|
|
foreach (ChunkRef chunk in cmsrc) {
|
|
|
|
|
cmdst.SetChunk(chunk.X, chunk.Z, chunk.GetChunkRef());
|
2012-04-29 00:35:57 +00:00
|
|
|
|
Console.WriteLine("Copying chunk: {0}, {1}", chunk.X, chunk.Z);
|
2011-06-02 20:08:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Copy level data from source to dest
|
|
|
|
|
dstWorld.Level.LoadTreeSafe(srcWorld.Level.BuildTree());
|
|
|
|
|
|
|
|
|
|
// Save level.dat
|
|
|
|
|
dstWorld.Level.Save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|