freezing the AI of a bat

Discussion in 'Spigot Plugin Development' started by Supercas240, Aug 2, 2018.

  1. currently working on a 1.8 plugin that requires me to disable the AI, aka freezing the bat in midair. but I'm pretty sure that with my current version the simple setAI(false); isnt working.
    Code (Java):
    Bat bat = (Bat) player.getWorld().spawnEntity(arrowLocation, EntityType.BAT);
                                     bat.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY,2147483647, 50));
                                     bat.setAI(false);
                                     bat.setLeashHolder(player);
    [​IMG]
    does anyone know an alternate way of dealing with this?

    I was just going to use an armor stand but you can leash them.
     
    • Funny Funny x 1
  2. This is a long shot, but have you tried giving it the slowness potion effect, or setting its generic.flyingSpeed attribute to 0? That's assuming it was even available in 1.8.
     
  3. yes, slowness does not seem to work on bats, for some reason. and flyingSpeed doesn't look likes that's a thing either.
    such an enoying problem
     
  4. You could teleport it on every tick and reset its velocity, but that's just super bad.
     
    • Agree Agree x 1
  5. If you're willing to use NMS then the k method works
    Code (Java):
    Bat bat = player.getWorld().spawn(arrowLocation, Bat.class);
    bat.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 50));
    ((CraftBat) bat).getHandle().k(true); // No AI
    Just a random side note, the World#spawn(Location, Class<T>) method uses generics and will returns the object so you don't have to cast it and it does the same thing. Also, I noticed you were using Integer.MAX_VALUE in its plain form. Might as well use the constant to make things more clear :p
     
  6. BananaPuncher714

    Supporter

    You can set the "NoAI" NBT tag of the bat to "1". This works in 1.8 up to 1.13 ;)
     
  7. I'd rather avoid that, way to much to updating
    you're right but I just love rolling my face over my keyboard from time to time ;)

    @Andavin your method gives an interesting error:
    [​IMG]
     
    #7 Supercas240, Aug 2, 2018
    Last edited: Aug 2, 2018
  8. yeah but that's also nms right? I was hoping for another option but if there's no somewhat reasonable way to make it work I guess I have no choice, thx anyway
     
  9. does LivingEntity have a method called setAI or no
     
  10. nope, that's my problem
     
  11. BananaPuncher714

    Supporter

  12. You cannot disable AI in 1.8 without using NMS
     
  13. maybe you can make the bat spawn where there is an barrier block so that it is trapped and cannot move. You can make it invincible too. Just remove the barrier block when u want it to move maybe?
     
  14. One thing you can try is set the bat’s speed to 0 as stated above.
     
  15. you would have to run that like every 1/2 second to work im pretty sure
     
  16. No, you don’t.

    What you can do is an entity spawn event if you want all of them to have 0 speed when they spawn in.
     
  17. updated api to 1.12 to see if I can get it to work, seems i'm still getting the same error ;/
    [​IMG]
     
  18. Perhaps LivingEntity#setAI it was added later, in 1.12.2?
    If you insist on using 1.8 without NMS, perhaps the entitydata command was a thing back then? I'm really not sure.
    Code (Text):
    getServer().dispatchCommand(getServer().getConsoleSender(), "entitydata " + bat.getUniqueId() + " {\"NoAI\":0}");
     
  19. MiniDigger

    Supporter

    the method setAI was added over 2 years ago. if your spigot version doesn't have that method, you should seriously consider not using ancient software..
     
  20. I just said I updated and tried it in 1.12, Getting the same error for some reason?