From 0014ea6ac6052f34d9e5bc521515b39a8eb4f395 Mon Sep 17 00:00:00 2001 From: Timo van Veen Date: Fri, 27 Oct 2023 00:17:12 +0200 Subject: [PATCH] Cache position in search method --- .../simibubi/create/content/trains/entity/Navigation.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/simibubi/create/content/trains/entity/Navigation.java b/src/main/java/com/simibubi/create/content/trains/entity/Navigation.java index e658a44d9..0a19dd7ff 100644 --- a/src/main/java/com/simibubi/create/content/trains/entity/Navigation.java +++ b/src/main/java/com/simibubi/create/content/trains/entity/Navigation.java @@ -543,6 +543,9 @@ public class Navigation { if (graph == null) return; + // Cache the position of a node on the station edge if provided + Vec3 destinationNodePosition = destination == null ? null : destination.edgeLocation.getSecond().getLocation(); + // Cache the list of track types that the train can travel on Set validTypes = new HashSet<>(); for (int i = 0; i < train.carriages.size(); i++) { @@ -682,7 +685,7 @@ public class Navigation { TrackNode newNode = target.getKey(); TrackEdge newEdge = target.getValue(); double newDistance = newEdge.getLength() + distance; - double remainingDist = destination == null ? 0 : newNode.getLocation().getLocation().distanceTo(destination.edgeLocation.getSecond().getLocation()); + double remainingDist = destination == null ? 0 : newNode.getLocation().getLocation().distanceTo(destinationNodePosition); reachedVia.putIfAbsent(newEdge, Pair.of(validTargets.size() > 1, Couple.create(node1, node2))); if (destination != null && remainingDist == 0.0 && stationTest.test(newDistance, newDistance + penalty, reachedVia,