diff options
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMoveNearestAir.java')
-rwxr-xr-x | src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMoveNearestAir.java | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMoveNearestAir.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMoveNearestAir.java index d9e9251d..ef4e9062 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMoveNearestAir.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMoveNearestAir.java @@ -17,6 +17,8 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; @Data public class ActionMoveNearestAir extends AbstractAction { @@ -54,24 +56,31 @@ public class ActionMoveNearestAir extends AbstractAction { } private int tick = -1; - private PathEntity latest; private List<BlockPos> poses; + private Future<List<BlockPos>> latestFuture; @Override public void onTick(DungeonRoom dungeonRoom) { tick = (tick+1) % 10; + if (latestFuture != null && latestFuture.isDone()) { + try { + poses = latestFuture.get(); + latestFuture = null; + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + } + } + if (tick == 0) { - latest = dungeonRoom.getPathFinder().createEntityPathTo(dungeonRoom.getContext().getWorld(), + try { + if (latestFuture != null) latestFuture.cancel(true); + } catch (Exception ignored) {} + if (!FeatureRegistry.SECRET_FREEZE_LINES.isEnabled()) + latestFuture = dungeonRoom.createEntityPathTo(dungeonRoom.getContext().getWorld(), Minecraft.getMinecraft().thePlayer, target.getBlockPos(dungeonRoom), Integer.MAX_VALUE); - if (latest != null) { - poses = new ArrayList<>(); - for (int i = 0; i < latest.getCurrentPathLength(); i++) { - PathPoint pathPoint = latest.getPathPointFromIndex(i); - poses.add(dungeonRoom.getMin().add(pathPoint.xCoord, pathPoint.yCoord, pathPoint.zCoord)); - } - } } } + @Override public String toString() { return "MoveNearestAir\n- target: "+target.toString(); |