aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide/dungeon
diff options
context:
space:
mode:
authorsyeyoung <cyong06@naver.com>2021-04-17 21:59:15 +0900
committersyeyoung <cyong06@naver.com>2021-04-17 21:59:15 +0900
commit57c8cb923c68ccc6fe0448ccb15f62de2f014019 (patch)
tree3859fb80371c220ae57abf1d4d9e47648c2f2996 /src/main/java/kr/syeyoung/dungeonsguide/dungeon
parentfbcfc4a5f43a93db3afd0bc0a6b308c653e21a32 (diff)
downloadSkyblock-Dungeons-Guide-57c8cb923c68ccc6fe0448ccb15f62de2f014019.tar.gz
Skyblock-Dungeons-Guide-57c8cb923c68ccc6fe0448ccb15f62de2f014019.tar.bz2
Skyblock-Dungeons-Guide-57c8cb923c68ccc6fe0448ccb15f62de2f014019.zip
freeze
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/dungeon')
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMove.java26
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMoveNearestAir.java27
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java25
3 files changed, 60 insertions, 18 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMove.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMove.java
index fae91d26..e64751b1 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMove.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMove.java
@@ -17,6 +17,8 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
@Data
public class ActionMove extends AbstractAction {
@@ -56,21 +58,27 @@ public class ActionMove 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));
- }
- }
}
}
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();
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java
index 208d25b6..ffc9ca6d 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java
@@ -17,13 +17,21 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.block.Block;
+import net.minecraft.entity.Entity;
+import net.minecraft.pathfinding.PathEntity;
import net.minecraft.pathfinding.PathFinder;
+import net.minecraft.pathfinding.PathPoint;
import net.minecraft.util.BlockPos;
+import net.minecraft.world.IBlockAccess;
import javax.vecmath.Vector2d;
import java.awt.*;
import java.util.*;
import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
@Getter
public class DungeonRoom {
@@ -67,6 +75,23 @@ public class DungeonRoom {
@Getter
private PathFinder pathFinder;
+
+ public ScheduledFuture<List<BlockPos>> createEntityPathTo(IBlockAccess blockaccess, Entity entityIn, BlockPos targetPos, float dist) {
+ return asyncPathFinder.schedule(() -> {
+ PathEntity latest = pathFinder.createEntityPathTo(blockaccess, entityIn, targetPos, dist);
+ if (latest != null) {
+ List<BlockPos> poses = new ArrayList<>();
+ for (int i = 0; i < latest.getCurrentPathLength(); i++) {
+ PathPoint pathPoint = latest.getPathPointFromIndex(i);
+ poses.add(getMin().add(pathPoint.xCoord, pathPoint.yCoord, pathPoint.zCoord));
+ }
+ return poses;
+ }
+ return new ArrayList<>();
+ }, 0, TimeUnit.MILLISECONDS);
+ }
+
+ private static final ScheduledExecutorService asyncPathFinder = Executors.newScheduledThreadPool(2);
@Getter
private NodeProcessorDungeonRoom nodeProcessorDungeonRoom;