summaryrefslogtreecommitdiffstats
path: root/src/Mobs
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2020-12-18 21:49:36 +0100
committerTiger Wang <ziwei.tiger@outlook.com>2020-12-21 14:52:23 +0100
commit5b6bed6b00a4337092920684461328901c4cb6f0 (patch)
treeb424ec3bc0352746a1cc154fdcc0286451bf414e /src/Mobs
parentMonsters: improve targeting (diff)
downloadcuberite-5b6bed6b00a4337092920684461328901c4cb6f0.tar
cuberite-5b6bed6b00a4337092920684461328901c4cb6f0.tar.gz
cuberite-5b6bed6b00a4337092920684461328901c4cb6f0.tar.bz2
cuberite-5b6bed6b00a4337092920684461328901c4cb6f0.tar.lz
cuberite-5b6bed6b00a4337092920684461328901c4cb6f0.tar.xz
cuberite-5b6bed6b00a4337092920684461328901c4cb6f0.tar.zst
cuberite-5b6bed6b00a4337092920684461328901c4cb6f0.zip
Diffstat (limited to 'src/Mobs')
-rw-r--r--src/Mobs/Enderman.cpp29
-rw-r--r--src/Mobs/Enderman.h3
2 files changed, 17 insertions, 15 deletions
diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp
index 302593183..02450487b 100644
--- a/src/Mobs/Enderman.cpp
+++ b/src/Mobs/Enderman.cpp
@@ -13,9 +13,10 @@
class cPlayerLookCheck
{
public:
- cPlayerLookCheck(Vector3d a_EndermanPos, int a_SightDistance) :
+
+ cPlayerLookCheck(Vector3d a_EndermanHeadPosition, int a_SightDistance) :
m_Player(nullptr),
- m_EndermanPos(a_EndermanPos),
+ m_EndermanHeadPosition(a_EndermanHeadPosition),
m_SightDistance(a_SightDistance)
{
}
@@ -28,29 +29,32 @@ public:
return false;
}
- // Don't check players who are more than SightDistance (64) blocks away
- auto Direction = m_EndermanPos - a_Player.GetPosition();
+ const auto PlayerHeadPosition = a_Player.GetPosition().addedY(a_Player.GetHeight());
+ const auto Direction = m_EndermanHeadPosition - PlayerHeadPosition;
+
+ // Don't check players who are more than SightDistance (64) blocks away:
if (Direction.Length() > m_SightDistance)
{
return false;
}
- // Don't check if the player has a pumpkin on his head
+ // Don't check if the player has a pumpkin on his head:
if (a_Player.GetEquippedHelmet().m_ItemType == E_BLOCK_PUMPKIN)
{
return false;
}
- // If the player's crosshair is within 5 degrees of the enderman, it counts as looking
- auto LookVector = a_Player.GetLookVector();
- auto dot = Direction.Dot(LookVector);
- if (dot <= cos(0.09)) // 0.09 rad ~ 5 degrees
+ const auto LookVector = a_Player.GetLookVector(); // Note: ||LookVector|| is always 1.
+ const auto Cosine = Direction.Dot(LookVector) / Direction.Length(); // a.b / (||a|| * ||b||)
+
+ // If the player's crosshair is within 5 degrees of the enderman, it counts as looking:
+ if ((Cosine < std::cos(0.09)) || (Cosine > std::cos(0))) // 0.09 rad ~ 5 degrees
{
return false;
}
// TODO: Check if endermen are angered through water in Vanilla
- if (!cLineBlockTracer::LineOfSightTrace(*a_Player.GetWorld(), m_EndermanPos, a_Player.GetPosition(), cLineBlockTracer::losAirWater))
+ if (!cLineBlockTracer::LineOfSightTrace(*a_Player.GetWorld(), m_EndermanHeadPosition, PlayerHeadPosition, cLineBlockTracer::losAirWater))
{
// No direct line of sight
return false;
@@ -63,8 +67,9 @@ public:
cPlayer * GetPlayer(void) const { return m_Player; }
protected:
+
cPlayer * m_Player;
- Vector3d m_EndermanPos;
+ Vector3d m_EndermanHeadPosition;
int m_SightDistance;
} ;
@@ -105,7 +110,7 @@ void cEnderman::CheckEventSeePlayer(cChunk & a_Chunk)
return;
}
- cPlayerLookCheck Callback(GetPosition(), m_SightDistance);
+ cPlayerLookCheck Callback(GetPosition().addedY(GetHeight()), m_SightDistance);
if (m_World->ForEachPlayer(Callback))
{
return;
diff --git a/src/Mobs/Enderman.h b/src/Mobs/Enderman.h
index a4864a7f1..1e2a6f52e 100644
--- a/src/Mobs/Enderman.h
+++ b/src/Mobs/Enderman.h
@@ -27,9 +27,6 @@ public:
BLOCKTYPE GetCarriedBlock(void) const {return m_CarriedBlock; }
NIBBLETYPE GetCarriedMeta(void) const {return m_CarriedMeta; }
- /** Returns if the current sky light level is sufficient for the enderman to become aggravated */
- bool CheckLight(void);
-
private:
bool m_bIsScreaming;