summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSTRWarrior <niels.breuker@hotmail.nl>2014-05-29 13:34:38 +0200
committerarchshift <admin@archshift.com>2014-06-18 05:34:20 +0200
commit9f03682258d949b3b6ddd4fedec93977dedbadde (patch)
tree60e9d02505fd83ef75590e0c8ef9558a7092b63a /src
parentMerge pull request #1101 from Howaner/FenceGate (diff)
downloadcuberite-9f03682258d949b3b6ddd4fedec93977dedbadde.tar
cuberite-9f03682258d949b3b6ddd4fedec93977dedbadde.tar.gz
cuberite-9f03682258d949b3b6ddd4fedec93977dedbadde.tar.bz2
cuberite-9f03682258d949b3b6ddd4fedec93977dedbadde.tar.lz
cuberite-9f03682258d949b3b6ddd4fedec93977dedbadde.tar.xz
cuberite-9f03682258d949b3b6ddd4fedec93977dedbadde.tar.zst
cuberite-9f03682258d949b3b6ddd4fedec93977dedbadde.zip
Diffstat (limited to 'src')
-rw-r--r--src/Mobs/Enderman.cpp90
-rw-r--r--src/Mobs/Enderman.h1
2 files changed, 91 insertions, 0 deletions
diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp
index becc99a86..bd5ed85f1 100644
--- a/src/Mobs/Enderman.cpp
+++ b/src/Mobs/Enderman.cpp
@@ -2,6 +2,66 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Enderman.h"
+#include "../Entities/Player.h"
+
+
+
+
+///////////////////////////////////////////////////////////////////////////
+// cPlayerLookCheck
+class cPlayerLookCheck :
+ public cPlayerListCallback
+{
+public:
+ cPlayerLookCheck(Vector3d a_EndermanPos) :
+ m_EndermanPos(a_EndermanPos),
+ m_Player(NULL)
+ {
+ }
+
+ virtual bool Item(cPlayer * a_Player) override
+ {
+ // Don't check players who are in creative gamemode.
+ if (a_Player->IsGameModeCreative())
+ {
+ return false;
+ }
+
+ Vector3d Direction = m_EndermanPos - a_Player->GetPosition();
+
+ // Don't check players who are more then 64 blocks away.
+ if (Direction.SqrLength() > 64)
+ {
+ return false;
+ }
+
+ // Don't check if the player has a pumpkin on his head.
+ if (a_Player->GetEquippedHelmet().m_ItemType == E_BLOCK_PUMPKIN)
+ {
+ return false;
+ }
+
+ Direction.Normalize();
+
+ Vector3d LookVector = a_Player->GetLookVector();
+ LookVector.Normalize();
+
+ if ((Direction - LookVector).SqrLength() > 0.02)
+ {
+ return false;
+ }
+
+ // TODO: Don't attack the player if there is a wall between the player and the enderman.
+ m_Player = a_Player;
+ return true;
+ }
+
+ cPlayer * GetPlayer(void) const {return m_Player;}
+ bool HasFoundPlayer(void) const {return (m_Player != NULL);}
+protected:
+ cPlayer * m_Player;
+ Vector3d m_EndermanPos;
+} ;
@@ -32,3 +92,33 @@ void cEnderman::GetDrops(cItems & a_Drops, cEntity * a_Killer)
+void cEnderman::Tick(float a_Dt, cChunk & a_Chunk)
+{
+ super::Tick(a_Dt, a_Chunk);
+
+ if (m_Target != NULL)
+ {
+ return;
+ }
+
+ cPlayerLookCheck Callback(GetPosition());
+ if (!m_World->ForEachPlayer(Callback))
+ {
+ return;
+ }
+
+ if (!Callback.HasFoundPlayer())
+ {
+ return;
+ }
+
+ m_bIsScreaming = true;
+ m_Target = Callback.GetPlayer();
+
+ m_World->BroadcastEntityMetadata(*this);
+}
+
+
+
+
+
diff --git a/src/Mobs/Enderman.h b/src/Mobs/Enderman.h
index 32e40e70b..be6e7bdf4 100644
--- a/src/Mobs/Enderman.h
+++ b/src/Mobs/Enderman.h
@@ -18,6 +18,7 @@ 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;
bool IsScreaming(void) const {return m_bIsScreaming; }
BLOCKTYPE GetCarriedBlock(void) const {return CarriedBlock; }