From cfdc035617d411917a3f312a5fe3ad7f54450255 Mon Sep 17 00:00:00 2001 From: BruceChen Date: Thu, 29 Sep 2022 23:11:30 +0800 Subject: [PATCH] Upgrade old coordinate parsing. --- MinecraftClient/Commands/Dig.cs | 10 ++++------ MinecraftClient/Commands/Look.cs | 9 +++------ MinecraftClient/Commands/Move.cs | 1 - MinecraftClient/Commands/Useblock.cs | 7 ++----- 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/MinecraftClient/Commands/Dig.cs b/MinecraftClient/Commands/Dig.cs index fc5214fb..eadf13db 100644 --- a/MinecraftClient/Commands/Dig.cs +++ b/MinecraftClient/Commands/Dig.cs @@ -24,16 +24,14 @@ namespace MinecraftClient.Commands { try { - int x = int.Parse(args[0]); - int y = int.Parse(args[1]); - int z = int.Parse(args[2]); - Location blockToBreak = new Location(x, y, z); - if (blockToBreak.DistanceSquared(handler.GetCurrentLocation().EyesLocation()) > 25) + Location current = handler.GetCurrentLocation(); + Location blockToBreak = Location.Parse(current, args[0], args[1], args[2]); + if (blockToBreak.DistanceSquared(current.EyesLocation()) > 25) return Translations.Get("cmd.dig.too_far"); if (handler.GetWorld().GetBlock(blockToBreak).Type == Material.Air) return Translations.Get("cmd.dig.no_block"); if (handler.DigBlock(blockToBreak)) - return Translations.Get("cmd.dig.dig", x, y, z); + return Translations.Get("cmd.dig.dig", blockToBreak.X, blockToBreak.Y, blockToBreak.Z); else return "cmd.dig.fail"; } catch (FormatException) { return GetCmdDescTranslated(); } diff --git a/MinecraftClient/Commands/Look.cs b/MinecraftClient/Commands/Look.cs index d27c09f5..68b1cab4 100644 --- a/MinecraftClient/Commands/Look.cs +++ b/MinecraftClient/Commands/Look.cs @@ -51,12 +51,9 @@ namespace MinecraftClient.Commands { try { - int x = int.Parse(args[0]); - int y = int.Parse(args[1]); - int z = int.Parse(args[2]); - - Location block = new Location(x, y, z); - handler.UpdateLocation(handler.GetCurrentLocation(), block); + Location current = handler.GetCurrentLocation(); + Location block = Location.Parse(current, args[0], args[1], args[2]); + handler.UpdateLocation(current, block); return Translations.Get("cmd.look.block", block); } diff --git a/MinecraftClient/Commands/Move.cs b/MinecraftClient/Commands/Move.cs index 62f4a983..edd95ccd 100644 --- a/MinecraftClient/Commands/Move.cs +++ b/MinecraftClient/Commands/Move.cs @@ -91,7 +91,6 @@ namespace MinecraftClient.Commands try { Location current = handler.GetCurrentLocation(), currentCenter = current.ToCenter(); - Location goal = Location.Parse(current, args[0], args[1], args[2]); if (!Movement.CheckChunkLoading(handler.GetWorld(), current, goal)) diff --git a/MinecraftClient/Commands/Useblock.cs b/MinecraftClient/Commands/Useblock.cs index bf72dd5b..f35ac385 100644 --- a/MinecraftClient/Commands/Useblock.cs +++ b/MinecraftClient/Commands/Useblock.cs @@ -21,11 +21,8 @@ namespace MinecraftClient.Commands string[] args = getArgs(command); if (args.Length >= 3) { - Location current = handler.GetCurrentLocation(); - double x = args[0].StartsWith('~') ? current.X + (args[0].Length > 1 ? double.Parse(args[0][1..]) : 0) : double.Parse(args[0]); - double y = args[1].StartsWith('~') ? current.Y + (args[1].Length > 1 ? double.Parse(args[1][1..]) : 0) : double.Parse(args[1]); - double z = args[2].StartsWith('~') ? current.Z + (args[2].Length > 1 ? double.Parse(args[2][1..]) : 0) : double.Parse(args[2]); - Location block = new Location(x, y, z).ToFloor(), blockCenter = block.ToCenter(); + Location block = Location.Parse(handler.GetCurrentLocation(), args[0], args[1], args[2]).ToFloor(); + Location blockCenter = block.ToCenter(); bool res = handler.PlaceBlock(block, Direction.Down); return Translations.Get("cmd.useblock.use", blockCenter.X, blockCenter.Y, blockCenter.Z, res ? "succeeded" : "failed"); }