Solved Removing PathfinderGoals from Entity AI

Discussion in 'Spigot Plugin Development' started by KingCobra, Jan 19, 2020.

  1. Helo!

    I am trying to remove look at player pathfindergoal from custom zombie, but I cant solve the problem (And I didnt find any working solution for 1.14.4)

    This is the last code what I tried: (In pathfindergoal class those fields are exist)
    Code (Java):
    public SoulHunter(org.bukkit.World world) {
            super(EntityTypes.ZOMBIE, ((CraftWorld)world).getHandle());
            Set<PathfinderGoalWrapped> goalD = (Set<PathfinderGoalWrapped>) getPrivateField("d", PathfinderGoalSelector.class, goalSelector); goalD.clear();
            Map<PathfinderGoal.Type, PathfinderGoalWrapped> goalC = (Map<PathfinderGoal.Type, PathfinderGoalWrapped>) getPrivateField("c", PathfinderGoalSelector.class, goalSelector); goalC.clear();
            Set<PathfinderGoalWrapped> goalD2 = (Set<PathfinderGoalWrapped>) getPrivateField("d", PathfinderGoalSelector.class, targetSelector); goalD2.clear();
            Map<PathfinderGoal.Type, PathfinderGoalWrapped> goalC2 = (Map<PathfinderGoal.Type, PathfinderGoalWrapped>) getPrivateField("c", PathfinderGoalSelector.class, targetSelector); goalC2.clear();
            this.targetSelector.a(1, (new PathfinderGoalHurtByTarget(this, new Class[0])).a(new Class[]{EntityPigZombie.class}));
            this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget<EntityHuman>(this, EntityHuman.class, true));
            this.goalSelector.a(1, new PathfinderGoalZombieAttack(this, 1.0D, false));
            this.goalSelector.a(2, new PathfinderGoalRandomStrollLand(this, 1.0D));
    Console dont show any error, but entities have normal AI
  2. just override the pathfinder method and add the pathfinders you actually want like this
    Code (Text):
    @Override// <- not necessary but I like putting it here
    public void initPathfinder() {
    //here goes the pathfinders you actually want
    • Like Like x 1
  3. You're welcomed.
  4. Also for entities that you already made the goal/target clearer should be like this at least on 1.14.4:

    Code (Text):
            entity.goalSelector = new PathfinderGoalSelector(handle.getWorld().getMethodProfiler());
            entity.targetSelector = new PathfinderGoalSelector(handle.getWorld().getMethodProfiler());
    I use these sometimes for entities that are easier to spawn from bukkit but need a goal clear
    • Informative Informative x 1