fCraft.DrawCommands.DrawCuboid C# (CSharp) Method

DrawCuboid() static private method

static private DrawCuboid ( Player player, Position marks, object tag ) : void
player Player
marks Position
tag object
return void
        internal static void DrawCuboid( Player player, Position[] marks, object tag ) {
            player.drawingInProgress = true;
            Block drawBlock = (Block)tag;

            // 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 blocks;
            byte block;
            int step = 8;

            blocks = (ex - sx + 1) * (ey - sy + 1) * (eh - sh + 1);
            if( blocks > 2000000 ) {
                player.Message( "NOTE: This draw command is too massive to undo." );
            }

            for( int x = sx; x <= ex; x += step ) {
                for( int y = sy; y <= ey; y += step ) {
                    for( int h = sh; h <= eh; h += step ) {

                        for( int h3 = 0; h3 < step && h + h3 <= eh; h3++ ) {
                            for( int y3 = 0; y3 < step && y + y3 <= ey; y3++ ) {
                                for( int x3 = 0; x3 < step && x + x3 <= ex; x3++ ) {
                                    block = player.world.map.GetBlock( x + x3, y + y3, h + h3 );
                                    if( block == (byte)drawBlock ) continue;
                                    if( block == (byte)Block.Admincrete && !player.Can( Permissions.DeleteAdmincrete ) ) continue;
                                    player.drawUndoBuffer.Enqueue( new BlockUpdate( Player.Console, x + x3, y + y3, h + h3, block ) );
                                    player.world.map.QueueUpdate( new BlockUpdate( Player.Console, x + x3, y + y3, h + h3, (byte)drawBlock ) );
                                }
                            }
                        }

                    }
                }
            }
            player.Message( "Drawing " + blocks + " blocks... The map is now being updated." );
            player.world.log.Log( "{0} initiated drawing a cuboid containing {1} blocks of type {2}.", LogType.UserActivity,
                                  player.name,
                                  blocks,
                                  drawBlock.ToString() );
            GC.Collect();
            player.drawingInProgress = false;
        }