From 3c75377ce679094dfe55ee9aa872dabffd2ba3f0 Mon Sep 17 00:00:00 2001 From: DarkoGNU <42816979+DarkoGNU@users.noreply.github.com> Date: Tue, 26 Apr 2022 00:16:40 +0200 Subject: Implement relative SendPlayerMoveLook. Use it in TurnToDirt (#5413) * Implement relative SendPlayerMoveLook * Use relative teleport in cBlockFarmlandHandler::TurnToDirt * Static cast to UInt8. Explicit float values * Maybe explicit doubles, too * Fix TurnToDirt for some edge cases * Improve the height check in TurnToDirt * Const is good, right? * Const - the continuation --- src/Protocol/Protocol_1_8.cpp | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'src/Protocol/Protocol_1_8.cpp') diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp index 7a3cd3b90..cbb13e68e 100644 --- a/src/Protocol/Protocol_1_8.cpp +++ b/src/Protocol/Protocol_1_8.cpp @@ -1136,18 +1136,37 @@ void cProtocol_1_8_0::SendPlayerListUpdatePing() -void cProtocol_1_8_0::SendPlayerMoveLook(void) +void cProtocol_1_8_0::SendPlayerMoveLook (const Vector3d a_Pos, const float a_Yaw, const float a_Pitch, const bool a_IsRelative) { ASSERT(m_State == 3); // In game mode? cPacketizer Pkt(*this, pktPlayerMoveLook); + Pkt.WriteBEDouble(a_Pos.x); + Pkt.WriteBEDouble(a_Pos.y); + Pkt.WriteBEDouble(a_Pos.z); + Pkt.WriteBEFloat(a_Yaw); + Pkt.WriteBEFloat(a_Pitch); + + if (a_IsRelative) + { + // Set all bits to 1 - makes everything relative + Pkt.WriteBEUInt8(static_cast(-1)); + } + else + { + // Set all bits to 0 - make everything absolute + Pkt.WriteBEUInt8(0); + } +} + + + + + +void cProtocol_1_8_0::SendPlayerMoveLook(void) +{ cPlayer * Player = m_Client->GetPlayer(); - Pkt.WriteBEDouble(Player->GetPosX()); - Pkt.WriteBEDouble(Player->GetPosY()); - Pkt.WriteBEDouble(Player->GetPosZ()); - Pkt.WriteBEFloat(static_cast(Player->GetYaw())); - Pkt.WriteBEFloat(static_cast(Player->GetPitch())); - Pkt.WriteBEUInt8(0); + SendPlayerMoveLook(Player->GetPosition(), static_cast(Player->GetYaw()), static_cast(Player->GetPitch()), false); } -- cgit v1.2.3