summaryrefslogtreecommitdiffstats
path: root/src/Protocol/Protocol_1_8.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2022-11-08 23:14:45 +0100
committerGitHub <noreply@github.com>2022-11-08 23:14:45 +0100
commit7a73fd467cfadfe3b3a5cf43d3eea9392f4c7f34 (patch)
tree49fd84a2dee2a1feeeb88565350fb3a55627dda5 /src/Protocol/Protocol_1_8.cpp
parentChunk: Optimise idle ticking (diff)
downloadcuberite-7a73fd467cfadfe3b3a5cf43d3eea9392f4c7f34.tar
cuberite-7a73fd467cfadfe3b3a5cf43d3eea9392f4c7f34.tar.gz
cuberite-7a73fd467cfadfe3b3a5cf43d3eea9392f4c7f34.tar.bz2
cuberite-7a73fd467cfadfe3b3a5cf43d3eea9392f4c7f34.tar.lz
cuberite-7a73fd467cfadfe3b3a5cf43d3eea9392f4c7f34.tar.xz
cuberite-7a73fd467cfadfe3b3a5cf43d3eea9392f4c7f34.tar.zst
cuberite-7a73fd467cfadfe3b3a5cf43d3eea9392f4c7f34.zip
Diffstat (limited to 'src/Protocol/Protocol_1_8.cpp')
-rw-r--r--src/Protocol/Protocol_1_8.cpp41
1 files changed, 18 insertions, 23 deletions
diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp
index e949d6116..d56375a8d 100644
--- a/src/Protocol/Protocol_1_8.cpp
+++ b/src/Protocol/Protocol_1_8.cpp
@@ -579,12 +579,15 @@ void cProtocol_1_8_0::SendEntityPosition(const cEntity & a_Entity)
{
ASSERT(m_State == 3); // In game mode?
- const auto Delta = (a_Entity.GetPosition() - a_Entity.GetLastSentPosition()) * 32;
+ const auto Delta = (a_Entity.GetPosition() * 32).Floor() - (a_Entity.GetLastSentPosition() * 32).Floor();
- // Limitations of a byte
- static const auto Max = std::numeric_limits<Int8>::max();
-
- if ((std::abs(Delta.x) <= Max) && (std::abs(Delta.y) <= Max) && (std::abs(Delta.z) <= Max))
+ // Ensure that the delta has enough precision and is within range of a BEInt8:
+ if (
+ Delta.HasNonZeroLength() &&
+ cByteBuffer::CanBEInt8Represent(Delta.x) &&
+ cByteBuffer::CanBEInt8Represent(Delta.y) &&
+ cByteBuffer::CanBEInt8Represent(Delta.z)
+ )
{
const auto Move = static_cast<Vector3<Int8>>(Delta);
@@ -613,8 +616,16 @@ void cProtocol_1_8_0::SendEntityPosition(const cEntity & a_Entity)
return;
}
- // Too big a movement, do a teleport
- SendEntityTeleport(a_Entity);
+ // Too big or small a movement, do a teleport.
+
+ cPacketizer Pkt(*this, pktTeleportEntity);
+ Pkt.WriteVarInt32(a_Entity.GetUniqueID());
+ Pkt.WriteFPInt(a_Entity.GetPosX());
+ Pkt.WriteFPInt(a_Entity.GetPosY());
+ Pkt.WriteFPInt(a_Entity.GetPosZ());
+ Pkt.WriteByteAngle(a_Entity.GetYaw());
+ Pkt.WriteByteAngle(a_Entity.GetPitch());
+ Pkt.WriteBool(a_Entity.IsOnGround());
}
@@ -4202,22 +4213,6 @@ void cProtocol_1_8_0::HandlePacket(cByteBuffer & a_Buffer)
-void cProtocol_1_8_0::SendEntityTeleport(const cEntity & a_Entity)
-{
- cPacketizer Pkt(*this, pktTeleportEntity);
- Pkt.WriteVarInt32(a_Entity.GetUniqueID());
- Pkt.WriteFPInt(a_Entity.GetPosX());
- Pkt.WriteFPInt(a_Entity.GetPosY());
- Pkt.WriteFPInt(a_Entity.GetPosZ());
- Pkt.WriteByteAngle(a_Entity.GetYaw());
- Pkt.WriteByteAngle(a_Entity.GetPitch());
- Pkt.WriteBool(a_Entity.IsOnGround());
-}
-
-
-
-
-
void cProtocol_1_8_0::StartEncryption(const Byte * a_Key)
{
m_Encryptor.Init(a_Key, a_Key);