summaryrefslogtreecommitdiffstats
path: root/src/Entities/Entity.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2020-07-14 18:55:25 +0200
committerTiger Wang <ziwei.tiger@outlook.com>2020-09-29 22:33:13 +0200
commit2624ccd8ba673ba79a99d24357458d763ac1e4c3 (patch)
tree828faffcf7e50de282a2424e58fa4afb48ea6e91 /src/Entities/Entity.cpp
parentBox size changes (diff)
downloadcuberite-2624ccd8ba673ba79a99d24357458d763ac1e4c3.tar
cuberite-2624ccd8ba673ba79a99d24357458d763ac1e4c3.tar.gz
cuberite-2624ccd8ba673ba79a99d24357458d763ac1e4c3.tar.bz2
cuberite-2624ccd8ba673ba79a99d24357458d763ac1e4c3.tar.lz
cuberite-2624ccd8ba673ba79a99d24357458d763ac1e4c3.tar.xz
cuberite-2624ccd8ba673ba79a99d24357458d763ac1e4c3.tar.zst
cuberite-2624ccd8ba673ba79a99d24357458d763ac1e4c3.zip
Diffstat (limited to 'src/Entities/Entity.cpp')
-rw-r--r--src/Entities/Entity.cpp25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 37ef925cf..1f270cff0 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -1067,9 +1067,15 @@ void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
// TODO: checks too much, very inefficient
for (int i = bstart.x; i <= bend.x; i++)
- for (int j = bstart.y; j <= bend.y; j++)
- for (int k = bstart.z; k <= bend.z; k++)
- Checks.emplace(Vector3i(i, j, k));
+ {
+ for (int j = bstart.y; j <= bend.y; j++)
+ {
+ for (int k = bstart.z; k <= bend.z; k++)
+ {
+ Checks.emplace(Vector3i(i, j, k));
+ }
+ }
+ }
return Checks;
}
@@ -1146,15 +1152,18 @@ void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
eBlockFace Face; // Face hit
cBoundingBox bb(a_BlockPos, a_BlockPos + Vector3i(1, 1, 1)); // Bounding box of the block hit
+ // First calculate line intersection
if (!bb.CalcLineIntersection(m_Start, m_End, LineCoeff, Face))
{
- // Math rounding errors have caused the calculation to miss the block completely, assume immediate hit
- LineCoeff = 0;
+ // Maths rounding errors have caused the calculation to miss the block completely
+ m_HitCoords = m_End;
+ m_HitBlockFace = BLOCK_FACE_NONE;
+ return true;
}
- m_HitCoords = m_Start + (m_End - m_Start) * LineCoeff; // Point where projectile goes into the hit block
-
- TestBoundingBoxCollisionWithEnvironment(m_HitCoords);
+ // Check bbox collision, setting final values
+ // Line tracer hit position is used as a starting point:
+ TestBoundingBoxCollisionWithEnvironment(m_Start + (m_End - m_Start) * LineCoeff);
return m_HitBlockFace != BLOCK_FACE_NONE;
}