targetSelector and goalSelector changed?

Discussion in 'Plugin Development' started by BaddCamden, Jul 6, 2021.

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

    BaddCamden

    I have been having issues working with custom entity AIs because it seems that the most important aspects of them have changed. this.targetSelector and this.goalSelector have changed to something I believe and I have no idea what. If anybody has any ideas of what I am doing wrong or what they must've changed to, please let me know.

    Code:
    import org.bukkit.Location;
    import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
    import net.minecraft.network.chat.ChatComponentText;
    import net.minecraft.world.entity.EntityTypes;
    import net.minecraft.world.entity.ai.goal.PathfinderGoalLeapAtTarget;
    import net.minecraft.world.entity.ai.goal.target.PathfinderGoalNearestAttackableTarget;
    import net.minecraft.world.entity.monster.EntitySkeleton;
    import net.minecraft.world.entity.player.EntityHuman;
    public class CustomBruteDefender extends EntitySkeleton {
        //Constructor
        public CustomBruteDefender(Location loc) {
            super(EntityTypes.aB, ((CraftWorld) loc.getWorld()).getHandle());
            this.setPosition(loc.getX(), loc.getY(), loc.getZ());
     
            this.setHealth(100.0f); // Sets Health
            this.setCustomName(new ChatComponentText(org.bukkit.ChatColor.DARK_GRAY + "Brute Defender"));
            this.setCustomNameVisible(true);
     
        }
        @Override
        public void initPathfinder() { // This method will apply some custom pathfinders to our pig
            super.initPathfinder(); // This will apply all default pathfinders to the pig
     
            /*
             * this.targetSelector - Communicates what the pig's target to walk to will be.
             *
             * .a(0, pathfinder) - The pig's ai.
             *
             * 0, - priority
             * new PathfinderGoalNearestAttackableTarget<EntityHuman> - Tells the pig to target the nearest attackable target - <EntityHuman>
             * sets the type of mob to select.
             *
             * (this, - the pig
             * EntityHuman.class, - what to target
             * true) - this part is weird, but it tells the pig weather to target its own kind. We really don't need to worry about this, but
             * if we used EntityCreature as the target this would stop the pig from attacking itself.
             */
         
            this.targetSelector.a(0, new PathfinderGoalNearestAttackableTarget<EntityHuman>(this, EntityHuman.class, true));
     
            /*
             * this.goalSelector - Communicates what the pig's goal to perform will be.
             *
             * PathfinderGoalLeapAtTarget( - will make the pig leap at the player similar to a wolf attacking(this will not to damage)
             * this, - the pig
             * 1.0f) - the height of the jump(Please experiment with this to get a height you want)
             */
         
            this.goalSelector.a(1, new PathfinderGoalLeapAtTarget(this, 1.0f));
        }
    }
    
    

    EDIT: I did take this straight from a tutorial since when I did it on my own, I thought that I had done something wrong and looked for help via the tutorial
     
  2. Offline

    Shqep

    @BaddCamden
    Pretty sure IDEs give you code insight, as long as you know what type of variable you are looking for, there shouldn't be any problems. But here you go, the 1.16.4:
    [​IMG]

    and 1.17:
    [​IMG]
     
  3. Offline

    BaddCamden

    Thank you! This should work
     
Thread Status:
Not open for further replies.

Share This Page