Improve Enderman targeting
* Fix look angle checks * Do LOS trace from eye-height
This commit is contained in:
parent
47c0b48bfd
commit
5b6bed6b00
@ -13,9 +13,10 @@
|
|||||||
class cPlayerLookCheck
|
class cPlayerLookCheck
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cPlayerLookCheck(Vector3d a_EndermanPos, int a_SightDistance) :
|
|
||||||
|
cPlayerLookCheck(Vector3d a_EndermanHeadPosition, int a_SightDistance) :
|
||||||
m_Player(nullptr),
|
m_Player(nullptr),
|
||||||
m_EndermanPos(a_EndermanPos),
|
m_EndermanHeadPosition(a_EndermanHeadPosition),
|
||||||
m_SightDistance(a_SightDistance)
|
m_SightDistance(a_SightDistance)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -28,29 +29,32 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't check players who are more than SightDistance (64) blocks away
|
const auto PlayerHeadPosition = a_Player.GetPosition().addedY(a_Player.GetHeight());
|
||||||
auto Direction = m_EndermanPos - a_Player.GetPosition();
|
const auto Direction = m_EndermanHeadPosition - PlayerHeadPosition;
|
||||||
|
|
||||||
|
// Don't check players who are more than SightDistance (64) blocks away:
|
||||||
if (Direction.Length() > m_SightDistance)
|
if (Direction.Length() > m_SightDistance)
|
||||||
{
|
{
|
||||||
return false;
|
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)
|
if (a_Player.GetEquippedHelmet().m_ItemType == E_BLOCK_PUMPKIN)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the player's crosshair is within 5 degrees of the enderman, it counts as looking
|
const auto LookVector = a_Player.GetLookVector(); // Note: ||LookVector|| is always 1.
|
||||||
auto LookVector = a_Player.GetLookVector();
|
const auto Cosine = Direction.Dot(LookVector) / Direction.Length(); // a.b / (||a|| * ||b||)
|
||||||
auto dot = Direction.Dot(LookVector);
|
|
||||||
if (dot <= cos(0.09)) // 0.09 rad ~ 5 degrees
|
// 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Check if endermen are angered through water in Vanilla
|
// 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
|
// No direct line of sight
|
||||||
return false;
|
return false;
|
||||||
@ -63,8 +67,9 @@ public:
|
|||||||
cPlayer * GetPlayer(void) const { return m_Player; }
|
cPlayer * GetPlayer(void) const { return m_Player; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
cPlayer * m_Player;
|
cPlayer * m_Player;
|
||||||
Vector3d m_EndermanPos;
|
Vector3d m_EndermanHeadPosition;
|
||||||
int m_SightDistance;
|
int m_SightDistance;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
@ -105,7 +110,7 @@ void cEnderman::CheckEventSeePlayer(cChunk & a_Chunk)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cPlayerLookCheck Callback(GetPosition(), m_SightDistance);
|
cPlayerLookCheck Callback(GetPosition().addedY(GetHeight()), m_SightDistance);
|
||||||
if (m_World->ForEachPlayer(Callback))
|
if (m_World->ForEachPlayer(Callback))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -27,9 +27,6 @@ public:
|
|||||||
BLOCKTYPE GetCarriedBlock(void) const {return m_CarriedBlock; }
|
BLOCKTYPE GetCarriedBlock(void) const {return m_CarriedBlock; }
|
||||||
NIBBLETYPE GetCarriedMeta(void) const {return m_CarriedMeta; }
|
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:
|
private:
|
||||||
|
|
||||||
bool m_bIsScreaming;
|
bool m_bIsScreaming;
|
||||||
|
Loading…
Reference in New Issue
Block a user