Resyncing nbtoolkit

This commit is contained in:
Justin Aquadro 2011-04-13 05:04:56 +00:00
parent 44ba6eac4e
commit 4141175491
8 changed files with 26 additions and 104 deletions

View file

@ -96,8 +96,9 @@ namespace NBToolkit
public override void Run () public override void Run ()
{ {
NBTWorld world = GetWorld(opt); INBTWorld world = GetWorld(opt);
FilteredChunkManager fcm = new FilteredChunkManager(world.ChunkManager, opt.GetChunkFilter()); IChunkManager cm = world.GetChunkManager(opt.OPT_DIM);
FilteredChunkManager fcm = new FilteredChunkManager(cm, opt.GetChunkFilter());
StreamWriter fstr; StreamWriter fstr;
try { try {

View file

@ -7,7 +7,7 @@ namespace NBToolkit
{ {
public interface IGenerator public interface IGenerator
{ {
bool Generate (BlockManager blockMan, Random rand, int x, int y, int z); bool Generate (IBlockManager blockMan, Random rand, int x, int y, int z);
} }
/** /**
@ -49,7 +49,7 @@ namespace NBToolkit
} }
} }
public bool Generate (BlockManager blockMan, Random rand, int x, int y, int z) public bool Generate (IBlockManager blockMan, Random rand, int x, int y, int z)
{ {
float rpi = (float)(rand.NextDouble() * Math.PI); float rpi = (float)(rand.NextDouble() * Math.PI);

View file

@ -53,8 +53,6 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Dump.cs" /> <Compile Include="Dump.cs" />

View file

@ -181,8 +181,9 @@ namespace NBToolkit
public override void Run () public override void Run ()
{ {
NBTWorld world = GetWorld(opt); INBTWorld world = GetWorld(opt);
FilteredChunkManager fcm = new FilteredChunkManager(world.ChunkManager, opt.GetChunkFilter()); IChunkManager cm = world.GetChunkManager(opt.OPT_DIM);
FilteredChunkManager fcm = new FilteredChunkManager(cm, opt.GetChunkFilter());
int affectedChunks = 0; int affectedChunks = 0;
foreach (ChunkRef chunk in fcm) { foreach (ChunkRef chunk in fcm) {
@ -204,7 +205,7 @@ namespace NBToolkit
Console.WriteLine("Affected Chunks: " + affectedChunks); Console.WriteLine("Affected Chunks: " + affectedChunks);
} }
public void ApplyChunk (NBTWorld world, ChunkRef chunk) public void ApplyChunk (INBTWorld world, ChunkRef chunk)
{ {
if (opt.OPT_V) { if (opt.OPT_V) {
Console.WriteLine("Generating {0} size {1} deposits of {2} between {3} and {4}", Console.WriteLine("Generating {0} size {1} deposits of {2} between {3} and {4}",
@ -221,7 +222,8 @@ namespace NBToolkit
((NativeGenOre)generator).MathFix = opt.OPT_MATHFIX; ((NativeGenOre)generator).MathFix = opt.OPT_MATHFIX;
} }
BlockManager bm = new GenOreBlockManager(world.ChunkManager, opt); IChunkManager cm = world.GetChunkManager(opt.OPT_DIM);
IBlockManager bm = new GenOreBlockManager(cm, opt);
for (int i = 0; i < opt.OPT_ROUNDS; i++) { for (int i = 0; i < opt.OPT_ROUNDS; i++) {
if (opt.OPT_VV) { if (opt.OPT_VV) {
@ -292,84 +294,5 @@ namespace NBToolkit
return false; return false;
} }
/*public override BlockRef GetBlockRef (int x, int y, int z)
{
BlockRef block;
try {
block = base.GetBlockRef(x, y, z);
}
catch {
return null;
}
if (block == null) {
return null;
}
int blockID = block.ID;
if (
((opt.OPT_OA) && (blockID != opt.OPT_ID)) ||
((opt.OPT_OO) && (
blockID == BLOCK_COAL || blockID == BLOCK_IRON ||
blockID == BLOCK_GOLD || blockID == BLOCK_REDSTONE ||
blockID == BLOCK_DIAMOND || blockID == BLOCK_LAPIS ||
blockID == BLOCK_DIRT || blockID == BLOCK_GRAVEL) && (blockID != opt.OPT_ID)) ||
(opt.OPT_OB_INCLUDE.Count > 0) ||
(blockID == BLOCK_STONE)
) {
// If overriding list of ores, check membership
if (opt.OPT_OB_INCLUDE.Count > 0 && !opt.OPT_OB_INCLUDE.Contains(blockID)) {
return null;
}
// Check for any excluded block
if (opt.OPT_OB_EXCLUDE.Contains(blockID)) {
return null;
}
// We're allowed to update the block
return block;
}
return null;
}
public override bool SetBlockID (int x, int y, int z, int id)
{
int blockID = 0;
try {
blockID = GetBlockID(x, y, z);
}
catch {
return false;
}
if (
((opt.OPT_OA) && (blockID != opt.OPT_ID)) ||
((opt.OPT_OO) && (
blockID == BLOCK_COAL || blockID == BLOCK_IRON ||
blockID == BLOCK_GOLD || blockID == BLOCK_REDSTONE ||
blockID == BLOCK_DIAMOND || blockID == BLOCK_LAPIS ||
blockID == BLOCK_DIRT || blockID == BLOCK_GRAVEL) && (blockID != opt.OPT_ID)) ||
(opt.OPT_OB_INCLUDE.Count > 0) ||
(blockID == BLOCK_STONE)
) {
// If overriding list of ores, check membership
if (opt.OPT_OB_INCLUDE.Count > 0 && !opt.OPT_OB_INCLUDE.Contains(blockID)) {
return false;
}
// Check for any excluded block
if (opt.OPT_OB_EXCLUDE.Contains(blockID)) {
return false;
}
// We're allowed to update the block
return base.SetBlockID(x, y, z, id);
}
return false;
}*/
} }
} }

View file

@ -69,8 +69,9 @@ namespace NBToolkit
public override void Run () public override void Run ()
{ {
NBTWorld world = GetWorld(opt); INBTWorld world = GetWorld(opt);
FilteredChunkManager fcm = new FilteredChunkManager(world.ChunkManager, opt.GetChunkFilter()); IChunkManager cm = world.GetChunkManager(opt.OPT_DIM);
FilteredChunkManager fcm = new FilteredChunkManager(cm, opt.GetChunkFilter());
int affectedChunks = 0; int affectedChunks = 0;
foreach (ChunkRef chunk in fcm) { foreach (ChunkRef chunk in fcm) {

View file

@ -149,8 +149,9 @@ namespace NBToolkit
public override void Run () public override void Run ()
{ {
NBTWorld world = GetWorld(opt); INBTWorld world = GetWorld(opt);
FilteredChunkManager fcm = new FilteredChunkManager(world.ChunkManager, opt.GetChunkFilter()); IChunkManager cm = world.GetChunkManager(opt.OPT_DIM);
FilteredChunkManager fcm = new FilteredChunkManager(cm, opt.GetChunkFilter());
int affectedChunks = 0; int affectedChunks = 0;
foreach (ChunkRef chunk in fcm) { foreach (ChunkRef chunk in fcm) {
@ -164,7 +165,7 @@ namespace NBToolkit
Console.WriteLine("Affected Chunks: " + affectedChunks); Console.WriteLine("Affected Chunks: " + affectedChunks);
} }
public void ApplyChunk (World world, ChunkRef chunk) public void ApplyChunk (INBTWorld world, ChunkRef chunk)
{ {
int xBase = chunk.X * chunk.XDim; int xBase = chunk.X * chunk.XDim;
int zBase = chunk.Z * chunk.ZDim; int zBase = chunk.Z * chunk.ZDim;
@ -242,7 +243,8 @@ namespace NBToolkit
chunk.SetBlockID(lx, ly, lz, (int)opt.OPT_AFTER); chunk.SetBlockID(lx, ly, lz, (int)opt.OPT_AFTER);
if (opt.OPT_VV) { if (opt.OPT_VV) {
Console.WriteLine("Replaced block at {0},{1},{2}", lx, ly, lz); Console.WriteLine("Replaced block at {0},{1},{2}",
chunk.BlockGlobalX(lx), chunk.BlockGlobalY(ly), chunk.BlockGlobalZ(lz));
} }
if (opt.OPT_DATA != null) { if (opt.OPT_DATA != null) {

View file

@ -11,15 +11,15 @@ namespace NBToolkit
public abstract void Run (); public abstract void Run ();
public NBTWorld GetWorld (TKOptions opt) public INBTWorld GetWorld (TKOptions opt)
{ {
NBTWorld world = null; INBTWorld world = null;
try { try {
if (opt.OPT_ALPHA) { if (opt.OPT_ALPHA) {
world = new AlphaWorld(opt.OPT_WORLD, opt.OPT_DIM); world = AlphaWorld.Open(opt.OPT_WORLD);
} }
else { else {
world = new BetaWorld(opt.OPT_WORLD, opt.OPT_REGION, opt.OPT_DIM); world = BetaWorld.Open(opt.OPT_WORLD);
} }
} }
catch (Exception ex) { catch (Exception ex) {

View file

@ -17,8 +17,7 @@ namespace NBToolkit
private OptionSet commonOpt = null; private OptionSet commonOpt = null;
public string OPT_WORLD = ""; public string OPT_WORLD = "";
public string OPT_REGION = "region"; public int OPT_DIM = 0;
public string OPT_DIM = "";
// Verbosity // Verbosity
public bool OPT_V = false; public bool OPT_V = false;
@ -37,9 +36,7 @@ namespace NBToolkit
{ "alpha", "Specify that the world is stored as individual chunk files", { "alpha", "Specify that the world is stored as individual chunk files",
v => OPT_ALPHA = true }, v => OPT_ALPHA = true },
{ "nether", "Update the Nether instead of the main region", { "nether", "Update the Nether instead of the main region",
v => OPT_DIM = "DIM-1" }, v => OPT_DIM = -1 },
{ "region", "Specify the name of the region directory",
v => OPT_REGION = v },
{ "v", "Verbose output", { "v", "Verbose output",
v => OPT_V = true }, v => OPT_V = true },
{ "vv", "Very verbose output", { "vv", "Very verbose output",