Show
Code: Select all
public enum DrawMode {
Cuboid,
CuboidHollow,
CuboidWireframe,
Ellipsoid,
Testing, // <----
EllipsoidHollow,
Sphere,
SphereHollow,
Replace,
ReplaceNot,
Line
}
....
cdTesting.Help += GeneralDrawingHelp;
CommandManager.RegisterCommand( cdTesting ); // I tried RegisterCustomCommand too
....
static readonly CommandDescriptor cdTesting = new CommandDescriptor {
Name = "testing",
Aliases = new[] { "test", "qwerty" },
Category = CommandCategory.Building,
Permissions = new[] { Permission.Draw },
Usage = "/testing [BlockName]",
Help = "TESTING " +
"If BlockType is omitted, uses the block that player is holding.",
Handler = Testing
};
internal static void Testing( Player player, Command cmd ) {
Draw( player, cmd, DrawMode.Testing );
}
......
SelectionCallback callback;
switch( mode ) {
case DrawMode.Cuboid:
callback = CuboidCallback;
break;
case DrawMode.Testing:
callback = TestingCallback;
break;
.....
// (it's identical to cuboid)
internal static void TestingCallback( Player player, Position[] marks, object tag ) {
byte drawBlock = (byte)tag;
if( drawBlock == (byte)Block.Undefined ) {
drawBlock = (byte)player.GetBind( player.LastUsedBlockType );
}
// find start/end coordinates
int sx = Math.Min( marks[0].X, marks[1].X );
int ex = Math.Max( marks[0].X, marks[1].X );
int sy = Math.Min( marks[0].Y, marks[1].Y );
int ey = Math.Max( marks[0].Y, marks[1].Y );
int sh = Math.Min( marks[0].H, marks[1].H );
int eh = Math.Max( marks[0].H, marks[1].H );
int volume = (ex - sx + 1) * (ey - sy + 1) * (eh - sh + 1);
if( !player.CanDraw( volume ) ) {
player.MessageNow( "You are only allowed to run draw commands that affect up to {0} blocks. This one would affect {1} blocks.",
player.Info.Rank.DrawLimit,
volume );
return;
}
player.UndoBuffer.Clear();
int blocks = 0, blocksDenied = 0;
bool cannotUndo = false;
for( int x = sx; x <= ex; x += DrawStride ) {
for( int y = sy; y <= ey; y += DrawStride ) {
for( int h = sh; h <= eh; h++ ) {
for( int y3 = 0; y3 < DrawStride && y + y3 <= ey; y3++ ) {
for( int x3 = 0; x3 < DrawStride && x + x3 <= ex; x3++ ) {
DrawOneBlock( player, drawBlock, x + x3, y + y3, h, ref blocks, ref blocksDenied, ref cannotUndo );
}
}
}
}
}
DrawingFinished( player, "drawn", blocks, blocksDenied );
Logger.Log( "{0} drew a plane containing {1} blocks of type {2} (on world {3})", LogType.UserActivity,
player.Name,
blocks,
(Block)drawBlock,
player.World.Name );
}