summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLogicParrot <LogicParrot@users.noreply.github.com>2016-03-23 09:44:51 +0100
committerLogicParrot <LogicParrot@users.noreply.github.com>2016-03-23 09:44:51 +0100
commit56f3fc954e02236522df7d7edde7273be387d21f (patch)
treedcf594053aefeb4ae2ffc5129648381a95f141b7
parentMerge pull request #3086 from cuberite/revert-2872-LuaCallback (diff)
parentRewrite mob tick code (diff)
downloadcuberite-56f3fc954e02236522df7d7edde7273be387d21f.tar
cuberite-56f3fc954e02236522df7d7edde7273be387d21f.tar.gz
cuberite-56f3fc954e02236522df7d7edde7273be387d21f.tar.bz2
cuberite-56f3fc954e02236522df7d7edde7273be387d21f.tar.lz
cuberite-56f3fc954e02236522df7d7edde7273be387d21f.tar.xz
cuberite-56f3fc954e02236522df7d7edde7273be387d21f.tar.zst
cuberite-56f3fc954e02236522df7d7edde7273be387d21f.zip
-rw-r--r--src/World.cpp59
1 files changed, 41 insertions, 18 deletions
diff --git a/src/World.cpp b/src/World.cpp
index dcc36f5f3..365447428 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -1135,28 +1135,51 @@ void cWorld::TickMobs(std::chrono::milliseconds a_Dt)
} // for i - AllFamilies[]
} // if (Spawning enabled)
- // move close mobs
- cMobProximityCounter::sIterablePair allCloseEnoughToMoveMobs = MobCensus.GetProximityCounter().getMobWithinThosesDistances(-1, 64 * 16);// MG TODO : deal with this magic number (the 16 is the size of a block)
- for (cMobProximityCounter::tDistanceToMonster::const_iterator itr = allCloseEnoughToMoveMobs.m_Begin; itr != allCloseEnoughToMoveMobs.m_End; ++itr)
+ class cCallback : public cEntityCallback
{
- cEntity & Entity = itr->second.m_Monster;
- cChunk * Chunk = Entity.GetParentChunk();
- if (!Entity.IsTicking())
+ virtual bool Item(cEntity * a_Entity) override
{
- ++itr;
- continue;
+ 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;
}
- ASSERT(Chunk == &(itr->second.m_Chunk));
- Entity.Tick(a_Dt, *Chunk);
- ASSERT(Chunk == &(itr->second.m_Chunk));
- }
+ public:
+ std::chrono::milliseconds m_Dt;
+ } Callback;
- // remove too far mobs
- cMobProximityCounter::sIterablePair allTooFarMobs = MobCensus.GetProximityCounter().getMobWithinThosesDistances(128 * 16, -1);// MG TODO : deal with this magic number (the 16 is the size of a block)
- for (cMobProximityCounter::tDistanceToMonster::const_iterator itr = allTooFarMobs.m_Begin; itr != allTooFarMobs.m_End; ++itr)
- {
- itr->second.m_Monster.Destroy(true);
- }
+ Callback.m_Dt = a_Dt;
+ ForEachEntity(Callback);
}