summaryrefslogtreecommitdiffstats
path: root/src/Protocol/Protocol_1_9.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_9.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 '')
-rw-r--r--src/Protocol/Protocol_1_9.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp
index dd2133f77..9a4bcdc4a 100644
--- a/src/Protocol/Protocol_1_9.cpp
+++ b/src/Protocol/Protocol_1_9.cpp
@@ -307,12 +307,15 @@ void cProtocol_1_9_0::SendEntityPosition(const cEntity & a_Entity)
{
ASSERT(m_State == 3); // In game mode?
- const auto Delta = (a_Entity.GetPosition() - a_Entity.GetLastSentPosition()) * 32 * 128;
+ const auto Delta = (a_Entity.GetPosition() * 32 * 128).Floor() - (a_Entity.GetLastSentPosition() * 32 * 128).Floor();
- // Limitations of a short
- static const auto Max = std::numeric_limits<Int16>::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 BEInt16:
+ if (
+ Delta.HasNonZeroLength() &&
+ cByteBuffer::CanBEInt16Represent(Delta.x) &&
+ cByteBuffer::CanBEInt16Represent(Delta.y) &&
+ cByteBuffer::CanBEInt16Represent(Delta.z)
+ )
{
const auto Move = static_cast<Vector3<Int16>>(Delta);
@@ -341,7 +344,8 @@ void cProtocol_1_9_0::SendEntityPosition(const cEntity & a_Entity)
return;
}
- // Too big a movement, do a teleport
+ // Too big or small a movement, do a teleport.
+
cPacketizer Pkt(*this, pktTeleportEntity);
Pkt.WriteVarInt32(a_Entity.GetUniqueID());
Pkt.WriteBEDouble(a_Entity.GetPosX());