summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2015-07-16 23:22:48 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2015-07-16 23:22:48 +0200
commitc633dd8cec149565538499b2e50ae97fd15b928c (patch)
treed109f84a573c4eaeeeb47e474bc2e9268adde90a
parentMerge pull request #2364 from hallucino/ageable-mobs (diff)
parentImproved spider AI (diff)
downloadcuberite-c633dd8cec149565538499b2e50ae97fd15b928c.tar
cuberite-c633dd8cec149565538499b2e50ae97fd15b928c.tar.gz
cuberite-c633dd8cec149565538499b2e50ae97fd15b928c.tar.bz2
cuberite-c633dd8cec149565538499b2e50ae97fd15b928c.tar.lz
cuberite-c633dd8cec149565538499b2e50ae97fd15b928c.tar.xz
cuberite-c633dd8cec149565538499b2e50ae97fd15b928c.tar.zst
cuberite-c633dd8cec149565538499b2e50ae97fd15b928c.zip
Diffstat (limited to '')
-rw-r--r--src/Mobs/Spider.cpp42
-rw-r--r--src/Mobs/Spider.h2
-rw-r--r--src/World.h1
3 files changed, 44 insertions, 1 deletions
diff --git a/src/Mobs/Spider.cpp b/src/Mobs/Spider.cpp
index 184a1d912..a9da28750 100644
--- a/src/Mobs/Spider.cpp
+++ b/src/Mobs/Spider.cpp
@@ -3,7 +3,8 @@
#include "Spider.h"
-
+#include "../World.h"
+#include "../Entities/Player.h"
@@ -33,3 +34,42 @@ void cSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer)
+
+void cSpider::EventSeePlayer(cEntity * a_Entity)
+{
+ if (!GetWorld()->IsChunkLighted(GetChunkX(), GetChunkZ()))
+ {
+ GetWorld()->QueueLightChunk(GetChunkX(), GetChunkZ());
+ return;
+ }
+
+ if (!static_cast<cPlayer *>(a_Entity)->IsGameModeCreative() && (GetWorld()->GetBlockBlockLight(this->GetPosition()) <= 9))
+ {
+ super::EventSeePlayer(a_Entity);
+ }
+}
+
+
+
+
+
+bool cSpider::DoTakeDamage(TakeDamageInfo & a_TDI)
+{
+ if (!super::DoTakeDamage(a_TDI))
+ {
+ return false;
+ }
+
+ // If the source of the damage is not from an pawn entity, switch to idle
+ if ((a_TDI.Attacker == nullptr) || !a_TDI.Attacker->IsPawn())
+ {
+ m_EMState = IDLE;
+ }
+ else
+ {
+ // If the source of the damage is from a pawn entity, chase that entity
+ m_EMState = CHASING;
+ }
+
+ return true;
+}
diff --git a/src/Mobs/Spider.h b/src/Mobs/Spider.h
index 24134c00f..4f9df7887 100644
--- a/src/Mobs/Spider.h
+++ b/src/Mobs/Spider.h
@@ -18,6 +18,8 @@ public:
CLASS_PROTODEF(cSpider)
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
+ virtual void EventSeePlayer(cEntity *) override;
+ virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override;
} ;
diff --git a/src/World.h b/src/World.h
index 4e85dc5e5..ab2b197c5 100644
--- a/src/World.h
+++ b/src/World.h
@@ -484,6 +484,7 @@ public:
BLOCKTYPE GetBlock (const Vector3i & a_Pos) { return GetBlock( a_Pos.x, a_Pos.y, a_Pos.z); }
NIBBLETYPE GetBlockMeta(const Vector3i & a_Pos) { return GetBlockMeta( a_Pos.x, a_Pos.y, a_Pos.z); }
void SetBlockMeta(const Vector3i & a_Pos, NIBBLETYPE a_MetaData) { SetBlockMeta( a_Pos.x, a_Pos.y, a_Pos.z, a_MetaData); }
+ NIBBLETYPE GetBlockBlockLight(const Vector3i & a_Pos) { return GetBlockBlockLight( a_Pos.x, a_Pos.y, a_Pos.z); }
// tolua_end
/** Writes the block area into the specified coords.