Skip to content

Commit

Permalink
misc: 使用nms方法来转换Yaw/Pitch
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Nov 4, 2024
1 parent 491465f commit 3ee7cea
Showing 1 changed file with 10 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,11 @@ private void onTeleport(ClientboundTeleportEntityPacket packet, PacketEvent even
if (!isDragon && !isPhantom)
return;

var yaw = packet.change().yRot();
var pitch = packet.change().xRot();
float yaw = packet.change().yRot();
float pitch = packet.change().xRot();

var playerYaw = isDragon ? (sourcePlayer.getYaw() + 180f) : sourcePlayer.getYaw();
yaw = (playerYaw / 360f) * 256f;

var playerPitch = isPhantom ? -sourcePlayer.getPitch() : sourcePlayer.getPitch();

pitch = (playerPitch / 360f) * 256f;
yaw = isDragon ? (yaw + 180f) : yaw;
pitch = isPhantom ? -pitch : pitch;

var container = event.getPacket();
container.getBytes().write(0, Mth.packDegrees(yaw));
Expand All @@ -111,9 +107,9 @@ private void onHeadRotation(ClientboundRotateHeadPacket packet, PacketEvent even
if (watcher == null || watcher.getEntityType() != EntityType.ENDER_DRAGON)
return;

var newHeadYaw = (byte)(((sourcePlayer.getYaw() + 180f) / 360f) * 256f);
var newHeadYaw = packet.getYHeadRot() + 180f;

var newPacket = new ClientboundRotateHeadPacket(sourceNmsEntity, newHeadYaw);
var newPacket = new ClientboundRotateHeadPacket(sourceNmsEntity, Mth.packDegrees(newHeadYaw));
var finalPacket = PacketContainer.fromPacket(newPacket);
getFactory().markPacketOurs(finalPacket);

Expand All @@ -140,17 +136,11 @@ private void onLookPacket(ClientboundMoveEntityPacket packet, PacketEvent event)
if (!isDragon && !isPhantom)
return;

var yaw = packet.getyRot();
var pitch = packet.getxRot();

var playerYaw = isDragon ? (sourcePlayer.getYaw() + 180f) : sourcePlayer.getYaw();
var finalYaw = (playerYaw / 360f) * 256f;
yaw = (byte)finalYaw;

var playerPitch = isPhantom ? -sourcePlayer.getPitch() : sourcePlayer.getPitch();
float yaw = packet.getyRot();
float pitch = packet.getxRot();

var finalPitch = (playerPitch / 360f) * 256f;
pitch = (byte)finalPitch;
yaw = isDragon ? (yaw + 180f) : yaw;
pitch = isPhantom ? -pitch : pitch;

ClientboundMoveEntityPacket newPacket;

Expand Down

0 comments on commit 3ee7cea

Please sign in to comment.