Minestom/src/main/java/net/minestom/server/entity/pathfinding/EntityPathFinder.java

36 lines
1.1 KiB
Java
Raw Normal View History

2020-04-24 03:25:58 +02:00
package net.minestom.server.entity.pathfinding;
2020-03-29 20:58:30 +02:00
2020-04-24 03:25:58 +02:00
import net.minestom.server.MinecraftServer;
import net.minestom.server.entity.Entity;
2020-04-25 23:06:16 +02:00
import net.minestom.server.instance.Instance;
2020-04-24 03:25:58 +02:00
import net.minestom.server.utils.BlockPosition;
import net.minestom.server.utils.Position;
import net.minestom.server.utils.thread.MinestomThread;
2020-03-29 20:58:30 +02:00
import java.util.LinkedList;
2020-04-09 14:25:42 +02:00
import java.util.concurrent.ExecutorService;
import java.util.function.Consumer;
2020-03-29 20:58:30 +02:00
public class EntityPathFinder {
2020-04-22 02:42:58 +02:00
private static ExecutorService pathfindingPool = new MinestomThread(MinecraftServer.THREAD_COUNT_ENTITIES_PATHFINDING, MinecraftServer.THREAD_NAME_ENTITIES_PATHFINDING);
2020-04-09 14:25:42 +02:00
2020-03-29 20:58:30 +02:00
private Entity entity;
public EntityPathFinder(Entity entity) {
this.entity = entity;
}
2020-04-09 14:25:42 +02:00
public void getPath(Position target, Consumer<LinkedList<BlockPosition>> consumer) {
pathfindingPool.execute(() -> {
2020-04-25 23:06:16 +02:00
Instance instance = entity.getInstance();
BlockPosition start = entity.getPosition().toBlockPosition();
BlockPosition end = target.toBlockPosition();
2020-03-29 20:58:30 +02:00
2020-04-25 23:06:16 +02:00
consumer.accept(AStarPathfinder.getPath(instance, start, end, 100));
2020-04-09 14:25:42 +02:00
});
2020-03-29 20:58:30 +02:00
}
}