summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-06-04 10:19:55 +0200
committerarchshift <admin@archshift.com>2014-06-18 05:36:47 +0200
commit5d4f70a7a52e986343bddde2104f07c797c574c9 (patch)
tree3b6a7b9db10439d51d97f44d8c83d6aa6415e0fd
parentSwapped m_Player and m_EndermanPos (diff)
downloadcuberite-5d4f70a7a52e986343bddde2104f07c797c574c9.tar
cuberite-5d4f70a7a52e986343bddde2104f07c797c574c9.tar.gz
cuberite-5d4f70a7a52e986343bddde2104f07c797c574c9.tar.bz2
cuberite-5d4f70a7a52e986343bddde2104f07c797c574c9.tar.lz
cuberite-5d4f70a7a52e986343bddde2104f07c797c574c9.tar.xz
cuberite-5d4f70a7a52e986343bddde2104f07c797c574c9.tar.zst
cuberite-5d4f70a7a52e986343bddde2104f07c797c574c9.zip
Diffstat (limited to '')
-rw-r--r--src/Mobs/Enderman.cpp45
-rw-r--r--src/Mobs/Enderman.h3
2 files changed, 34 insertions, 14 deletions
diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp
index 40782d0b0..416b541ed 100644
--- a/src/Mobs/Enderman.cpp
+++ b/src/Mobs/Enderman.cpp
@@ -3,6 +3,7 @@
#include "Enderman.h"
#include "../Entities/Player.h"
+#include "../Tracer.h"
@@ -51,13 +52,19 @@ public:
return false;
}
- // TODO: Don't attack the player if there is a wall between the player and the enderman.
+ cTracer LineOfSight(a_Player->GetWorld());
+ if (LineOfSight.Trace(m_EndermanPos, Direction, (int)Direction.Length()))
+ {
+ // No direct line of sight
+ return false;
+ }
+
m_Player = a_Player;
return true;
}
- cPlayer * GetPlayer(void) const {return m_Player;}
- bool HasFoundPlayer(void) const {return (m_Player != NULL);}
+ cPlayer * GetPlayer(void) const { return m_Player; }
+
protected:
cPlayer * m_Player;
Vector3d m_EndermanPos;
@@ -92,33 +99,45 @@ void cEnderman::GetDrops(cItems & a_Drops, cEntity * a_Killer)
-void cEnderman::Tick(float a_Dt, cChunk & a_Chunk)
-{
- super::Tick(a_Dt, a_Chunk);
-
+void cEnderman::CheckEventSeePlayer()
+{
if (m_Target != NULL)
{
return;
}
cPlayerLookCheck Callback(GetPosition());
- if (!m_World->ForEachPlayer(Callback))
+ if (m_World->ForEachPlayer(Callback))
{
return;
}
+
+ ASSERT(Callback.GetPlayer() != NULL);
- if (!Callback.HasFoundPlayer())
+ int CX, CZ;
+ cChunkDef::BlockToChunk(POSX_TOINT, POSZ_TOINT, CX, CZ);
+ if (!GetWorld()->IsChunkLighted(CX, CZ))
{
+ GetWorld()->QueueLightChunk(CX, CZ);
return;
}
- m_bIsScreaming = true;
- m_Target = Callback.GetPlayer();
-
- m_World->BroadcastEntityMetadata(*this);
+ if ((GetWorld()->GetBlockSkyLight(POSX_TOINT, POSY_TOINT, POSZ_TOINT) - GetWorld()->GetSkyDarkness() < 15) && !Callback.GetPlayer()->IsGameModeCreative())
+ {
+ super::EventSeePlayer(Callback.GetPlayer());
+ m_EMState = CHASING;
+ m_bIsScreaming = true;
+ GetWorld()->BroadcastEntityMetadata(*this);
+ }
}
+void cEnderman::EventLosePlayer()
+{
+ super::EventLosePlayer();
+ m_bIsScreaming = false;
+ GetWorld()->BroadcastEntityMetadata(*this);
+} \ No newline at end of file
diff --git a/src/Mobs/Enderman.h b/src/Mobs/Enderman.h
index be6e7bdf4..044b40511 100644
--- a/src/Mobs/Enderman.h
+++ b/src/Mobs/Enderman.h
@@ -18,7 +18,8 @@ public:
CLASS_PROTODEF(cEnderman);
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
- virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
+ virtual void CheckEventSeePlayer(void) override;
+ virtual void EventLosePlayer(void) override;
bool IsScreaming(void) const {return m_bIsScreaming; }
BLOCKTYPE GetCarriedBlock(void) const {return CarriedBlock; }