コード例 #1
0
        public static void CreateGeometry(IMinecraftCommandService commandService, params string[] args)
        {
            var position = commandService.GetLocation();
            var lines    = new CreateCommandHandler(commandService).Handle(args.ToList().Skip(1).ToArray(), position,
                                                                           new List <SavedPosition>());

            if (lines.Any())
            {
                var _commandFormater = commandService.GetFormater();
                var sw = new Stopwatch();
                sw.Start();
                var lastLine = lines.First();
                foreach (var line in lines)
                {
                    if (lastLine.Start.Distance2D(line.Start) > 100)
                    {
                        commandService.Command($"tp @s {line.Start.X} ~ {line.Start.Z}");
                    }
                    var command = _commandFormater.Fill(line.Start.X, line.Start.Y, line.Start.Z, line.End.X, line.End.Y, line.End.Z, line.Block, line.Block.Contains(" ")?"":"0");
                    commandService.Command(command);
                    lastLine = line;
                }
                sw.Stop();
                commandService.Status($"time to queue commands {sw.Elapsed.TotalSeconds}");
                //Console.WriteLine($"time to queue commands {sw.Elapsed.TotalSeconds}");
                sw.Reset();
                sw.Start();
                commandService.Wait();
                sw.Stop();
                commandService.Status($"time to complete import {sw.Elapsed.TotalSeconds}");
                //Console.WriteLine($"time to complete import {sw.Elapsed.TotalSeconds}");
            }
        }
コード例 #2
0
        public void Handle(string[] args, IMinecraftCommandService minecraftService)
        {
            var position = minecraftService.GetLocation();

            for (var i = 0; i <= RadiusHandler.Radius; i++)
            {
                CreateHandler.CreateGeometry(minecraftService, "create", "circle", $"{i}", "1", "air", $"{position.X}", $"{position.Y+i}", $"{position.Z}");
                //minecraftService.Command($"fill ~-{i} ~{i} ~-{i} ~{i} ~{i} ~{i} air");
            }
        }
コード例 #3
0
        public static void CreateGeometry(IMinecraftCommandService commandService, List <SavedPosition> savedPositions, params string[] args)
        {
            var sw = new Stopwatch();

            sw.Start();
            var position = commandService.GetLocation();

            var commandArgs   = args.Skip(1).ToArray();
            var lines         = new List <Line>();
            var createCommand = (commandArgs.ElementAtOrDefault(0) ?? "").ToLower();

            switch (createCommand)
            {
            case "circle":
                lines = CreateCircle(commandService, commandArgs, position, savedPositions);
                break;

            case "ring":
                lines = CreateRing(commandService, commandArgs, position, savedPositions);
                break;

            case "walls":
                lines = CreateWalls(commandService, commandArgs, position, savedPositions);
                break;

            case "outline":
                lines = CreateBox(commandService, commandArgs, position, savedPositions, false);
                break;

            case "box":
                lines = CreateBox(commandService, commandArgs, position, savedPositions, true);
                break;

            case "floor":
                lines = CreateFloor(commandService, commandArgs, position, savedPositions);
                break;

            case "sphere":
                lines = CreateSphere(commandService, commandArgs, position, savedPositions);
                break;

            case "merlon":
                lines = CreateMerlon(commandService, commandArgs, position, savedPositions);
                break;

            case "maze":
                lines = CreateMaze(commandService, commandArgs, position, savedPositions);
                break;

            case "house":
                lines = CreateHouse(commandService, commandArgs, position, savedPositions);
                break;

            case "triangle":
                lines = CreateTriangle(commandService, commandArgs, position, savedPositions);
                break;

            case "poly":
            case "polygon":
                lines = CreatePoly(commandService, commandArgs, position, savedPositions);
                break;

            default:
                commandService.Status("CREATE\n" +
                                      "create circle\n" +
                                      "create ring\n" +
                                      "create walls\n" +
                                      "create outline\n" +
                                      "create box\n" +
                                      "create floor\n" +
                                      "create sphere\n" +
                                      "create merlon\n" +
                                      "create triangle\n" +
                                      "create [poly|polygon]\n" +
                                      "create maze"
                                      );
                return;
            }

            if (!lines.Any())
            {
                return;
            }
            LogTime(commandService, sw, $"CREATE {createCommand.ToUpper()}: time to get lines to render: {sw.Elapsed.TotalSeconds}");

            var commandFormater = commandService.GetFormater();

            var lastLine = lines.First();

            foreach (var line in lines)
            {
                if (lastLine.Start.Distance2D(line.Start) > 100)
                {
                    commandService.Command($"tp @s {line.Start.X} ~ {line.Start.Z}");
                }

                var command = commandFormater.Fill(line.Start.X, line.Start.Y, line.Start.Z, line.End.X, line.End.Y,
                                                   line.End.Z, line.Block, line.Block.Contains(" ") ? "" : "0");
                // TODO: Identify the limitation here and account for it.
                // Should this be executed on a thread so that other commands can be processed at the same time?
                // Is that possible?
                commandService.Command(command);
                lastLine = line;
            }

            LogTime(commandService, sw, $"CREATE {createCommand.ToUpper()}: time to queue commands: {sw.Elapsed.TotalSeconds}");

            commandService.Wait();
            LogTime(commandService, sw, $"CREATE {createCommand.ToUpper()}: time to complete import: {sw.Elapsed.TotalSeconds}");
        }