summaryrefslogtreecommitdiffstats
path: root/src/BlockEntities/MobSpawnerEntity.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/BlockEntities/MobSpawnerEntity.cpp')
-rw-r--r--src/BlockEntities/MobSpawnerEntity.cpp41
1 files changed, 13 insertions, 28 deletions
diff --git a/src/BlockEntities/MobSpawnerEntity.cpp b/src/BlockEntities/MobSpawnerEntity.cpp
index 5246ae6ca..8a4cc4d38 100644
--- a/src/BlockEntities/MobSpawnerEntity.cpp
+++ b/src/BlockEntities/MobSpawnerEntity.cpp
@@ -1,4 +1,4 @@
-
+
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "MobSpawnerEntity.h"
@@ -138,47 +138,36 @@ void cMobSpawnerEntity::SpawnEntity(void)
return;
}
- class cCallback : public cChunkCallback
- {
- public:
- cCallback(int a_RelX, int a_RelY, int a_RelZ, eMonsterType a_MobType, int a_NearbyEntitiesNum) :
- m_RelX(a_RelX),
- m_RelY(a_RelY),
- m_RelZ(a_RelZ),
- m_MobType(a_MobType),
- m_NearbyEntitiesNum(a_NearbyEntitiesNum)
- {
- }
-
- virtual bool Item(cChunk * a_Chunk)
+ auto MobType = m_Entity;
+ bool EntitiesSpawned = m_World->DoWithChunk(GetChunkX(), GetChunkZ(), [&](cChunk & a_Chunk)
{
auto & Random = GetRandomProvider();
- bool EntitiesSpawned = false;
+ bool HaveSpawnedEntity = false;
for (size_t i = 0; i < 4; i++)
{
- if (m_NearbyEntitiesNum >= 6)
+ if (NearbyEntities >= 6)
{
break;
}
int RelX = m_RelX + static_cast<int>((Random.RandReal<double>() - Random.RandReal<double>()) * 4.0);
- int RelY = m_RelY + Random.RandInt(-1, 1);
+ int RelY = m_PosY + Random.RandInt(-1, 1);
int RelZ = m_RelZ + static_cast<int>((Random.RandReal<double>() - Random.RandReal<double>()) * 4.0);
- cChunk * Chunk = a_Chunk->GetRelNeighborChunkAdjustCoords(RelX, RelZ);
+ cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelX, RelZ);
if ((Chunk == nullptr) || !Chunk->IsValid())
{
continue;
}
EMCSBiome Biome = Chunk->GetBiomeAt(RelX, RelZ);
- if (cMobSpawner::CanSpawnHere(Chunk, RelX, RelY, RelZ, m_MobType, Biome))
+ if (cMobSpawner::CanSpawnHere(Chunk, RelX, RelY, RelZ, MobType, Biome))
{
double PosX = Chunk->GetPosX() * cChunkDef::Width + RelX;
double PosZ = Chunk->GetPosZ() * cChunkDef::Width + RelZ;
- auto Monster = cMonster::NewMonsterFromType(m_MobType);
+ auto Monster = cMonster::NewMonsterFromType(MobType);
if (Monster == nullptr)
{
continue;
@@ -188,7 +177,7 @@ void cMobSpawnerEntity::SpawnEntity(void)
Monster->SetYaw(Random.RandReal(360.0f));
if (Chunk->GetWorld()->SpawnMobFinalize(std::move(Monster)) != cEntity::INVALID_ID)
{
- EntitiesSpawned = true;
+ HaveSpawnedEntity = true;
Chunk->BroadcastSoundParticleEffect(
EffectID::PARTICLE_MOBSPAWN,
static_cast<int>(PosX * 8.0),
@@ -196,19 +185,15 @@ void cMobSpawnerEntity::SpawnEntity(void)
static_cast<int>(PosZ * 8.0),
0
);
- m_NearbyEntitiesNum++;
+ NearbyEntities++;
}
}
}
return EntitiesSpawned;
}
- protected:
- int m_RelX, m_RelY, m_RelZ;
- eMonsterType m_MobType;
- int m_NearbyEntitiesNum;
- } Callback(m_RelX, m_PosY, m_RelZ, m_Entity, NearbyEntities);
+ );
- if (m_World->DoWithChunk(GetChunkX(), GetChunkZ(), Callback))
+ if (EntitiesSpawned)
{
ResetTimer();
}