1.16.5 The changed FOLLOW_RANGE attribute does not actually work.

Discussion in 'Spigot Plugin Development' started by Unlegit_Denis, Jul 15, 2021.

  1. Hi, I'm trying to make a simple custom archer mob.

    Here the class of the entity.
    In the initPathfinder method I put all the goals of the EntitySkeleton class (by decompiling it) and I simply took out the PathfinderGoalNearestAttackableTargets towards the players and other mobs and created one just for the chickens.
    Code (Java):
    import net.minecraft.server.v1_16_R3.*;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.craftbukkit.v1_16_R3.CraftWorld;
    import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
    import org.bukkit.inventory.ItemStack;

    public class Archer extends EntitySkeleton {

        public Archer(Location loc) {
            super(EntityTypes.SKELETON, ((CraftWorld) loc.getWorld()).getHandle());
            this.setPosition(loc.getX(), loc.getY(), loc.getZ());

            this.setCustomName(new ChatComponentText(ChatColor.GOLD+""
                    +ChatColor.BOLD+ "Archer"));
            this.setCustomNameVisible(true);
            this.setHealth(100);

            setItem(EnumItemSlot.MAINHAND, new ItemStack(Material.BOW));

            System.out.println("Archer range " + this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).getValue());


        }

        @Override
        public void initPathfinder() {
            this.goalSelector.a(2, new PathfinderGoalRestrictSun(this));
            this.goalSelector.a(3, new PathfinderGoalFleeSun(this, 1.0D));
            this.goalSelector.a(3, new PathfinderGoalAvoidTarget<>(this, EntityWolf.class, 6.0F, 1.0D, 1.2D));
            this.goalSelector.a(5, new PathfinderGoalRandomStrollLand(this, 1.0D));
            this.goalSelector.a(6, new PathfinderGoalLookAtPlayer(this, (Class)EntityHuman.class, 8.0F));
            this.goalSelector.a(6, new PathfinderGoalRandomLookaround(this));
            this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this));
            this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget<>(this, EntityChicken.class, 10, true, false, entityLiving -> {
                try {
                    String n = entityLiving.getCustomName().getString();
                    if(n.equalsIgnoreCase("Target"))
                        return true;
                }catch (NullPointerException e) { }

                return false;

            }));

        }


        public void setItem(EnumItemSlot slot, ItemStack item) {
            this.setSlot(slot, CraftItemStack.asNMSCopy(item));
        }
    }
     

    To create the mob I do this.
    Code (Java):

    Archer archer = new Archer(player.getLocation());
    archer.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(35);
    System.out.println("new Archer range " + archer.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).getValue());
    WorldServer world = ((CraftWorld) player.getWorld()).getHandle();
    world.addEntity(archer);
     

    As you can see I change with "archer.getAttribute Instance (Generic Attributes.FOLLOW RANGE) .setValue (35);" this attribute so that the mob after 16 blocks(default) would follow the chicken.
    I have tested it and even if he changes it to 35 the mob has a range of 16 de facto and beyond this range it does not follow to attack chickens.
     
    #1 Unlegit_Denis, Jul 15, 2021
    Last edited: Jul 15, 2021