[UnSolved] Pathfinding goals not working on custom mobs

Discussion in 'Plugin Development' started by Jogy34, May 29, 2013.

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

    Jogy34

    In one of my plugins I'm adding a few custom mobs and I am starting to try to add path finding goals in with them. On the one I am curectly working on, I'm trying to basically make an enderman that just attaches to a player. I made it an EntityTameableAnimal and made it always return true for if it's tamed and return the player's name it is attached to for the getOwnerName(). I tried adding a PathfinderGoalFollowOwner to it's goal selector but it isn't doing anything for it's movement. Anyone know if what I'm doing wrong.

    This is my current code for this entity
    Code:java
    1.  
    2. public class VashtaNerada extends EntityTameableAnimal
    3. {
    4. private String target;
    5. public VashtaNerada(World world, String target)
    6. {
    7. super(world);
    8. this.target = target;
    9. //I know this doesn't do much, I have it configured to use the enderman network id so that it looks like an enderman
    10. this.texture = "/mob/enderman.png";
    11. this.getNavigation().a(true); //I have tried setting b, c, and d, to true also
    12.  
    13. //This has been set to 0 but still nothing
    14. this.goalSelector.a(1, new PathfinderGoalFollowOwner(this, 0.3F, 10.0F, 2.0F));
    15.  
    16. this.bukkitEntity = new CraftTameableAnimal(this.world.getServer(), this);
    17.  
    18. //When these were in there a really cool/trippy rendering glitch was happening
    19. /*this.setTamed(true);
    20.   ((CraftTameableAnimal)bukkitEntity).setTamed(true);*/
    21. }
    22.  
    23. @Override
    24. public int getMaxHealth()
    25. {
    26. return 10000;
    27. }
    28.  
    29. @Override
    30. public EntityAgeable createChild(EntityAgeable ea)
    31. {
    32. return null;
    33. }
    34.  
    35. @Override
    36. public boolean isTamed()
    37. {
    38. return true;
    39. }
    40.  
    41. @Override
    42. public void setSitting(boolean flag){}
    43.  
    44. @Override
    45. public boolean isSitting()
    46. {
    47. return false;
    48. }
    49.  
    50. @Override
    51. public String getOwnerName()
    52. {
    53. return target;
    54. }
    55.  
    56. @Override
    57. public void setOwnerName(String name){}
    58. }
    59. [/CODE]
     
  2. Offline

    SoThatsIt

    i think you can do this with the remote entities library link!
     
  3. Offline

    Jogy34

    I don't want to use any external libraries.

    Jacek kumpelblase2, maybe one of you can help me?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  4. Offline

    Jacek

    Trying to use the target as the owner could be a problem since that changes quite a lot, try setting it to a specific player based on some action. Also make sure there are none of the default pathfinders that would override the movement.
     
  5. Offline

    Jogy34

    target is my own variable. I am going to end up spawning these mobs attached to a player so I send in the player's name in the constructor and use that as the owner so they will follow them around. There isn't any sort of owner variable in EntityTameableAnimal class, the owner is set through a byte in a datawatcher. Also there aren't any PathFinderGoals set in EntityTameableAnimal by default except there is a protected variable for a PathfinderGoalSit.
     
  6. Offline

    Jacek

    Jogy34 Perhaps the entity is not set to use the pathfinder AI then ?
     
  7. Offline

    Jogy34


    Any Idea on how to make it use the pathfinder AI? I looked at the EntityWolf class which extends EntityTameableAnimal and it didn't look like it does anything special to activate the pathfinder AI.
     
  8. Offline

    Jacek

    Jogy34 They have a boolean method that returns true if they use the new AI, it's been a while since I looked into that so they may all just use it now. You can find the method by looking for where the pathfinders are called, I forget where that is but you can find it by searching for the method name from the pathfinder or just fire up Eclipse and use that :p
     
  9. Offline

    DSH105

    Jogy34
    I created my own Pathfinder Selector system and it worked for me :)
     
  10. Offline

    Jogy34


    I'm looking through the NMS code and I can't find anything that looks like it would make the entities use the AI. I can't even find anywhere that the goalselector is used.


    Would you mind if I take a look at your code. I may need to make a similar implementation if I can't get the built in AI things to work.

    Well I sort of got it to somewhat work.

    This is what I'm using right now:
    Code:
        @Override
        public void l_()
        {
            super.l_();
            followOwner.a();
            followOwner.e();
            Player p = Bukkit.getServer().getPlayer(target);
            if(p != null)
            {
                Location loc = Bukkit.getServer().getPlayer(target).getLocation();
                this.getControllerMove().a(loc.getX(), loc.getY(), loc.getZ(), 0.0F);
                this.getControllerMove().c();
            }
        }
    
    The l_() method is called when the world ticks the entities.
    followOwner is a stored PathfinderGoalFollowOwner.
    The e() method will teleport the entity near the player if it gets to far away.
    The a() and c() methods on the ControlerMove will make it so the entity, for the most part, only moves towards the player and looks in the player's direction. It doesn't go right away though so it isn't the most efficient and can act weird some times.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  11. Offline

    DSH105

    Jogy34
    When I was doing this, I first researched all the way back to the EntityLiving class to determine where exactly the PathFinders are 'ticked'. This is what I found. And this is what I created from that:
    Show Spoiler

    Entity class constructor and variables:
    Code:java
    1.  
    2.  
    3. public PetGoalSelector petPathfinderSelector, petTargetSelector;
    4. public Navigation nav;
    5.  
    6. public EntityPet(World world, Pet pet) {
    7. super(world);
    8.  
    9. this.petPathfinderSelector = new PetGoalSelector(); // Note underneath for these values
    10. this.petTargetSelector = new PetGoalSelector();
    11.  
    12. nav = this.getNavigation();
    13. this.setGoals();
    14. // Set your goals here using the two goal selectors (initialised above)
    15. }
    16.  

    bo() as I mentioned above:
    Code:java
    1.  
    2.  
    3. // Overriden from EntityLiving - Most importantly overrides pathfinding selectors
    4. @Override
    5. protected void bo() {
    6. ++this.bC;
    7. //this.world.methodProfiler.a("checkDespawn");
    8. //this.bn();
    9. //this.world.methodProfiler.b();
    10.  
    11. //this.world.methodProfiler.a("sensing");
    12. this.getEntitySenses().a(); // Gets the field 'bP', as in EntityLiving class
    13. //this.world.methodProfiler.b();
    14.  
    15. //this.world.methodProfiler.a("targetSelector");
    16. //this.targetSelector.a();
    17. this.petTargetSelector.run(); // This is where I tick my own target selector
    18. //this.world.methodProfiler.b();
    19.  
    20. //this.world.methodProfiler.a("goalSelector");
    21. //this.goalSelector.a();
    22. this.petPathfinderSelector.run(); // This is where I tick my own pathfinder selector
    23. //this.world.methodProfiler.b();
    24.  
    25. //this.world.methodProfiler.a("navigation");
    26. //this.navigation.e();
    27. this.nav.e();
    28. //this.world.methodProfiler.b();
    29.  
    30. //this.world.methodProfiler.a("mob tick");
    31. this.bp();
    32. //this.world.methodProfiler.b();
    33.  
    34. //this.world.methodProfiler.a("controls");
    35.  
    36. //this.world.methodProfiler.a("move");
    37. this.getControllerMove().c();
    38.  
    39. //this.world.methodProfiler.c("look");
    40. this.getControllerLook().a();
    41.  
    42. //this.world.methodProfiler.c("jump");
    43. this.getControllerJump().b();
    44. //this.world.methodProfiler.b();
    45. //this.world.methodProfiler.b();
    46. }
    47.  





    My pathfinder selector is just simply an extension of the one used in NMS, just with a few of my own things added. I do know of another one on GitHub that is slightly different but should do the same thing :). You can find that here.
     
Thread Status:
Not open for further replies.

Share This Page