2011-04-30 05:18:30 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Substrate;
|
|
|
|
|
|
2011-06-02 07:35:25 +00:00
|
|
|
|
// This example is a tool to delete all entities of a given type (e.g., "pig")
|
|
|
|
|
// on a map. It optionally can be restricted to boxed region in block coords.
|
|
|
|
|
// Only 10% of the effort is actually spend purging anything.
|
|
|
|
|
|
2011-04-30 05:18:30 +00:00
|
|
|
|
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];
|
|
|
|
|
|
2011-06-02 07:35:25 +00:00
|
|
|
|
// Our initial bounding box is "infinite"
|
2011-04-30 05:18:30 +00:00
|
|
|
|
int x1 = BlockManager.MIN_X;
|
|
|
|
|
int x2 = BlockManager.MAX_X;
|
|
|
|
|
int z1 = BlockManager.MIN_Z;
|
|
|
|
|
int z2 = BlockManager.MAX_Z;
|
|
|
|
|
|
2011-06-02 07:35:25 +00:00
|
|
|
|
// If we have all coordinate parameters, set the bounding box
|
2011-04-30 05:18:30 +00:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|