From a7a805c7b54aad99739d03b796cb06b8087c3900 Mon Sep 17 00:00:00 2001 From: syeyoung Date: Sat, 11 Feb 2023 20:07:42 +0900 Subject: - Fix typos - Show lines even if player is in blocked loc - Force refresh now should work as intended Signed-off-by: syeyoung --- .../dungeonsguide/mod/dungeon/actions/ActionMove.java | 3 ++- .../mod/dungeon/actions/ActionMoveNearestAir.java | 3 ++- .../mod/dungeon/pathfinding/algorithms/AStarCornerCut.java | 13 +++++++++---- .../mod/dungeon/pathfinding/algorithms/AStarFineGrid.java | 13 +++++++++---- .../mod/dungeon/pathfinding/algorithms/IPathfinder.java | 1 + .../dungeon/pathfinding/algorithms/PathfinderExecutor.java | 2 +- .../mod/dungeon/pathfinding/algorithms/ThetaStar.java | 13 +++++++++---- 7 files changed, 33 insertions(+), 15 deletions(-) (limited to 'mod/src/main/java/kr/syeyoung') diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/actions/ActionMove.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/actions/ActionMove.java index 8f1fc2d1..9ccbee8c 100755 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/actions/ActionMove.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/actions/ActionMove.java @@ -107,7 +107,8 @@ public class ActionMove extends AbstractAction { public void forceRefresh(DungeonRoom dungeonRoom) { - if (executor != null) executor.setTarget(Minecraft.getMinecraft().thePlayer.getPositionVector()); + if (executor == null) executor = dungeonRoom.createEntityPathTo(target.getBlockPos(dungeonRoom)); + executor.setTarget(Minecraft.getMinecraft().thePlayer.getPositionVector()); } @Override public String toString() { diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/actions/ActionMoveNearestAir.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/actions/ActionMoveNearestAir.java index dce9494a..e832a59a 100755 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/actions/ActionMoveNearestAir.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/actions/ActionMoveNearestAir.java @@ -79,7 +79,8 @@ public class ActionMoveNearestAir extends AbstractAction { } public void forceRefresh(DungeonRoom dungeonRoom) { - if (executor != null) executor.setTarget(Minecraft.getMinecraft().thePlayer.getPositionVector()); + if (executor == null) executor = dungeonRoom.createEntityPathTo(target.getBlockPos(dungeonRoom)); + executor.setTarget(Minecraft.getMinecraft().thePlayer.getPositionVector()); } @Override public String toString() { diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/pathfinding/algorithms/AStarCornerCut.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/pathfinding/algorithms/AStarCornerCut.java index 2d060fbc..08e88392 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/pathfinding/algorithms/AStarCornerCut.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/pathfinding/algorithms/AStarCornerCut.java @@ -112,11 +112,16 @@ public class AStarCornerCut implements IPathfinder { return false; } + @Override + public Vec3 getTarget() { + return new Vec3(lastSx / 2.0, lastSy / 2.0, lastSz / 2.0); + } + @Override public void setTarget(Vec3 from) { int tobeX = (int) Math.round(from.xCoord * 2); - int tobeY = (int) Math.round(from.zCoord * 2); - int tobeZ = (int) Math.round(from.yCoord * 2); + int tobeY = (int) Math.round(from.yCoord * 2); + int tobeZ = (int) Math.round(from.zCoord * 2); if (lastSx != tobeX || lastSy != tobeY || lastSz != tobeZ) { } else { return; @@ -124,8 +129,8 @@ public class AStarCornerCut implements IPathfinder { if (dungeonRoom.isBlocked(tobeX, tobeY, tobeZ)) return; this.lastSx = tobeX; - this.lastSz = tobeY; - this.lastSy = tobeZ; + this.lastSy = tobeY; + this.lastSz = tobeZ; open.clear(); pfindIdx++; found = false; diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/pathfinding/algorithms/AStarFineGrid.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/pathfinding/algorithms/AStarFineGrid.java index 9980a7c7..3811076b 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/pathfinding/algorithms/AStarFineGrid.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/pathfinding/algorithms/AStarFineGrid.java @@ -112,8 +112,8 @@ public class AStarFineGrid implements IPathfinder { @Override public void setTarget(Vec3 from) { int tobeX = (int) Math.round(from.xCoord * 2); - int tobeY = (int) Math.round(from.zCoord * 2); - int tobeZ = (int) Math.round(from.yCoord * 2); + int tobeY = (int) Math.round(from.yCoord * 2); + int tobeZ = (int) Math.round(from.zCoord * 2); if (lastSx != tobeX || lastSy != tobeY || lastSz != tobeZ) { } else { return; @@ -121,8 +121,8 @@ public class AStarFineGrid implements IPathfinder { if (dungeonRoom.isBlocked(tobeX, tobeY, tobeZ)) return; this.lastSx = tobeX; - this.lastSz = tobeY; - this.lastSy = tobeZ; + this.lastSy = tobeY; + this.lastSz = tobeZ; open.clear(); pfindIdx++; found = false; @@ -141,6 +141,11 @@ public class AStarFineGrid implements IPathfinder { } } + @Override + public Vec3 getTarget() { + return new Vec3(lastSx / 2.0, lastSy / 2.0, lastSz / 2.0); + } + @Override public List getRoute(Vec3 from) { int lastSx = (int) Math.round(from.xCoord * 2); diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/pathfinding/algorithms/IPathfinder.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/pathfinding/algorithms/IPathfinder.java index 3ea5cfa1..a88a772f 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/pathfinding/algorithms/IPathfinder.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/pathfinding/algorithms/IPathfinder.java @@ -28,5 +28,6 @@ public interface IPathfinder { boolean doOneStep(); void setTarget(Vec3 from); + Vec3 getTarget(); List getRoute(Vec3 from); } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/pathfinding/algorithms/PathfinderExecutor.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/pathfinding/algorithms/PathfinderExecutor.java index 8dcd499c..3c433237 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/pathfinding/algorithms/PathfinderExecutor.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/pathfinding/algorithms/PathfinderExecutor.java @@ -59,7 +59,7 @@ public class PathfinderExecutor { public List getRoute(Vec3 target) { if (!isComplete) return lastRoute; List route = pathfinder.getRoute(target); - if (route == null) return lastRoute = pathfinder.getRoute(getTarget()); + if (route == null) return lastRoute = pathfinder.getRoute(pathfinder.getTarget()); else return lastRoute = route; } } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/pathfinding/algorithms/ThetaStar.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/pathfinding/algorithms/ThetaStar.java index 9365485a..0916af59 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/pathfinding/algorithms/ThetaStar.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/pathfinding/algorithms/ThetaStar.java @@ -122,11 +122,16 @@ public class ThetaStar implements IPathfinder { return false; } + @Override + public Vec3 getTarget() { + return new Vec3(lastSx / 2.0, lastSy / 2.0, lastSz / 2.0); + } + @Override public void setTarget(Vec3 from) { int tobeX = (int) Math.round(from.xCoord * 2); - int tobeY = (int) Math.round(from.zCoord * 2); - int tobeZ = (int) Math.round(from.yCoord * 2); + int tobeY = (int) Math.round(from.yCoord * 2); + int tobeZ = (int) Math.round(from.zCoord * 2); if (lastSx != tobeX || lastSy != tobeY || lastSz != tobeZ) { } else { return; @@ -134,8 +139,8 @@ public class ThetaStar implements IPathfinder { if (dungeonRoom.isBlocked(tobeX, tobeY, tobeZ)) return; this.lastSx = tobeX; - this.lastSz = tobeY; - this.lastSy = tobeZ; + this.lastSy = tobeY; + this.lastSz = tobeZ; open.clear(); pfindIdx++; found = false; -- cgit