summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
authorstone3311 <9110659+stone3311@users.noreply.github.com>2020-03-20 09:31:06 +0100
committerGitHub <noreply@github.com>2020-03-20 09:31:06 +0100
commit0a1cfda02cb971ccafa6e7bab8a6386039aed126 (patch)
treee6001ac38869e1a0310022f467a9ab0a04cce207 /src/Entities
parentFIx formatting issue in Backers file (diff)
downloadcuberite-0a1cfda02cb971ccafa6e7bab8a6386039aed126.tar
cuberite-0a1cfda02cb971ccafa6e7bab8a6386039aed126.tar.gz
cuberite-0a1cfda02cb971ccafa6e7bab8a6386039aed126.tar.bz2
cuberite-0a1cfda02cb971ccafa6e7bab8a6386039aed126.tar.lz
cuberite-0a1cfda02cb971ccafa6e7bab8a6386039aed126.tar.xz
cuberite-0a1cfda02cb971ccafa6e7bab8a6386039aed126.tar.zst
cuberite-0a1cfda02cb971ccafa6e7bab8a6386039aed126.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/Entity.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index f0118104b..87d385691 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -2239,8 +2239,16 @@ Vector3d cEntity::GetLookVector(void) const
// Set position
void cEntity::SetPosition(const Vector3d & a_Position)
{
+ // Clamp the positions to exactly representable single-precision floating point values
+ // This is necessary to avoid rounding errors in the noise generator and overflows in the chunk loader
+ const double MaxFloat = std::pow(2, std::numeric_limits<float>().digits);
+
+ const double ClampedPosX = Clamp(a_Position.x, -MaxFloat, MaxFloat);
+ const double ClampedPosY = Clamp(a_Position.y, -MaxFloat, MaxFloat);
+ const double ClampedPosZ = Clamp(a_Position.z, -MaxFloat, MaxFloat);
+
m_LastPosition = m_Position;
- m_Position = a_Position;
+ m_Position = {ClampedPosX, ClampedPosY, ClampedPosZ};
}