diff options
author | Mattes D <github@xoft.cz> | 2019-10-11 11:02:53 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2019-10-28 10:45:43 +0100 |
commit | 61904af626b036b6e4e045ca219b2a361aa45a6e (patch) | |
tree | 60b99ab37c9ec87ca96d403b3254a4da023cf6ac /src/BlockEntities/MobSpawnerEntity.cpp | |
parent | Update README.md (#4423) (diff) | |
download | cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar.gz cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar.bz2 cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar.lz cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar.xz cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar.zst cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.zip |
Diffstat (limited to '')
-rw-r--r-- | src/BlockEntities/MobSpawnerEntity.cpp | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/BlockEntities/MobSpawnerEntity.cpp b/src/BlockEntities/MobSpawnerEntity.cpp index 85bdd7ecf..76b86f73a 100644 --- a/src/BlockEntities/MobSpawnerEntity.cpp +++ b/src/BlockEntities/MobSpawnerEntity.cpp @@ -151,36 +151,36 @@ void cMobSpawnerEntity::SpawnEntity(void) break; } - int RelX = m_RelX + static_cast<int>((Random.RandReal<double>() - Random.RandReal<double>()) * 4.0); - int RelY = m_Pos.y + 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); - if ((Chunk == nullptr) || !Chunk->IsValid()) + Vector3i 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()) { continue; } - EMCSBiome Biome = Chunk->GetBiomeAt(RelX, RelZ); + EMCSBiome Biome = chunk->GetBiomeAt(spawnRelPos.x, spawnRelPos.z); - if (cMobSpawner::CanSpawnHere(Chunk, RelX, RelY, RelZ, MobType, Biome)) + if (cMobSpawner::CanSpawnHere(chunk, spawnRelPos, MobType, Biome)) { - double PosX = Chunk->GetPosX() * cChunkDef::Width + RelX; - double PosZ = Chunk->GetPosZ() * cChunkDef::Width + RelZ; - - auto Monster = cMonster::NewMonsterFromType(MobType); - if (Monster == nullptr) + auto absPos = chunk->RelativeToAbsolute(spawnRelPos); + auto monster = cMonster::NewMonsterFromType(MobType); + if (monster == nullptr) { continue; } - - Monster->SetPosition(PosX, RelY, PosZ); - 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, - Vector3d(PosX, RelY, PosZ).Floor(), + absPos, 0 ); NearbyEntities++; |