Bat Pet

Discussion in 'Plugin Development' started by CentrumGuy, Sep 14, 2015.

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

    CentrumGuy

    Hi, I am working on a new project and in that project I have to make a bat follow a player. I want the bat to follow the player but not be limited to only being near the player. For example, the bat will be able to do whatever within a 3 block radius of the player, but if the distance between the player and the bat is greater than 3, the bat will follow the player until the distance is less than or equal to 3. I am really good at the coding part but really bad at the ai part. I tried to make the bat a pet by using the pet lib but it seems that it doesn't work on a bat for some reason. Thank you in advance,
    CentrumGuy
     
  2. Offline

    raGan.

    As I see it, you are basically just asking to get it done for you.

    What did you try so far? Do you need help with any particular algorithms? Apparently you know where to start already, and if not, you might want to look into NMS and create your own bat with simple custom AI to start with. I'm not sure what exactly you need help with, so maybe you should start and give people something to work with here.

    Also, AI part kinda belongs into coding part.
     
  3. This is my older code of one of my hub plugins (it allows pets to follow a specific player) - I got this code someday from google and modified it, just make sure to check the radius of the bat and modify it by YOURSELF. Hope this helps a bit.

    Code:
        public void petFollow(final Player player, final Entity pet, final double speed) {
            new BukkitRunnable() {
    
                @SuppressWarnings("deprecation")
                @Override
                public void run() {
                    if((!pet.isValid() || (!player.isOnline()))) {
                        this.cancel();
                    }
                    net.minecraft.server.v1_8_R1.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 && !pet.isDead() && player.isOnGround()) {
                            pet.teleport(player.getLocation());
                        }
                        AttributeInstance attributes = ((EntityInsentient) ((CraftEntity) pet).getHandle()).getAttributeInstance(GenericAttributes.d);
                        attributes.setValue(speed);
                    }
                }
            }.runTaskTimer(plugin, 0L, 20L);
        }
     
  4. Offline

    CentrumGuy

    I tried setting the bat's pathfinder goal to near the player, but for some reason, the bat seems to ignore it when I run the code. (All other mobs follow it so it's supposed to work for the bat too, but it doesn't)
     
  5. Offline

    caderape

    @CentrumGuy Create a class with a sccheduler for each pet, spawn the pet, and every second, check the distance betwwen play and the entity. If it's greater than 3, tp the pet to the player. With pathfinder, the bat will be locked on the player and it's not what you ask.
     
  6. Offline

    CentrumGuy

    Thank you, I'll see what I can do with that.

    I want to make it so it follows the player. Not teleports to the player. If it teleports then it breaks the whole effect :p

    This code seems to work for every mob but for some reason it doesn't work for the bat. Is there something special about the bat that makes it so that it doesn't follow a certain pathfinder goal?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
Thread Status:
Not open for further replies.

Share This Page