summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Barney <samjbarney@gmail.com>2013-11-05 22:11:13 +0100
committerSamuel Barney <samjbarney@gmail.com>2013-11-05 22:11:13 +0100
commiteefc6d37efd266edad5d1a2cbc2ea6e543e60cc2 (patch)
treedc8c1026776784a7f67e70facda0e2572ee820b7
parentAdded more documentation. Changed cTracer::Trace to return a bool instead of an int because it was only returning 1 or 0 anyways. (diff)
downloadcuberite-eefc6d37efd266edad5d1a2cbc2ea6e543e60cc2.tar
cuberite-eefc6d37efd266edad5d1a2cbc2ea6e543e60cc2.tar.gz
cuberite-eefc6d37efd266edad5d1a2cbc2ea6e543e60cc2.tar.bz2
cuberite-eefc6d37efd266edad5d1a2cbc2ea6e543e60cc2.tar.lz
cuberite-eefc6d37efd266edad5d1a2cbc2ea6e543e60cc2.tar.xz
cuberite-eefc6d37efd266edad5d1a2cbc2ea6e543e60cc2.tar.zst
cuberite-eefc6d37efd266edad5d1a2cbc2ea6e543e60cc2.zip
Diffstat (limited to '')
-rw-r--r--source/Tracer.cpp7
-rw-r--r--source/Tracer.h7
2 files changed, 10 insertions, 4 deletions
diff --git a/source/Tracer.cpp b/source/Tracer.cpp
index 4d036486e..bad1604d7 100644
--- a/source/Tracer.cpp
+++ b/source/Tracer.cpp
@@ -131,7 +131,7 @@ void cTracer::SetValues(const Vector3f & a_Start, const Vector3f & a_Direction)
-bool cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance)
+bool cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance, bool a_LineOfSight)
{
if ((a_Start.y < 0) || (a_Start.y >= cChunkDef::Height))
{
@@ -224,8 +224,9 @@ bool cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int
}
BLOCKTYPE BlockID = m_World->GetBlock(pos.x, pos.y, pos.z);
- // No collision with water ;)
- if (g_BlockIsSolid[BlockID])
+ // Block is counted as a collision if we are not doing a line of sight and it is solid,
+ // or if the block is not air and not water. That way mobs can still see underwater.
+ if ((!a_LineOfSight && g_BlockIsSolid[BlockID]) || (BlockID != E_BLOCK_AIR && !IsBlockWater(BlockID)))
{
BlockHitPosition = pos;
int Normal = GetHitNormal(a_Start, End, pos );
diff --git a/source/Tracer.h b/source/Tracer.h
index 85cb406c8..dc393ae5e 100644
--- a/source/Tracer.h
+++ b/source/Tracer.h
@@ -14,7 +14,12 @@ public: // tolua_export
~cTracer(); // tolua_export
/// Determines if a collision occures along a line. Returns true if a collision occurs.
- bool Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance); // tolua_export
+ bool Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance) // tolua_export
+ {
+ return Trace(a_Start, a_Direction, a_Distance, false);
+ }
+
+ bool Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance, bool a_LineOfSight); // tolua_export
/// Contains the position of the block that caused the collision
Vector3f BlockHitPosition; // tolua_export