QtCraft API C++ classes QML types Handbook

QcNaturalSpawner Class

Creatures that come by themselves (decision E-422): monsters every tick around the living players by the original game's rules (decision E-836: QcSpawnLight, QcSpawnGround, QcMonsterCap; in the spawn areas of structures only their kinds, decision E-871: QcSpawnAreas), the other kinds every second up to four spawn attempts around each living player by time of day, place, light and the data's spawn rules, within the caps per player; and the creatures of a chunk seen for the first time: its group of persistent animals (decision E-086) and the creatures of the village pieces in it (decision E-404). More...

Header: #include <server/spawning/QcNaturalSpawner.h>

Public Types

struct Sky
NextId
PlayerView

Public Functions

QcNaturalSpawner(QcMobManager &mobs, std::shared_ptr<const QcContentRegistry> content, quint64 seed, QRandomGenerator &random)
QcMonsterCap monsterCap(const QcServerWorld &world, const QList<QcNaturalSpawner::PlayerView> &players) const
void setCaps(int hostile, int passive, int ambient)
void setWaterCaps(int fish, int large)
const QcSpawnAreas &spawnAreas() const
void spawnChunkAnimals(const QcServerWorld &world, QcChunkPos pos, const QcChunk &chunk, const QcNaturalSpawner::NextId &nextEntityId)
void spawnVillageMobs(const QcServerWorld &world, QcChunkPos pos, const QcNaturalSpawner::NextId &nextEntityId)
bool spawnsInChunk(QcCreatureKindId type, QcChunkPos pos) const
void tick(QcServerWorld &world, const QList<QcNaturalSpawner::PlayerView> &players, QcNaturalSpawner::Sky sky, double dt, const QcNaturalSpawner::NextId &nextEntityId)

Static Public Members

const int ambientCapPerPlayer
const double animalSearchDistance
const int caveDepth
const double chunkAnimalChance
bool isMonster(const QcMobDefinition &definition)
const int monsterAttemptsPerTick
const int monsterCapPer289Chunks
const double monsterRadiusMax
const double monsterRadiusMin
const int passiveCapPerPlayer
const double spawnRadiusMax
const double spawnRadiusMin

Detailed Description

Part of QcMobManager, which owns the creatures; it draws from the manager's random sequence, monsters from a sequence of their own.

Member Type Documentation

[alias] QcNaturalSpawner::NextId

Gives the entity id of the next creature.

[alias] QcNaturalSpawner::PlayerView

What the spawner knows about a player (QcMobExchange::PlayerView).

Member Function Documentation

QcNaturalSpawner::QcNaturalSpawner(QcMobManager &mobs, std::shared_ptr<const QcContentRegistry> content, quint64 seed, QRandomGenerator &random)

mobs owns the creatures this adds and random is its sequence; both outlive the spawner. Kinds from content, chunk chances decided by the world seed.

[static] bool QcNaturalSpawner::isMonster(const QcMobDefinition &definition)

Returns whether creatures of definition spawn as monsters (QcMonsterCap): hostile ones that walk or fly on land, not water or ambient creatures.

QcMonsterCap QcNaturalSpawner::monsterCap(const QcServerWorld &world, const QList<QcNaturalSpawner::PlayerView> &players) const

Returns the monster cap of this moment in world: the areas of the living ones of players and the monsters in them.

void QcNaturalSpawner::setCaps(int hostile, int passive, int ambient)

Sets the caps: hostile monsters per QcMonsterCap::areaChunks loaded chunks around players, passive and ambient creatures around one player at most.

void QcNaturalSpawner::setWaterCaps(int fish, int large)

Sets the caps of water creatures spawning by themselves around one player: fish for fish (decision E-502), large for larger ones like the squid (QcAquaticDefinition::Cap::Large, decision E-974).

const QcSpawnAreas &QcNaturalSpawner::spawnAreas() const

Returns the spawn areas of structures around the players, as of the last monster pass.

void QcNaturalSpawner::spawnChunkAnimals(const QcServerWorld &world, QcChunkPos pos, const QcChunk &chunk, const QcNaturalSpawner::NextId &nextEntityId)

Spawns the group of animals of the new chunk chunk at pos in world, with ids from nextEntityId (QcNaturalSpawner::chunkAnimalChance).

void QcNaturalSpawner::spawnVillageMobs(const QcServerWorld &world, QcChunkPos pos, const QcNaturalSpawner::NextId &nextEntityId)

Spawns the village creatures of the chunk at pos of world seen for the first time, with ids from nextEntityId (QcChunkSpawns).

bool QcNaturalSpawner::spawnsInChunk(QcCreatureKindId type, QcChunkPos pos) const

Returns whether the seed lets a mob of the kind type with a spawnChunkChance below 1 spawn in the chunk at pos (slime chunks).

void QcNaturalSpawner::tick(QcServerWorld &world, const QList<QcNaturalSpawner::PlayerView> &players, QcNaturalSpawner::Sky sky, double dt, const QcNaturalSpawner::NextId &nextEntityId)

One tick of dt seconds in world under sky with natural spawning on: monsters around every living one of players, and once a second the other kinds, with ids from nextEntityId.

Member Variable Documentation

const double QcNaturalSpawner::animalSearchDistance

Animals spawn naturally around a player only while none is awake within this distance.

const int QcNaturalSpawner::caveDepth

Blocks of rock above a cave floor for it to count as dark enough for cave spawns.

const double QcNaturalSpawner::chunkAnimalChance

Share of newly generated chunks that get a group of animals.

const int QcNaturalSpawner::monsterAttemptsPerTick

Places tried for monsters around each living player in every tick, in its area of QcMonsterCap::areaChunks chunks.