Small utility methods for EntityRotationPacket

This commit is contained in:
themode 2021-01-22 21:28:33 +01:00
parent 5eb5f32095
commit 7de0067a13
4 changed files with 18 additions and 9 deletions

View File

@ -75,7 +75,7 @@ public interface Viewable {
/**
* Sends a packet to all viewers and the viewable element if it is a player.
* <p>
* If 'this' isn't a player, then {only @link #sendPacketToViewers(ServerPacket)} is called.
* If 'this' isn't a player, then only {@link #sendPacketToViewers(ServerPacket)} is called.
*
* @param packet the packet to send
*/

View File

@ -463,13 +463,8 @@ public class Player extends LivingEntity implements CommandSender {
position, new Position(lastPlayerSyncX, lastPlayerSyncY, lastPlayerSyncZ), onGround);
} else {
// View changed
EntityRotationPacket entityRotationPacket = new EntityRotationPacket();
entityRotationPacket.entityId = getEntityId();
entityRotationPacket.yaw = position.getYaw();
entityRotationPacket.pitch = position.getPitch();
entityRotationPacket.onGround = onGround;
updatePacket = entityRotationPacket;
updatePacket = EntityRotationPacket.getPacket(getEntityId(),
position.getYaw(), position.getPitch(), onGround);
}
if (viewChanged) {
@ -552,7 +547,7 @@ public class Player extends LivingEntity implements CommandSender {
/**
* Respawns the player by sending a {@link RespawnPacket} to the player and teleporting him
* to {@link #getRespawnPoint()}. It also resets fire and his health
* to {@link #getRespawnPoint()}. It also resets fire and health.
*/
public void respawn() {
if (!isDead())

View File

@ -26,6 +26,7 @@ public class EntityPositionPacket implements ServerPacket {
return ServerPacketIdentifier.ENTITY_POSITION;
}
@NotNull
public static EntityPositionPacket getPacket(int entityId,
@NotNull Position newPosition, @NotNull Position oldPosition,
boolean onGround) {

View File

@ -23,4 +23,17 @@ public class EntityRotationPacket implements ServerPacket {
public int getId() {
return ServerPacketIdentifier.ENTITY_ROTATION;
}
@NotNull
public static EntityRotationPacket getPacket(int entityId,
float yaw, float pitch,
boolean onGround) {
EntityRotationPacket entityRotationPacket = new EntityRotationPacket();
entityRotationPacket.entityId = entityId;
entityRotationPacket.yaw = yaw;
entityRotationPacket.pitch = pitch;
entityRotationPacket.onGround = onGround;
return entityRotationPacket;
}
}