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}"); } }
public void OnConnection() { _minecraftService.Command(_minecraftService.GetFormater().Title(_serverName + " Started", "")); foreach (var subscription in _eventSubscriptions) { Console.WriteLine($"subscibing to {subscription}"); _minecraftService.Subscribe((new SubscribeMessage(subscription.ToString())).ToString()); Thread.Sleep(100); } }
private void CommandTest(IEnumerable <string> args, Position position) { var target = position.GetAbsolutePosition(args.Take(3)); var shift = GetShiftPosition(args.Skip(3).Take(3)); // analyze then import all schematics in the folder. var filesToProcess = GetSchematics().Select(a => new { Points = LoadFile(a), Filename = a }) .ToList() .Select(a => new { a.Filename, a.Points, Analysis = ModelAnalyzer.Analyze(a.Points) }) .OrderBy(a => a.Analysis.TotalPlaceableBlocks) .ToList(); foreach (var f in filesToProcess) { _commandService.Command( $"tp @s {target.X + f.Analysis.Width / 2} {target.Y + f.Analysis.Height} {target.Z - 5}"); _commandService.Status($"importing {Path.GetFileName(f.Filename)}"); SendCommandsToCodeConnection(target, f.Points, Rotate.None, shift); target.X += f.Analysis.Width + 15; } }
public void Handle(string[] args, IMinecraftCommandService minecraftService) { minecraftService.Command("getchunks overworld"); minecraftService.Command("getchunkdata overworld ~ ~ ~"); }
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}"); }
public void SchematicCommandProcessor(string[] args) { // var s = new MinecraftCodeConnectionCommandService(); var target = new Position(0, 0, 0); var shift = new Position(0, 0, 0); var rotation = Rotate.None; var command = args[0]; switch (command) { case "list": var files = Directory.GetFiles(ConfigurationManager.AppSettings["data"], "*.schematic"); _minecraftCommandService .Status("Schematics: " + files.Select(b => $"\n" + Path.GetFileName(b)) .OrderBy(a => a) .Aggregate((a, b) => a += b)); break; case "analyze": { var points = LoadFile(args[1]); var results = ModelAnalyzer.Analyze(points); var firstGroundLayer = results.Layers.First(a => a.Blocks.Any(b => b.Block.Equals("air") && b.PercentOfLayer >= 0.5)) .Y; string output = $"{Path.GetFileName(args[1])} Model Size: X:{results.Width} Y:{results.Height} Z:{results.Length} Ground Level:{firstGroundLayer} Total Blocks:{results.Width*results.Height*results.Length}"; _minecraftCommandService.Status(output); break; } case "outline": Outline(args, target, shift); break; case "import": Import(args, target, rotation, shift); break; case "test": //analyze then import all schematics in the folder. var x = int.Parse(args[1]); var y = int.Parse(args[2]); var z = int.Parse(args[3]); var files1 = Directory.GetFiles(ConfigurationManager.AppSettings["data"], "*.schematic"); var filesToProcess = files1.Select(a => new { Points = LoadFile(a), Filename = a }) .ToList() .Select(a => new { a.Filename, a.Points, Analysis = ModelAnalyzer.Analyze(a.Points) }) .OrderBy(a => a.Analysis.TotalPlaceableBlocks) .ToList(); foreach (var f in filesToProcess) { target.X = x; target.Y = y; target.Z = z; _minecraftCommandService.Command( $"tp @s {x + f.Analysis.Width/2} {y + f.Analysis.Height} {z - 5}"); _minecraftCommandService.Status($"importing {Path.GetFileName(f.Filename)}"); SendCommandsToCodeConnection(target, f.Points, rotation, shift); var results = f.Analysis; x = x + results.Width + 15; } break; default: _minecraftCommandService.Status("schematic command\n" + "schematic list\n" + "schematic analyze [name]\n" + "schematic import name x y z (rotation) (Shift X) (Shift Y) (Shift Z)"); break; } }