PathFinderGoal#c() method is called only once

Discussion in 'Spigot Plugin Development' started by DIGDA, May 13, 2017.

  1. Hi.
    PathFinderGoal#a() always return true, but PathFinderGoal#c() is called only once when the mob spawned.

    CODE:
    Code (Text):
    public class PathfinderGoalTest extends PathfinderGoal {
        @Override
        public boolean a() {
            System.out.println("A");
            return true;
        }

        @Override
        public void c(){
            System.out.println("C");
        }
    }
    With this code, the console is like this:
    A
    C
    A
    A
    A
    A
    A
    ...

    Please lend me a hand.
     
  2. where do you use the "PathfinderGoalTest" class?
     
  3. Like this:
    Code (Text):
    public class TestGiant extends EntityGiantZombie{

        public TestGiant(World world){
            super(world);

            LinkedHashSet<?> goalB = (LinkedHashSet)getPrivateField("b", PathfinderGoalSelector.class, goalSelector); goalB.clear();
            LinkedHashSet<?> goalC = (LinkedHashSet)getPrivateField("c", PathfinderGoalSelector.class, goalSelector); goalC.clear();
            LinkedHashSet<?> targetB = (LinkedHashSet)getPrivateField("b", PathfinderGoalSelector.class, targetSelector); targetB.clear();
            LinkedHashSet<?> targetC = (LinkedHashSet)getPrivateField("c", PathfinderGoalSelector.class, targetSelector); targetC.clear();

            this.goalSelector.a(0, new PathfinderGoalFloat(this));
            this.goalSelector.a(1, new PathfinderGoalTest());
            this.goalSelector.a(1, new PathfinderGoalRandomStroll(this, 1.0D, 2));
        }
    I tested 2 more case.
    Case1: priority of PathfinderGoalTest = 1 and priority of PathfinderGoalRandomStroll = 2
    Case2: priority of PathfinderGoalTest = 2 and priority of PathfinderGoalRandomStroll = 1
    But the result is same.
     
  4. Sorry, I forgot to tag. @Phloxz
     
  5. You don't have to, they receive a notification whenever someone posts here because you automatically watch any thread that you replied to. You should also just edit the post instead of create another post to tag someone.
     
  6. Thank you for letting me know. It won't happen again.
     
  7. Ok so i basically took some research on the PathfinderGoal Class provided already from Spigot, and your "c()" method is beeing used to setup the goal, that's the reason why it has been called only once.

    (Class Image of PathfinderGoalSelector ( 1.11.2 )

    [​IMG]


    And as you can see here, method "a()" is beeing called everytime a check has been done.

    [​IMG]

    As an example, method "e()" is beeing called for the goal tick.

    [​IMG]


    I am not very familar with PathfinderGoal's and their mechanics so i can't really help you out by that ( but i hope i could help you out a bit why "a()" or "c()" is beeing called ).
     
  8. Thanks for reply. I succeeded to run functions after a() returns true by using e() instead of c() as you say.
    Thank you very much for helping!