summaryrefslogtreecommitdiffstats
path: root/src/World.cpp
diff options
context:
space:
mode:
authorLogicParrot <LogicParrot@users.noreply.github.com>2016-04-06 11:16:14 +0200
committerLogicParrot <LogicParrot@users.noreply.github.com>2016-04-06 11:16:14 +0200
commitc9e80cdeaeba33b22661bdcca77b5565f89d9afa (patch)
treed086e85a69ea7fa9dcfd11b8e2e34f04fc1c0dc8 /src/World.cpp
parentMerge pull request #3100 from LogicParrot/mobTick2 (diff)
downloadcuberite-c9e80cdeaeba33b22661bdcca77b5565f89d9afa.tar
cuberite-c9e80cdeaeba33b22661bdcca77b5565f89d9afa.tar.gz
cuberite-c9e80cdeaeba33b22661bdcca77b5565f89d9afa.tar.bz2
cuberite-c9e80cdeaeba33b22661bdcca77b5565f89d9afa.tar.lz
cuberite-c9e80cdeaeba33b22661bdcca77b5565f89d9afa.tar.xz
cuberite-c9e80cdeaeba33b22661bdcca77b5565f89d9afa.tar.zst
cuberite-c9e80cdeaeba33b22661bdcca77b5565f89d9afa.zip
Diffstat (limited to 'src/World.cpp')
-rw-r--r--src/World.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/World.cpp b/src/World.cpp
index dcf02f02a..d8b77647a 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -1131,6 +1131,52 @@ void cWorld::TickMobs(std::chrono::milliseconds a_Dt)
}
} // for i - AllFamilies[]
} // if (Spawning enabled)
+
+ class cCallback : public cEntityCallback
+ {
+ virtual bool Item(cEntity * a_Entity) override
+ {
+ if (!a_Entity->IsMob())
+ {
+ return false;
+ }
+ if (!a_Entity->IsTicking())
+ {
+ return false;
+ }
+
+ auto Monster = static_cast<cMonster *>(a_Entity);
+ ASSERT(Monster->GetParentChunk() != nullptr); // A ticking entity must have a valid parent chunk
+
+ // Tick close mobs
+ if (Monster->GetParentChunk()->HasAnyClients())
+ {
+ Monster->Tick(m_Dt, *(a_Entity->GetParentChunk()));
+ }
+ // Destroy far hostile mobs
+ else if ((Monster->GetMobFamily() == cMonster::eFamily::mfHostile))
+ {
+ if (Monster->GetMobType() != eMonsterType::mtWolf)
+ {
+ Monster->Destroy(true);
+ }
+ else
+ {
+ auto Wolf = static_cast<cWolf *>(Monster);
+ if (Wolf->IsAngry())
+ {
+ Monster->Destroy(true);
+ }
+ }
+ }
+ return false;
+ }
+ public:
+ std::chrono::milliseconds m_Dt;
+ } Callback;
+
+ Callback.m_Dt = a_Dt;
+ ForEachEntity(Callback);
}