From 902b04656cafb7f5ce4689ef7e92062be847e2d4 Mon Sep 17 00:00:00 2001 From: ORelio Date: Sun, 13 Dec 2015 21:58:55 +0100 Subject: [PATCH] Fix pathfinding to coordinates - Now possible to walk to given coordinates - Fix sending location before it is received --- MinecraftClient/Mapping/Movement.cs | 9 +++++---- MinecraftClient/McTcpClient.cs | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/MinecraftClient/Mapping/Movement.cs b/MinecraftClient/Mapping/Movement.cs index ac963f84..b85852db 100644 --- a/MinecraftClient/Mapping/Movement.cs +++ b/MinecraftClient/Mapping/Movement.cs @@ -99,7 +99,7 @@ namespace MinecraftClient.Mapping public static Queue CalculatePath(World world, Location start, Location goal, bool allowUnsafe = false) { HashSet ClosedSet = new HashSet(); // The set of locations already evaluated. - HashSet OpenSet = new HashSet(); // The set of tentative nodes to be evaluated, initially containing the start node + HashSet OpenSet = new HashSet(new []{ start }); // The set of tentative nodes to be evaluated, initially containing the start node Dictionary Came_From = new Dictionary(); // The map of navigated nodes. Dictionary g_score = new Dictionary(); //:= map with default value of Infinity @@ -117,13 +117,14 @@ namespace MinecraftClient.Mapping .OrderBy(pair => pair.Value).First().Key; if (current == goal) { //reconstruct_path(Came_From, goal) - Queue total_path = new Queue(new Location[] { current }); + List total_path = new List(new[] { current }); while (Came_From.ContainsKey(current)) { current = Came_From[current]; - total_path.Enqueue(current); + total_path.Add(current); } - return total_path; + total_path.Reverse(); + return new Queue(total_path); } OpenSet.Remove(current); ClosedSet.Add(current); diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index a4750e93..6423460a 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -32,6 +32,7 @@ namespace MinecraftClient public void BotClear() { bots.Clear(); } private object locationLock = new object(); + private bool locationReceived = false; private World world = new World(); private Queue steps; private Queue path; @@ -356,6 +357,7 @@ namespace MinecraftClient this.location += location; } else this.location = location; + locationReceived = true; } } @@ -468,7 +470,7 @@ namespace MinecraftClient } } - if (Settings.TerrainAndMovements) + if (Settings.TerrainAndMovements && locationReceived) { lock (locationLock) {