1
0

Fixing Mob spawner behaviour (#4930)

* fixed mob spawner failure (whoopsie in the BlockEntity.GetChunkZ())
Style

* fixed spawning behaviour

* fixed saving entity type saving

* checkstyle

* removed debug log

* removed short saving

* Style

Co-authored-by: 12xx12 <12xx12100@gmail.com>
Co-authored-by: Tiger Wang <ziwei.tiger@outlook.com>
This commit is contained in:
12xx12
2020-09-27 19:02:16 +02:00
committed by GitHub
parent c158569af3
commit 410d6c0045
6 changed files with 137 additions and 143 deletions

View File

@@ -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++;
}
}