summaryrefslogtreecommitdiffstats
path: root/src/World.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2017-05-11 14:34:36 +0200
committerworktycho <work.tycho@gmail.com>2017-05-11 14:34:36 +0200
commit2c3c1f15273835923d9bd4950a19ee88a95ee0f4 (patch)
treecda390aa07a202497271439c2b330643074239df /src/World.cpp
parentExported cFallingBlock and cExpOrb (#3700) (diff)
downloadcuberite-2c3c1f15273835923d9bd4950a19ee88a95ee0f4.tar
cuberite-2c3c1f15273835923d9bd4950a19ee88a95ee0f4.tar.gz
cuberite-2c3c1f15273835923d9bd4950a19ee88a95ee0f4.tar.bz2
cuberite-2c3c1f15273835923d9bd4950a19ee88a95ee0f4.tar.lz
cuberite-2c3c1f15273835923d9bd4950a19ee88a95ee0f4.tar.xz
cuberite-2c3c1f15273835923d9bd4950a19ee88a95ee0f4.tar.zst
cuberite-2c3c1f15273835923d9bd4950a19ee88a95ee0f4.zip
Diffstat (limited to '')
-rw-r--r--src/World.cpp38
1 files changed, 16 insertions, 22 deletions
diff --git a/src/World.cpp b/src/World.cpp
index 2614ead7b..447e2cf25 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -13,6 +13,7 @@
#include "Generating/ChunkDesc.h"
#include "SetChunkData.h"
#include "DeadlockDetect.h"
+#include "LineBlockTracer.h"
// Serializers
#include "WorldStorage/ScoreboardSerializer.h"
@@ -50,11 +51,6 @@
#include "Bindings/PluginManager.h"
#include "Blocks/BlockHandler.h"
-#include "Tracer.h"
-
-// DEBUG: Test out the cLineBlockTracer class by tracing a few lines:
-#include "LineBlockTracer.h"
-
#ifndef _WIN32
#include <stdlib.h>
#endif
@@ -3190,11 +3186,8 @@ bool cWorld::DoWithPlayerByUUID(const AString & a_PlayerUUID, cLambdaPlayerCallb
-// TODO: This interface is dangerous!
cPlayer * cWorld::FindClosestPlayer(const Vector3d & a_Pos, float a_SightLimit, bool a_CheckLineOfSight)
{
- cTracer LineOfSight(this);
-
double ClosestDistance = a_SightLimit;
cPlayer * ClosestPlayer = nullptr;
@@ -3208,22 +3201,23 @@ cPlayer * cWorld::FindClosestPlayer(const Vector3d & a_Pos, float a_SightLimit,
Vector3f Pos = (*itr)->GetPosition();
double Distance = (Pos - a_Pos).Length();
- if (Distance < ClosestDistance)
+ // If the player is too far, skip them:
+ if (Distance > ClosestDistance)
{
- if (a_CheckLineOfSight)
- {
- if (!LineOfSight.Trace(a_Pos, (Pos - a_Pos), static_cast<int>((Pos - a_Pos).Length())))
- {
- ClosestDistance = Distance;
- ClosestPlayer = *itr;
- }
- }
- else
- {
- ClosestDistance = Distance;
- ClosestPlayer = *itr;
- }
+ continue;
}
+
+ // Check LineOfSight, if requested:
+ if (
+ a_CheckLineOfSight &&
+ !cLineBlockTracer::LineOfSightTrace(*this, a_Pos, Pos, cLineBlockTracer::losAirWater)
+ )
+ {
+ continue;
+ }
+
+ ClosestDistance = Distance;
+ ClosestPlayer = *itr;
}
return ClosestPlayer;
}