mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 10:36:10 +01:00
Fix saving of body vs head yaw
This commit is contained in:
parent
32429f140d
commit
8109a90440
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user