Solved Pathfinding issue when player leaves close range

Discussion in 'Spigot Plugin Development' started by Ski23, May 14, 2016.

  1. I am having an issue that, when a player is withing close range of my custom mob, the mob moves correctly. However, when the player moves back further away, the mob stops/ slows down. I think this might be due to a chunk loading issue. I tried loading the chunk that the mob is in every time the navigation is set if the chunk is not already loaded. That did not seem to have any effect. Here is a video demonstrating the issue:

    If anyone has any ideas on how to fix this, it would be very much appreciated. Thanks in advance!
     
  2. What's the code you used?

    Do you update the direction the mob's target every time he moves? That way, he'll sometimes see a player and try to walk to him, but your plug-in makes the zombie walk down the path instead (which is what you want). However, if the mob doesn't even walk (because there's no player nearby), nothing will get updated either.

    Chunk loading is not the problem - as long as you see a chunk it's (always) loaded.
     
    #2 StillNoNumber, May 14, 2016
    Last edited: May 14, 2016
  3. @StillNoNumber I'm not entirely sure what you mean by updating the direction the mob targets. The mob targets a location and not an entity. This is the code that I am using. This method is inside of my custom zombie and it gets called every tick:
    Code (Text):
    public void setPath()
        {
            Entity entity = this.getBukkitEntity();
            Location currentLoc = entity.getLocation();
            if (!currentLoc.getChunk().isLoaded())
            {
                currentLoc.getChunk().load();
                MyLogger.info("loading chunk");
            }
            if (pathToken + 1 <= path.length)
            {
                if (this.getBukkitEntity().getLocation().distance(path[pathToken]) <= .5)
                {
                    pathToken ++;
                }
                Location locationToNavigate = path[pathToken];
                if (currentLoc.distance(locationToNavigate) >= 20)
                {
                    double xDiff = locationToNavigate.getX() - currentLoc.getX();
                    double zDiff = locationToNavigate.getZ() - currentLoc.getZ();
                    double absX = Math.abs(xDiff);
                    double absZ = Math.abs(zDiff);
                    if (absX == Math.max(absX,absZ))
                    {
                        if (xDiff >= 0)
                        {
                            locationToNavigate = currentLoc.add(20, 0, 0);
                        }
                        else
                        {
                            locationToNavigate = currentLoc.add(-20, 0, 0);
                        }
                    }
                    else
                    {
                        if (zDiff >= 0)
                        {
                            locationToNavigate = currentLoc.add(0, 0, 20);
                        }
                        else
                        {
                            locationToNavigate = currentLoc.add(0, 0, -20);
                        }
                    }
                }
                this.getNavigation().a(locationToNavigate.getX(), locationToNavigate.getY(), locationToNavigate.getZ(), speed);
                //MyLogger.info("Navigating to " + path[pathToken]);
            }
            else
            {
                MyLogger.info("BOOM");
            }
        }
     
  4. bump again
     
  5. I have it solved! For any whom it may concern, I overrode the m() method in my custom entity and added this line:
    Code (Java):
    activatedTick = MinecraftServer.currentTick;
    Make sure to also call the super m() method as well though.
     
    • Like Like x 1