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? 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]
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.
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.
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.
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
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)
@Borlea I know this is kind of spoon-feeding, but how would you override its controller look? Is that NMS?
I found somewhere that the rotation is only applied when it moves. So maybe teleports the entity 0.25 up in the air?
Its easy to understand tho. Take a look: https://www.spigotmc.org/threads/tutorial-creating-custom-entities-with-pathfindergoals.18519/
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...