From df18018d447452ad6e59586b5cfd124b7c287367 Mon Sep 17 00:00:00 2001 From: someaddons <38401808+someaddons@users.noreply.github.com> Date: Mon, 9 Dec 2024 17:52:46 +0100 Subject: [PATCH] Cornerfixes (#10520) Adjust pathfinding to advance rather than creating a corner when it already exists --- .../pathfinding/pathjobs/AbstractPathJob.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/AbstractPathJob.java b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/AbstractPathJob.java index c43b559c84b..a908cd53bcf 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/AbstractPathJob.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/AbstractPathJob.java @@ -739,13 +739,9 @@ protected final void exploreInDirection(final MNode node, int dX, int dY, int dZ node.y + newY - nextY, node.z))) { - dX = 0; - dY = newY - nextY; - dZ = 0; - - nextX = node.x + dX; - nextY = node.y + dY; - nextZ = node.z + dZ; + nextX = node.x; + nextY = node.y + (newY - nextY); + nextZ = node.z; corner = true; } // If we're going down, take the air-corner before going to the lower node @@ -753,10 +749,8 @@ else if (!node.isCornerNode() && newY - node.y < 0 && (dX != 0 || dZ != 0) && (node.parent == null || (node.x != node.parent.x || node.y - 1 != node.parent.y || node.z != node.parent.z))) { - dY = 0; - nextX = node.x + dX; - nextY = node.y + dY; + nextY = node.y; nextZ = node.z + dZ; corner = true; @@ -783,7 +777,19 @@ else if (!node.isCornerNode() && newY - node.y < 0 && (dX != 0 || dZ != 0) && return; } - corner = true; + if (corner && nextNode.parent != null && (nextNode.parent.x != nextX || nextNode.parent.z != nextZ)) + { + // Corner node from different direction already created, skip to using the actual next pos + nextX = node.x + dX; + nextY = newY; + nextZ = node.z + dZ; + nextNode = nodes.get(MNode.computeNodeKey(nextX, nextY, nextZ)); + corner = false; + } + else + { + corner = true; + } } // Current node is already visited, only update nearby costs do not create new nodes @@ -999,7 +1005,7 @@ else if (pathingOptions.dropCost != 0) { cost += pathingOptions.traverseToggleAbleCost; } - else if (!onPath && !ShapeUtil.hasCollision(cachedBlockLookup, tempWorldPos.set(x, y, z), state)) + else if (!onPath && ShapeUtil.hasCollision(cachedBlockLookup, tempWorldPos.set(x, y, z), state)) { cost += pathingOptions.walkInShapesCost; }