PathfinderGoal not navigating

Discussion in 'Plugin Development' started by mine2012craft, Dec 2, 2018.

Thread Status:
Not open for further replies.
  1. Offline


    So I'm currently trying to make random wandering Pathfinding Goal, however whenever it gets to the navigation part, the path returns null and the mob does not wander to the location.
    public class PathfinderGoalStrollWithinRadius extends PathfinderGoal {
        Random rand = new Random();
        private double speed;
        private EntityCreature entity;
        private NavigationAbstract navigation;
        private int radius;
        public PathfinderGoalStrollWithinRadius(EntityCreature entity, double speed, int radius) {
            this.entity = entity;
            this.navigation = this.entity.getNavigation();
            this.speed = speed;
            this.radius = radius;
        public boolean a() {
            return true;
        public void c() {
            ArrayList<Block> blocks = MiniUtils.getBlocks(entity.getBukkitEntity().getLocation().getBlock(), radius);
            blocks.removeIf(n -> (!n.getType().isSolid()));
            Block block = blocks.get(rand.nextInt(blocks.size()));
            Location bLoc = block.getLocation();
            new BukkitRunnable() {
                public void run() {
                    PathEntity path = entity.getNavigation().a(entity.locX + ThreadLocalRandom.current().nextDouble(-7, 7), entity.locY, entity.locZ + ThreadLocalRandom.current().nextDouble(-7, 7));
                    System.out.println(entity == null);
                    System.out.println(entity.getNavigation() == null);
                    System.out.println(bLoc == null);
                    entity.getNavigation().a(path, speed);
                    Bukkit.broadcastMessage("Pathfinded 1");
            }.runTaskLater(Core.getInstance(), 1);
    So far I've checked to make sure all of the parameters and getters are equal to something and not null. I don't really know what the problem is here. Help is appreciated.

    - WarlordWeaponry
  2. Offline



    It looks like you are saying that path is null. The best reason I can guess is that you are using a random location, so it is possible that the location is inaccessible. Maybe, the path a() method of the navigation returns null if the location can't be reached.
    Also, it looks like bLocation is never used, so why do you create it?
Thread Status:
Not open for further replies.

Share This Page