Pet Method

Discussion in 'Plugin Development' started by Jaaakee224, Dec 17, 2014.

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

    Jaaakee224

    I found a resource on a method to easily create mobs that follow you around. However, some mobs do not work with this method. Such as Blaze, Slime, and Bat. Here is the method I am currently using:

    Code:
    public class PetCreator {
    
        public static void createPet(final Player player , final Entity pet , final double speed){
            new BukkitRunnable() {
    
                @SuppressWarnings("deprecation")
                public void run() {
                    if ((!pet.isValid() || (!player.isOnline()))) {
                        this.cancel();
                    }
    
                    net.minecraft.server.v1_7_R4.Entity pett = ((CraftEntity) pet).getHandle();
                    ((EntityInsentient) pett).getNavigation().a(2);
                    Object petf = ((CraftEntity) pet).getHandle();
                    Location targetLocation = player.getLocation();
    
                    PathEntity path;
                    path = ((EntityInsentient) petf).getNavigation().a(targetLocation.getX() + 1, targetLocation.getY(), targetLocation.getZ() + 1);
                    if (path != null) {
                        ((EntityInsentient) petf).getNavigation().a(path, 1.0D);
                        ((EntityInsentient) petf).getNavigation().a(2.0D);
                    }
    
                    int distance = (int) Bukkit.getPlayer(player.getName()).getLocation().distance(pet.getLocation());
                    if (distance > 10 && player.isOnGround()) {
                        pet.teleport(player.getLocation());
                    }
    
                    AttributeInstance attributes = ((EntityInsentient)((CraftEntity)pet).getHandle()).getAttributeInstance(GenericAttributes.d);
                    attributes.setValue(speed);
                }
            }.runTaskTimer(AzideaTokens.i, 0L, 20L);
        }
    }
    Is there an easy way to make the mobs I have said follow the player normally like any other mob? Much Appreciated.
     
  2. Offline

    CraftCreeper6

    @Jaaakee224
    Could you not just use the setTarget() method?
     
  3. Offline

    GeorgeeeHD

    @CraftCreeper6
    just saying, your signature will cause an endless while loop
     
    pookeythekid likes this.
  4. Offline

    Jaaakee224

    @CraftCreeper6
    I thought setTarget() was only for non-passive mobs?
     
  5. Offline

    pookeythekid

  6. Offline

    Jaaakee224

    Bumping this just to make sure there is no other way with the method I am using.
     
Thread Status:
Not open for further replies.

Share This Page