diff --git a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java index 85f71d8bb..9dc7aa982 100644 --- a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java +++ b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java @@ -158,7 +158,7 @@ public class CitizensNPC extends AbstractNPC { CurrentLocation spawnLocation = getTrait(CurrentLocation.class); if (getTrait(Spawned.class).shouldSpawn() && spawnLocation.getLocation() != null) { spawn(spawnLocation.getLocation(), SpawnReason.RESPAWN); - NMS.setHeadYaw(getEntity(), spawnLocation.getHeadYaw()); + NMS.setBodyYaw(getEntity(), spawnLocation.getBodyYaw()); } if (getTrait(Spawned.class).shouldSpawn() && spawnLocation.getLocation() == null) { Messaging.debug("Tried to spawn", getId(), "on load but world was null"); @@ -262,11 +262,10 @@ public class CitizensNPC extends AbstractNPC { Bukkit.getPluginManager().callEvent(new NPCNeedsRespawnEvent(this, at)); return false; } - getEntity().teleport(at); - NMS.setBodyYaw(getEntity(), at.getYaw()); NMS.setHeadYaw(getEntity(), at.getYaw()); + NMS.setBodyYaw(getEntity(), at.getYaw()); // Set the spawned state getTrait(CurrentLocation.class).setLocation(at); diff --git a/main/src/main/java/net/citizensnpcs/trait/CurrentLocation.java b/main/src/main/java/net/citizensnpcs/trait/CurrentLocation.java index c3604170e..426f88b8a 100644 --- a/main/src/main/java/net/citizensnpcs/trait/CurrentLocation.java +++ b/main/src/main/java/net/citizensnpcs/trait/CurrentLocation.java @@ -5,6 +5,7 @@ import org.bukkit.Location; import net.citizensnpcs.api.persistence.Persist; import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.TraitName; +import net.citizensnpcs.api.util.DataKey; import net.citizensnpcs.util.NMS; /** @@ -13,7 +14,7 @@ import net.citizensnpcs.util.NMS; @TraitName("location") public class CurrentLocation extends Trait { @Persist - private float headYaw; + private float bodyYaw; @Persist(value = "", required = true) private Location location = new Location(null, 0, 0, 0); @@ -21,20 +22,25 @@ public class CurrentLocation extends Trait { super("location"); } - public float getHeadYaw() { - return headYaw; + public float getBodyYaw() { + return bodyYaw; } public Location getLocation() { return location.getWorld() == null ? null : location; } + @Override + public void load(DataKey key) { + key.removeKey("headYaw"); + } + @Override public void run() { if (!npc.isSpawned()) return; location = npc.getEntity().getLocation(location); - headYaw = NMS.getHeadYaw(npc.getEntity()); + bodyYaw = NMS.getYaw(npc.getEntity()); } public void setLocation(Location loc) { diff --git a/main/src/main/java/net/citizensnpcs/util/NMS.java b/main/src/main/java/net/citizensnpcs/util/NMS.java index cb9b1a95f..9539a38ce 100644 --- a/main/src/main/java/net/citizensnpcs/util/NMS.java +++ b/main/src/main/java/net/citizensnpcs/util/NMS.java @@ -273,6 +273,10 @@ public class NMS { return BRIDGE.getVerticalMovement(bukkitEntity); } + public static float getYaw(Entity entity) { + return BRIDGE.getYaw(entity); + } + public static boolean isOnGround(org.bukkit.entity.Entity entity) { return BRIDGE.isOnGround(entity); } diff --git a/main/src/main/java/net/citizensnpcs/util/NMSBridge.java b/main/src/main/java/net/citizensnpcs/util/NMSBridge.java index 6507f63ca..6cd6ef7fe 100644 --- a/main/src/main/java/net/citizensnpcs/util/NMSBridge.java +++ b/main/src/main/java/net/citizensnpcs/util/NMSBridge.java @@ -75,6 +75,8 @@ public interface NMSBridge { public float getVerticalMovement(Entity entity); + public float getYaw(Entity entity); + public boolean isOnGround(Entity entity); public boolean isValid(Entity entity); diff --git a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java index d4c99947a..f167a91ab 100644 --- a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java +++ b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java @@ -547,6 +547,11 @@ public class NMSImpl implements NMSBridge { return handle.bf; } + @Override + public float getYaw(org.bukkit.entity.Entity entity) { + return getHandle(entity).yaw; + } + @Override public boolean isOnGround(org.bukkit.entity.Entity entity) { return NMSImpl.getHandle(entity).onGround; @@ -1521,7 +1526,6 @@ public class NMSImpl implements NMSBridge { private static Field SKULL_PROFILE_FIELD; private static MethodHandle TEAM_FIELD; private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c"); - private static final Field WITHER_BOSS_BAR_FIELD = NMS.getField(EntityWither.class, "bG"); static { diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java index eb8001e5b..9c3f8df39 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java @@ -585,6 +585,11 @@ public class NMSImpl implements NMSBridge { return handle.be; } + @Override + public float getYaw(org.bukkit.entity.Entity entity) { + return getHandle(entity).yaw; + } + @Override public boolean isOnGround(org.bukkit.entity.Entity entity) { return NMSImpl.getHandle(entity).onGround; diff --git a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java index df1aa1757..4507843e2 100644 --- a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java +++ b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java @@ -589,6 +589,11 @@ public class NMSImpl implements NMSBridge { return handle.be; } + @Override + public float getYaw(org.bukkit.entity.Entity entity) { + return getHandle(entity).yaw; + } + @Override public boolean isOnGround(org.bukkit.entity.Entity entity) { return NMSImpl.getHandle(entity).onGround; diff --git a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java index a3fd9bce1..da8c2cf0a 100644 --- a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java +++ b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java @@ -611,6 +611,11 @@ public class NMSImpl implements NMSBridge { return handle.bh; } + @Override + public float getYaw(org.bukkit.entity.Entity entity) { + return getHandle(entity).yaw; + } + @Override public boolean isOnGround(org.bukkit.entity.Entity entity) { return NMSImpl.getHandle(entity).onGround; diff --git a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java index d19c68897..c43983364 100644 --- a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java +++ b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java @@ -660,6 +660,11 @@ public class NMSImpl implements NMSBridge { return handle.bb; } + @Override + public float getYaw(org.bukkit.entity.Entity entity) { + return getHandle(entity).yaw; + } + @Override public boolean isOnGround(org.bukkit.entity.Entity entity) { return NMSImpl.getHandle(entity).onGround; diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/EntityHumanNPC.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/EntityHumanNPC.java index c09c9d34b..513550373 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/EntityHumanNPC.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/EntityHumanNPC.java @@ -397,7 +397,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable super.tick(); if (npc == null) return; - this.noclip = isSpectator(); + noclip = isSpectator(); if (updateCounter + 1 > Setting.PACKET_UPDATE_DELAY.asInt()) { updateEffects = true; } diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java index a0c33ff74..e08999080 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java @@ -662,6 +662,11 @@ public class NMSImpl implements NMSBridge { return handle.aZ; } + @Override + public float getYaw(org.bukkit.entity.Entity entity) { + return getHandle(entity).yaw; + } + @Override public boolean isOnGround(org.bukkit.entity.Entity entity) { return NMSImpl.getHandle(entity).onGround; diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java index e9941a4c0..5d9e01ff4 100644 --- a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java @@ -489,6 +489,11 @@ public class NMSImpl implements NMSBridge { return handle.aZ; } + @Override + public float getYaw(org.bukkit.entity.Entity entity) { + return getHandle(entity).yaw; + } + @Override public boolean isOnGround(org.bukkit.entity.Entity entity) { return NMSImpl.getHandle(entity).onGround; @@ -1396,5 +1401,4 @@ public class NMSImpl implements NMSBridge { ex.printStackTrace(); } } - }