Make NOAI Mob Face Certain Way

Discussion in 'Spigot Plugin Development' started by RustyDesigns, May 31, 2016.

  1. HEY SPIGOT!
    I'm having trouble making a villager face a certain way, its direction is always constant. Is it the NOAI tag fighting me?:confused:

    http://prntscr.com/bao252.png

    Code (Text):

    package com.spencerhiltbrand.beamcore.extras;



    import org.bukkit.Bukkit;

    import org.bukkit.entity.Entity;

    import org.bukkit.entity.EntityType;

    import org.bukkit.entity.LivingEntity;

    import org.bukkit.entity.Villager;

    import org.bukkit.event.EventHandler;

    import org.bukkit.event.Listener;

    import org.bukkit.event.entity.EntityChangeBlockEvent;

    import org.bukkit.plugin.Plugin;



    import net.md_5.bungee.api.ChatColor;



    publicclass Mob implements Listener {



    publicstatic Plugin plugin;



    public static void spawnInfoVilager() {



    LivingEntity villager = Bukkit.getWorld("Hub").spawn(Locations.villager,

    Villager.class);

    villager.setCustomName(ChatColor.RED + "" + ChatColor.BOLD + "ABOUT");

    villager.getLocation().setPitch(6F);

    villager.teleport(villager.getLocation());

    villager.setCustomNameVisible(true);

    villager.setAI(false);

    villager.setCollidable(false);

    villager.setRemoveWhenFarAway(false);



    }



    public static void deleteInfoVillager() {



    for (Entity villager : Bukkit.getWorld("Hub").getEntities()) {



    if (villager.getType().equals(EntityType.VILLAGER)) {



    villager.remove();



    }



    }



    }



    @EventHandler

    public void onChangeBlock(EntityChangeBlockEvent event) {



    if (event.getEntity().getType().equals(EntityType.VILLAGER)) {



    if (event.getEntity().getWorld().getName().toString()

    .equals("Hub")) {



    event.getEntity().teleport(Locations.spawn);

    event.setCancelled(true);



    }



    }



    }



    }


    [/SIZE]
     
     
  2. You could teleport the entity to the exact same location is it currently in except change the rotation upon teleportation. There is probably a better way, but that may work.
     
  3. Thats what I did if you would notice my code.
     
  4. Make a new Location object based off the villager's current location, change the rotation of the new location, and then teleport the villager to that location. Spigot/Minecraft can be a bit finicky when it comes to applying changes to entities directly, one example being that you can't edit an item's metadata directly, you have to create a new metadata object then re-apply it.
     
  5. Why not create a Custom Villager with pathfindergoals?
     
  6. You set the pitch. The pitch is looking up and down and is I think in degrees. This means that all you did was point his head up with 6 degrees. Something you barely notice.
     
  7. @bram0101 I updated it and used yaw, and set the value to 1000 and it still doesn't work.
     
  8. Choco

    Moderator

    You want to create a duplicate location, and teleport the entity to that.
    Code (Java):
    Location to = villager.getLocation().clone();
    to.setYaw(180F);
    villager.teleport(to);
    That SHOULD in theory, work. Mess around with some yaw values. Range from 0 - 360. Remember that it's sinusoidal. Periods are 360 degrees
     
  9. You can override its controller look.. If that doesn't work then I would suggest removing the noai tag and just overriding the move methods & the controller look. It's what I use and it seems to work perfectly.

    But with the 2nd option you may wanna prevent things that move the entity other ways without calling the move method(like a fishing hook pull)
     
    • Agree Agree x 2
  10. @Borlea
    I know this is kind of spoon-feeding, but how would you override its controller look? Is that NMS?
     
  11. I found somewhere that the rotation is only applied when it moves. So maybe teleports the entity 0.25 up in the air?
     
  12. That is a little outside of my expertise. ;)
     
  13. Ehm. So if you put his yaw at 90 and add 0.25 to his y position it doesn't work?
     
  14. I have had the same problem, it is a known bug tho.
    The only way of doing this is not disabling the AI until you have positioned the mob correctly.
    That means that you spawn a NPC, then face it with food or something and then finally, disable the AI. But somehow teleporting the mob isn't working for me either...
     
  15. MiniDigger

    Supporter

    Don't the no air stuff manually and override the look controller, worked for me.