summaryrefslogtreecommitdiffstats
path: root/src/BlockEntities
diff options
context:
space:
mode:
author12xx12 <44411062+12xx12@users.noreply.github.com>2020-09-27 19:02:16 +0200
committerGitHub <noreply@github.com>2020-09-27 19:02:16 +0200
commit410d6c00453f2207ddb7a184590251b62b4769fa (patch)
treef204973b0481e4579f79077f2b5cd73dd94f6959 /src/BlockEntities
parentRemove unused Temporary namespace (diff)
downloadcuberite-410d6c00453f2207ddb7a184590251b62b4769fa.tar
cuberite-410d6c00453f2207ddb7a184590251b62b4769fa.tar.gz
cuberite-410d6c00453f2207ddb7a184590251b62b4769fa.tar.bz2
cuberite-410d6c00453f2207ddb7a184590251b62b4769fa.tar.lz
cuberite-410d6c00453f2207ddb7a184590251b62b4769fa.tar.xz
cuberite-410d6c00453f2207ddb7a184590251b62b4769fa.tar.zst
cuberite-410d6c00453f2207ddb7a184590251b62b4769fa.zip
Diffstat (limited to '')
-rw-r--r--src/BlockEntities/BlockEntity.h2
-rw-r--r--src/BlockEntities/MobSpawnerEntity.cpp33
2 files changed, 15 insertions, 20 deletions
diff --git a/src/BlockEntities/BlockEntity.h b/src/BlockEntities/BlockEntity.h
index 1933ed891..c133c186c 100644
--- a/src/BlockEntities/BlockEntity.h
+++ b/src/BlockEntities/BlockEntity.h
@@ -122,7 +122,7 @@ public:
cWorld * GetWorld() const { return m_World; }
int GetChunkX() const { return FAST_FLOOR_DIV(m_Pos.x, cChunkDef::Width); }
- int GetChunkZ() const { return FAST_FLOOR_DIV(m_Pos.y, cChunkDef::Width); }
+ int GetChunkZ() const { return FAST_FLOOR_DIV(m_Pos.z, cChunkDef::Width); }
int GetRelX() const { return m_RelX; }
int GetRelZ() const { return m_RelZ; }
diff --git a/src/BlockEntities/MobSpawnerEntity.cpp b/src/BlockEntities/MobSpawnerEntity.cpp
index d7b72714d..f5fb5c3ff 100644
--- a/src/BlockEntities/MobSpawnerEntity.cpp
+++ b/src/BlockEntities/MobSpawnerEntity.cpp
@@ -124,14 +124,13 @@ void cMobSpawnerEntity::ResetTimer(void)
void cMobSpawnerEntity::SpawnEntity(void)
{
- int NearbyEntities = GetNearbyMonsterNum(m_Entity);
+ auto NearbyEntities = GetNearbyMonsterNum(m_Entity);
if (NearbyEntities >= 6)
{
ResetTimer();
return;
}
- auto MobType = m_Entity;
bool EntitiesSpawned = m_World->DoWithChunk(GetChunkX(), GetChunkZ(), [&](cChunk & a_Chunk)
{
auto & Random = GetRandomProvider();
@@ -144,38 +143,34 @@ void cMobSpawnerEntity::SpawnEntity(void)
break;
}
- Vector3i spawnRelPos(GetRelPos());
- spawnRelPos += Vector3i(
+ auto SpawnRelPos(GetRelPos());
+ SpawnRelPos += Vector3i(
static_cast<int>((Random.RandReal<double>() - Random.RandReal<double>()) * 4.0),
Random.RandInt(-1, 1),
static_cast<int>((Random.RandReal<double>() - Random.RandReal<double>()) * 4.0)
);
- auto chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(spawnRelPos);
- if ((chunk == nullptr) || !chunk->IsValid())
+ auto Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(SpawnRelPos);
+ if ((Chunk == nullptr) || !Chunk->IsValid())
{
continue;
}
- EMCSBiome Biome = chunk->GetBiomeAt(spawnRelPos.x, spawnRelPos.z);
+ EMCSBiome Biome = Chunk->GetBiomeAt(SpawnRelPos.x, SpawnRelPos.z);
- if (cMobSpawner::CanSpawnHere(chunk, spawnRelPos, MobType, Biome))
+ if (cMobSpawner::CanSpawnHere(Chunk, SpawnRelPos, m_Entity, Biome, true))
{
- auto absPos = chunk->RelativeToAbsolute(spawnRelPos);
- auto monster = cMonster::NewMonsterFromType(MobType);
- if (monster == nullptr)
+ auto AbsPos = Chunk->RelativeToAbsolute(SpawnRelPos);
+ auto Monster = cMonster::NewMonsterFromType(m_Entity);
+ if (Monster == nullptr)
{
continue;
}
- monster->SetPosition(absPos);
- monster->SetYaw(Random.RandReal(360.0f));
- if (chunk->GetWorld()->SpawnMobFinalize(std::move(monster)) != cEntity::INVALID_ID)
+ Monster->SetPosition(AbsPos);
+ Monster->SetYaw(Random.RandReal(360.0f));
+ if (Chunk->GetWorld()->SpawnMobFinalize(std::move(Monster)) != cEntity::INVALID_ID)
{
HaveSpawnedEntity = true;
- m_World->BroadcastSoundParticleEffect(
- EffectID::PARTICLE_MOBSPAWN,
- absPos,
- 0
- );
+ m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_MOBSPAWN, AbsPos, 0);
NearbyEntities++;
}
}