Solved Sheep won't keep following if out of render

Discussion in 'Spigot Plugin Development' started by ProSl3nderMan, May 22, 2016.

  1. BTW: I'm running this up against 1.8 Spigot as I do not wish to update the code just yet.

    Hello, today I ran into a problem while remaking the Mineplex Snake game, it's not copying detail by detail that is. The problem I'm having is that once my snake gets pretty big to where the last sheep is out of render, the sheep just stops moving. They continue to move if I run through them and they find their sheep they are suppose to follow, but it'll repeat. I don't think this is due to chunks unloading because I've ran off while the last ones were in the spawn chunks and I've tried out ChunkLoaderX.

    A little info about the code since I do not wish to paste it: The sheep are all powered by Vectors, their direction is always changing towards the direction of the sheep in front of them.

    If no one understands the problem, just wait please, as I am uploading a video showing it. Estimated time till video is complete: 18 minutes.

    Thanks in advance.

    at 0:30
    #1 ProSl3nderMan, May 22, 2016
    Last edited by a moderator: May 22, 2016
  2. Bump. If bumping is not allowed, sorry. It would be useful if someone could direct me to rules with a link.
  3. MiniDigger


    bumping is allowed after 24h, you are fine ^^ (
    if you don't share some more information with us we can't help you. how do you make the sheeps follow you? if you use pathfinders, is your custom one the only pathfinder applied?
    • Informative Informative x 1
    • Friendly Friendly x 1
  4. @MiniDigger Hello, thank you for the reply. Here is some code from my plugin:
    Code (Text):
    ((CraftSheep) m).getHandle().yaw = lead.getLocation().getYaw();
    ((CraftSheep) m).getHandle().pitch = lead.getLocation().getPitch();
    Vector dir = lead.getLocation().getDirection();
    Vector vec = new Vector(dir.getX() * 0.8D, 0.0D, dir.getZ() * 0.8D);
    I set the mobs direction towards the sheep in front of them, then I send them forward with a vector.
    m = follower
    lead = sheep in front of follower
  5. I did this once in an entirely different game, but it was with flying ducks..

    Are you taking into consideration the fact that mobs simply stop moving if they are too far from a player? I am not sure if this would interfere with movement from applying force to them.
    Also, how are you calculating the vector? If you are scaling it by distance in some way, it may be weakening to the point where a sheep left far away is unable to keep up because the impulse gets too weak?
  6. MiniDigger


    I am not sure if using the velo is the best approach to your problem. Personaly I would have used some custom pathfinding goals. This will allow me to controll every move the sheep does (if you remove the vanilla goals)
    • Agree Agree x 1
  7. @FlyingLlama I am not taking that into fact, do you know a way to fix it to where they don't stop moving? Also, my vector calculations are above your post.
    @MiniDigger Hm, well, I hope to find another way instead of using pathfinders as they confuse the heck out of me. If there's no other way, I guess I'll take time to learn it.
  8. I don't think that would work, since I believe is his sheeps aren't being updated correctly, or as he might expect. I think the best approach may be to manually teleport the sheeps on each tick, rather than relying the the vanilla Movement behavior, this should also make the trail a lot more consistent and safer.
  9. I thought of that, but wouldn't it make it quite a load on CPU?
  10. This guy had the same problem and fixed it.
  11. If you can disable the movement for the sheeps it would actually be a lot more efficient. Because in the background (the vanilla server), the sheeps are also being moved, however here the server also does collision checking, which is much slower, and unnecessary, since you can assume the sheeps will never go into the ground below, nor the walls around.
  12. Thanks, but I'm confused in how to add this to my current pathfinder? Is this correct?:
    Code (Text):

        public CustomSheep(org.bukkit.World world) {
            try {
                Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
                Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
                bField.set(this.goalSelector, new UnsafeList());
                bField.set(this.targetSelector, new UnsafeList());
                cField.set(this.goalSelector, new UnsafeList());
                cField.set(this.targetSelector, new UnsafeList());
                activatedTick = MinecraftServer.currentTick;
            catch (Exception exc) {
    If activateTick = Minecraftserver.currentTick is in the right place and that is all, then it doesn't work. Not sure if it has something to do with me being 1.9, cause the kid with the problem might have been 1.9.
  13. I think this might fix your problem!
    Go to your server config and find the line:
    Code (Text):
    and increase it it to 20 or something.

    I'm not positive this will work, but this might fix the out of render problem
  14. Even if it did work, it would lag some players most likely, the goal is to not lag players. Plus, trails of sheep can get very long in the game I'm making.
  15. Cannot increase view distance past 10
  16. Please suggest a proper fix instead. This may fix the problem, but the cost would be too great.
  17. S/he also said to call the m method of the super class.
  18. I apparently do not know Pathfinders as much as I thought I did. To call the m method with super, would I just add in the line,
    Code (Text):
    to my customsheep class?
    #18 ProSl3nderMan, May 24, 2016
    Last edited: May 24, 2016
  19. Code (Text):
    public void m(){
    activatedTick = MinecraftServer.currentTick;
    I think he meant this.
    #19 sander2798, May 24, 2016
    Last edited: May 24, 2016
    • Agree Agree x 1
  20. I'm think m has to be like m() though, I was just looking at a pathfinder and a() and c() sounded like that. Anyways, thanks. I'll be able to try this when I get home from school.