NBTExplorer/Substrate/SubstrateCS/Examples/PurgeEntities/Program.cs

52 lines
1.6 KiB
C#
Raw Normal View History

2011-04-30 05:18:30 +00:00
using System;
using System.Collections.Generic;
using Substrate;
namespace PurgeEntities
{
class Program
{
static void Main (string[] args)
{
// Process arguments
if (args.Length != 2 && args.Length != 6) {
Console.WriteLine("Usage: PurgeEntities <world> <entityID> [<x1> <z1> <x2> <z2>]");
return;
}
string dest = args[0];
string eid = args[1];
int x1 = BlockManager.MIN_X;
int x2 = BlockManager.MAX_X;
int z1 = BlockManager.MIN_Z;
int z2 = BlockManager.MAX_Z;
if (args.Length == 6) {
x1 = Convert.ToInt32(args[2]);
z1 = Convert.ToInt32(args[3]);
x2 = Convert.ToInt32(args[4]);
z2 = Convert.ToInt32(args[5]);
}
// Load world
BetaWorld world = BetaWorld.Open(dest);
ChunkManager cm = world.GetChunkManager();
// Remove entities
foreach (ChunkRef chunk in cm) {
// Skip chunks that don't cover our selected area
2011-06-01 06:11:50 +00:00
if (((chunk.X + 1) * chunk.Blocks.XDim < x1) ||
(chunk.X * chunk.Blocks.XDim >= x2) ||
((chunk.Z + 1) * chunk.Blocks.ZDim < z1) ||
(chunk.Z * chunk.Blocks.ZDim >= z2)) {
2011-04-30 05:18:30 +00:00
continue;
}
// Delete the specified entities
2011-06-01 06:11:50 +00:00
chunk.Entities.RemoveAll(eid);
2011-04-30 05:18:30 +00:00
cm.Save();
}
}
}
}