Entity's Navigation

Discussion in 'Plugin Development' started by 97WaterPolo, Oct 18, 2014.

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

    97WaterPolo

    Hello!

    I am currently trying to get a pig to follow a player around. I am trying to use
    Code:java
    1. public boolean walkTo(Entity p, Location l){
    2. return ((EntityAnimal)p).getNavigation().a(l.getX(), l.getY(), l.getZ(), .25);
    3. }


    I keep getting ClassCastException whether I sue EntityAnimal, or EntityCreature. I normally would cast it to EntityLiving it doesn't seem to have a navigation feature.

    Any idea how I can modify it so that it does work?
     
  2. Offline

    mine-care

  3. 97WaterPolo
    Cast to EntityInsentient. Something like this
    Code:java
    1. public boolean walkTo(Entity p, Location l) {
    2. return (((EntityInsentient) (LivingEntity) p)).getNavigation().a(l.getX(), l.getY(), l.getZ(), .25);
    3. }
     
  4. Offline

    97WaterPolo

    mine-care
    I check to see if the Entity's Type is a pig, which would fall under the category of animal. I am trying not to use pathfinders as I don't want to re-create the mob.

    Assist
    Just tried using EntityInsentient, still not working. Still get the error CraftPig cannot be cast to EntityInsentient.
     
  5. Offline

    mine-care

  6. Offline

    macguy8

    I may be wrong, but wouldn't you want to cast p.getHandle() to EntityAnimal instead of p?
     
  7. 97WaterPolo
    Whoops.
    Code:java
    1. return (((EntityInsentient) (LivingEntity) p).getHandle()).getNavigation().a(l.getX(), l.getY(), l.getZ(), .25);

    Don't know if brackets are correct there, wrote it on my phone.

    edit: Ninja'd.
     
  8. Offline

    97WaterPolo

    macguy8 Assist
    Am I missing something, but neither EntityAnimal, nor EntityInsentiet have a getHandle() method?
     
  9. 97WaterPolo
    That's because I messed up the brackets () there. You can probably just get rid of EntityInsentient and cast to (Craft)LivingEntity only.
     
  10. Offline

    97WaterPolo

    macguy8 Assist
    Thanks! Figured it out, there is a getNavigation() method for CraftPig, so I checked to see if it was a Pig, and if so casted to CraftPig. Thanks for all the help, still kinda clueless as to why EntityInsentiet didn't work.
     
Thread Status:
Not open for further replies.

Share This Page