Solved PathfinderGoal not working

Discussion in 'Plugin Development' started by xTDKx, Jul 30, 2014.

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

    xTDKx

    I created a PathfinderGoal for my custom skeleton, yet it does nothing at all. I've cleared all of the default PathfinderGoals and just left the one that I created. Does anyone know why it's not working?
    Custom Skeleton Class:
    Code:java
    1. package me.xTDKx.MW.CustomMobs.CustomSkeleton;
    2.  
    3. import me.xTDKx.MW.CustomMobs.PathfinderGoalWalkToTile;
    4. import me.xTDKx.MW.Util.LocTrans;
    5. import me.xTDKx.MW.Util.Locations;
    6. import net.minecraft.server.v1_7_R4.*;
    7. import org.bukkit.Location;
    8. import org.bukkit.craftbukkit.v1_7_R4.util.UnsafeList;
    9.  
    10. import java.lang.reflect.Field;
    11.  
    12.  
    13. public class CustomEntitySkeleton extends EntitySkeleton {
    14.  
    15. public CustomEntitySkeleton(World world) {
    16. super(world);
    17. this.setSkeletonType(1);
    18. this.getAttributeInstance(GenericAttributes.maxHealth).setValue(100D);
    19. this.setHealth(100);
    20. this.fireProof = true;
    21.  
    22.  
    23. try {
    24. Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
    25. bField.setAccessible(true);
    26. Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
    27. cField.setAccessible(true);
    28. bField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    29. bField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    30. cField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    31. cField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    32. } catch (Exception exc) {
    33. exc.printStackTrace();
    34. }
    35.  
    36.  
    37. Location l = LocTrans.stringToLoc(Locations.getLocationFromName("Block Location"));
    38. this.goalSelector.a(0, new PathfinderGoalWalkToTile(this, l, (double) 5));
    39. this.goalSelector.a(1, new PathfinderGoalFloat(this));
    40. }
    41.  
    42. @Override
    43. public void g(double d0, double d1, double d2) {
    44. return;
    45. }
    46.  
    47. @Override
    48. public void collide(Entity e) {
    49. super.collide(e);
    50. if (e instanceof EntityPlayer) {
    51. return;
    52. }
    53. }
    54.  
    55. @Override
    56. protected void getRareDrop(int i) {
    57. return;
    58. }
    59.  
    60. @Override
    61. protected void bC() {
    62. super.bC();
    63. }
    64.  
    65.  
    66. }

    PathfinderGoal Class:
    Code:java
    1. package me.xTDKx.MW.CustomMobs;
    2.  
    3. import net.minecraft.server.v1_7_R4.EntityInsentient;
    4. import net.minecraft.server.v1_7_R4.Navigation;
    5. import net.minecraft.server.v1_7_R4.PathEntity;
    6. import net.minecraft.server.v1_7_R4.PathfinderGoal;
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.Location;
    9.  
    10. public class PathfinderGoalWalkToTile extends PathfinderGoal {
    11.  
    12. private double speed;
    13. private EntityInsentient entity;
    14. private Location loc;
    15. private Navigation navigation;
    16.  
    17. public PathfinderGoalWalkToTile(EntityInsentient entity, Location loc, double speed) {
    18. this.entity = entity;
    19. this.loc = loc;
    20. this.navigation = this.entity.getNavigation();
    21. this.speed = speed;
    22. }
    23.  
    24. public boolean a() {
    25. Bukkit.getLogger().info("CAN I WALK???");
    26. return true;
    27. }
    28.  
    29. @Override
    30. public void c() {
    31. Bukkit.getLogger().info("IMMA WALKIN!!");
    32.  
    33. PathEntity pathEntity = this.navigation.a(loc.getX(), loc.getY(), loc.getZ());
    34. this.navigation.a(pathEntity, speed);
    35. }
    36. }

    This can be seen in the console when the custom skeleton is spawned:
    [​IMG]
     
  2. Offline

    artish1

    xTDKx
    Show me how you spawn it.
     
  3. Offline

    ResultStatic

    xTDKx i had gotten into pathfinders and figured out how they work somewhat. they have methods that are called at certain times for instance

    public void e(){ is called multiple times per second not sure how many tps, updating status and location here.

    public boolean a() { is weather it should call public void e(){ or move onto the next priority pathfinder

    they also have more , i think public void c(){ is called when a() is true not 100% sure tho
     
  4. Offline

    xTDKx

    artish1 The custom mob works (it follows all the other methods I override). I also cleared it's default Pathfinder Goals. It's just not following the custom one I made, so it just stands there.
    Code:java
    1. World world = ((CraftWorld) Bukkit.getWorld("world")).getHandle();
    2. CustomEntitySkeleton skeleton = new CustomEntitySkeleton(world);
    3. skeleton.setPosition(0, 65, 0);
    4. world.addEntity(skeleton, CreatureSpawnEvent.SpawnReason.CUSTOM);


    ResultStatic The tutorial Ivan wrote says that a() is used to validate the goal and c() to execute the walking process.
     
  5. Offline

    ResultStatic

    xTDKx i used a() to find the nearest player, if there was a player nearby return true. then e() would be called while a() is true so it will walk to the player. c() is only called the first time a() is true. for updating locations and following players you should use e(). thats how i got mine to work anyway.
     
    xTDKx likes this.
  6. Offline

    xTDKx

    ResultStatic I'll try using e() then.

    ResultStatic Thanks using e() instead of c() worked. I guess all the tutorials I followed are outdated. Thanks so much for your help!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page