PathfinderGoal not navigating

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

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

    mine2012craft

    Hello,
    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.
    Code:
    Code:
    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;
        }
    
        @Override
        public boolean a() {
            return true;
        }
    
        @Override
        public void c() {
            ArrayList<Block> blocks = MiniUtils.getBlocks(entity.getBukkitEntity().getLocation().getBlock(), radius);
            blocks.removeIf(n -> (!n.getType().isSolid()));
            System.out.println(blocks);
            Block block = blocks.get(rand.nextInt(blocks.size()));
            System.out.println(block);
            Location bLoc = block.getLocation();
            bLoc.setY(entity.locY);
            System.out.println(bLoc);
            new BukkitRunnable() {
    
                @Override
                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);
                    System.out.println(path);
                    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. @mine2012craft

    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