Remove Player from PathfinderGoal (Zombie)

Discussion in 'Plugin Development' started by GEGENPHASE, Nov 28, 2020.

  1. Offline

    GEGENPHASE

    ^ Hey, I want to spawn a zombie, which attacks Skeletons, Creepers, Endermen, Silverfishes, etc... but NO players. My code for the spawn-class is

    Code:
    public class Defender{
    
        Player p;
        Location loc;
        WorldServer world;
       
        EntityCreature c;
        EntityZombie cc;
       
        public Defender(Player p, Plugin pl) {
           
            this.p = p;
    
            this.loc = p.getLocation();
            world = ((CraftWorld) loc.getWorld()).getHandle();
           
            cc = new EntityZombie(EntityTypes.ZOMBIE, world);
            c = (EntityCreature) cc;
           
        }
       
        @SuppressWarnings("deprecation")
        public void spawn() {
    
            try {
                Zombie b = (Zombie) cc.getBukkitEntity();
    
                b.setMaxHealth(10);
                b.setHealth(10);
    
                b.setCustomName((ChatColor.GOLD + p.getName() + "'s defender"));
                b.setCustomNameVisible(true);
               
                b.getEquipment().setHelmet(new ItemStack(Material.IRON_HELMET));
                b.getEquipment().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
                b.getEquipment().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
                b.getEquipment().setBoots(new ItemStack(Material.IRON_BOOTS));
    
                b.getEquipment().setItemInMainHand(new ItemStack(Material.IRON_SWORD));
               
                c.goalSelector.a(4, new PathfinderGoalMeleeAttack((EntityCreature) c, 1.0D, true));
               
                c.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget<EntityPig>((EntityCreature) c, EntityPig.class, true));
                c.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget<EntitySkeleton>((EntityCreature) c, EntitySkeleton.class, true));
                c.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget<EntitySilverfish>((EntityCreature) c, EntitySilverfish.class, true));
                c.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget<EntityCreeper>((EntityCreature) c, EntityCreeper.class, true));
                c.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget<EntityEnderman>((EntityCreature) c, EntityEnderman.class, true));
    
                c.targetSelector.a(-1, new PathfinderGoalNearestAttackableTarget<EntityHuman>((EntityCreature) c, EntityHuman.class, true));
    
                c.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
               
                world.addEntity(c);
               
            } catch (Exception e) {
    
                Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Something went wrong!");
                   
            }
           
        }
       
    }
    I have no Idea how to REMOVE a player from the pathfindergoals of the zombie. I tried several solutions I've found in the internet but none of them work in my version (1.16.1). He does attack everything I've set in the code but ALSO players and he is not supposed to do that please help..
     
  2. Offline

    MrDaniel

    @Genesis12345678900000
    You are entering the deep and complex world of NMS. If you don't already know what it is, I suggest googling it and looking at some threads.

    The way you override the default pathfinder goals is by overriding a function under the name of m (as of version 1.16.3)
    This is how the method looks like:
    Code:
    protected void m() {
        this.goalSelector.a(2, new PathfinderGoalZombieAttack(this, 1.0D, false));
        this.goalSelector.a(6, new PathfinderGoalMoveThroughVillage(this, 1.0D, true, 4, this::eU));
        this.goalSelector.a(7, new PathfinderGoalRandomStrollLand(this, 1.0D));
        this.targetSelector.a(1, (new PathfinderGoalHurtByTarget(this, new Class[0])).a(new Class[] { EntityPigZombie.class }));
        this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget<>(this, EntityHuman.class, true));
        if (this.world.spigotConfig.zombieAggressiveTowardsVillager)
          this.targetSelector.a(3, new PathfinderGoalNearestAttackableTarget<>(this, EntityVillagerAbstract.class, false)); 
        this.targetSelector.a(3, new PathfinderGoalNearestAttackableTarget<>(this, EntityIronGolem.class, true));
        this.targetSelector.a(5, new PathfinderGoalNearestAttackableTarget<>(this, EntityTurtle.class, 10, true, false, EntityTurtle.bo));
    }
    
    To override what the pathfinder looks at, just change the EntityHuman.class to something else, or just remove that line all together.
     
  3. Offline

    GEGENPHASE

    I dont know what this means to my code. Should I add this method to my Class or how can I override this method?
     

Share This Page