diff --git a/paper-api/src/main/java/org/bukkit/entity/Entity.java b/paper-api/src/main/java/org/bukkit/entity/Entity.java index 2c68aae864a7..e2205b6bdf66 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Entity.java +++ b/paper-api/src/main/java/org/bukkit/entity/Entity.java @@ -135,6 +135,16 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent */ public void setRotation(float yaw, float pitch); + /** + * Sets the entity's rotation. + * + * @param yaw the yaw + * @param relativeYaw whether the yaw is relative to the current yaw + * @param pitch the pitch + * @param relativePitch whether the pitch is relative to the current pitch + */ + void setRotation(float yaw, boolean relativeYaw, float pitch, boolean relativePitch); + // Paper start - Teleport API /** * Teleports this entity to the given location. diff --git a/paper-api/src/main/java/org/bukkit/entity/Player.java b/paper-api/src/main/java/org/bukkit/entity/Player.java index fe3f4b7552e1..3dc58808ad0d 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Player.java +++ b/paper-api/src/main/java/org/bukkit/entity/Player.java @@ -3795,6 +3795,20 @@ public int getPing() { */ void setRotation(float yaw, float pitch); + /** + * Set the player's rotation. + *

+ * Note: When relative parameters are set, client will do interpolations to + * make the rotation smooth, it's different from just send a new rotation with + * yaw or pitch addition. + * + * @param yaw the yaw + * @param relativeYaw whether the yaw is relative to the current yaw + * @param pitch the pitch + * @param relativePitch whether the pitch is relative to the current pitch + */ + void setRotation(float yaw, boolean relativeYaw, float pitch, boolean relativePitch); + /** * Causes the player to look towards the given entity. * diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java index 2f40476da09c..05573d9f99ac 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java @@ -277,6 +277,14 @@ public void setRotation(float yaw, float pitch) { this.getHandle().forceSetRotation(yaw, false, pitch, false); } + @Override + public void setRotation(float yaw, final boolean relativeYaw, float pitch, final boolean relativePitch) { + NumberConversions.checkFinite(pitch, "pitch not finite"); + NumberConversions.checkFinite(yaw, "yaw not finite"); + + this.getHandle().forceSetRotation(yaw, relativeYaw, pitch, relativePitch); + } + @Override public boolean teleport(Location location) { return this.teleport(location, TeleportCause.PLUGIN); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 2e95fee39986..3fbbfc6bf0b0 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -1299,6 +1299,13 @@ public void setRotation(float yaw, float pitch) { super.setRotation(yaw, pitch); } + @Override + public void setRotation(final float yaw, final boolean relativeYaw, final float pitch, final boolean relativePitch) { + if (this.getHandle().connection == null) return; + + super.setRotation(yaw, relativeYaw, pitch, relativePitch); + } + @Override public void lookAt(org.bukkit.entity.@NonNull Entity entity, @NonNull LookAnchor playerAnchor, @NonNull LookAnchor entityAnchor) { this.getHandle().lookAt(toNmsAnchor(playerAnchor), ((CraftEntity) entity).getHandle(), toNmsAnchor(entityAnchor));