MCPcopy Create free account
hub / github.com/cuberite/cuberite / SpawnMobs

Method SpawnMobs

src/Chunk.cpp:495–556  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

493
494
495void cChunk::SpawnMobs(cMobSpawner& a_MobSpawner)
496{
497 int Center_X,Center_Y,Center_Z;
498 getRandomBlockCoords(Center_X,Center_Y,Center_Z);
499
500 BLOCKTYPE PackCenterBlock = GetBlock(Center_X, Center_Y, Center_Z);
501 if (a_MobSpawner.CheckPackCenter(PackCenterBlock))
502 {
503 a_MobSpawner.NewPack();
504 int NumberOfTries = 0;
505 int NumberOfSuccess = 0;
506 int MaxNbOfSuccess = 4; // this can be changed during the process for Wolves and Ghass
507 while (NumberOfTries < 12 && NumberOfSuccess < MaxNbOfSuccess)
508 {
509 const int HorizontalRange = 20; // MG TODO : relocate
510 const int VerticalRange = 0; // MG TODO : relocate
511 int Try_X, Try_Y, Try_Z;
512 getThreeRandomNumber(Try_X, Try_Y, Try_Z, 2*HorizontalRange+1 , 2*VerticalRange+1 , 2*HorizontalRange+1);
513 Try_X -= HorizontalRange;
514 Try_Y -= VerticalRange;
515 Try_Z -= HorizontalRange;
516 Try_X += Center_X;
517 Try_Y += Center_Y;
518 Try_Z += Center_Z;
519
520 ASSERT(Try_Y > 0);
521 ASSERT(Try_Y < cChunkDef::Height-1);
522
523 EMCSBiome Biome = m_ChunkMap->GetBiomeAt (Try_X, Try_Z);
524 // MG TODO :
525 // Moon cycle (for slime)
526 // check player and playerspawn presence < 24 blocks
527 // check mobs presence on the block
528
529 // MG TODO : check that "Level" really means Y
530
531 /*
532 NIBBLETYPE SkyLight = 0;
533
534 NIBBLETYPE BlockLight = 0;
535 */
536
537 if (IsLightValid())
538 {
539 cEntity* newMob = a_MobSpawner.TryToSpawnHere(this, Try_X, Try_Y, Try_Z, Biome, MaxNbOfSuccess);
540 if (newMob)
541 {
542 int WorldX, WorldY, WorldZ;
543 PositionToWorldPosition(Try_X, Try_Y, Try_Z, WorldX, WorldY, WorldZ);
544 double ActualX = WorldX + 0.5;
545 double ActualZ = WorldZ + 0.5;
546 newMob->SetPosition(ActualX, WorldY, ActualZ);
547 LOGD("Spawning %s #%i at %d,%d,%d",newMob->GetClass(),newMob->GetUniqueID(),WorldX, WorldY, WorldZ);
548 NumberOfSuccess++;
549 }
550 }
551
552 NumberOfTries++;

Callers 1

TickMobsMethod · 0.45

Calls 7

CheckPackCenterMethod · 0.80
NewPackMethod · 0.80
TryToSpawnHereMethod · 0.80
GetClassMethod · 0.80
GetBiomeAtMethod · 0.45
SetPositionMethod · 0.45
GetUniqueIDMethod · 0.45

Tested by

no test coverage detected