diff options
| author | syeyoung <cyong06@naver.com> | 2021-04-17 21:59:15 +0900 |
|---|---|---|
| committer | syeyoung <cyong06@naver.com> | 2021-04-17 21:59:15 +0900 |
| commit | 57c8cb923c68ccc6fe0448ccb15f62de2f014019 (patch) | |
| tree | 3859fb80371c220ae57abf1d4d9e47648c2f2996 /src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder | |
| parent | fbcfc4a5f43a93db3afd0bc0a6b308c653e21a32 (diff) | |
| download | Skyblock-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/roomfinder')
| -rwxr-xr-x | src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java | 25 |
1 files changed, 25 insertions, 0 deletions
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; |
