QtCraft API C++ classes QML types Handbook

QcSpawners Class

The monster spawners of the loaded chunks (decision E-520): one entry per spawner block with the creature kind it brings forth and the ticks left until its next cycle, filed by chunk so that they are saved, unloaded and loaded with their chunk (QcBlockEntityRecord::Table::Spawners). More...

Header: #include <server/spawners/QcSpawners.h>

Public Types

struct Entry

Public Functions

QcSpawners::Entry *at(QcBlockPos pos)
const QcSpawners::Entry *at(QcBlockPos pos) const
void clear()
bool contains(QcBlockPos pos) const
void forgetChunk(QcChunkPos pos)
bool isSpawner(QcBlockId block) const
void noteBlock(QcBlockPos pos, QcBlockId before, QcBlockId after)
void noteChunk(QcChunkPos pos, const QcChunk &chunk, quint32 sections)
QList<QcBlockPos> positions() const
QList<QcBlockPos> positionsIn(QcChunkPos pos) const
void restore(const QList<QcSpawners::Entry> &entries, const QcChunk &chunk)
QList<QcSpawners::Entry> savedOf(QcChunkPos pos) const
bool set(const QcSpawners::Entry &entry)
qsizetype size() const
QList<QcBlockPos> takeChanges()
QList<QcSpawners::Entry> takeChunk(QcChunkPos pos)

Static Public Members

const quint32 firstDelay
const quint32 maxDelay

Detailed Description

Kept in step with the blocks by QcServerWorld: a spawner block set anywhere gets an entry with its block's kind (QcSpawnerDefinition::mob), one that goes loses it; a chunk that arrives gets entries for its spawner blocks, then restore() puts back what was saved. The rules that use the entries are QcSpawnerRules.

Member Function Documentation

QcSpawners::Entry *QcSpawners::at(QcBlockPos pos)

Returns the entry of the spawner at pos for changes, or null.

const QcSpawners::Entry *QcSpawners::at(QcBlockPos pos) const

Returns the entry of the spawner at pos, or null.

void QcSpawners::clear()

Forgets every spawner.

bool QcSpawners::contains(QcBlockPos pos) const

Returns whether a spawner is at pos.

void QcSpawners::forgetChunk(QcChunkPos pos)

Forgets the entries of the chunk at pos (it left the world or was generated again).

bool QcSpawners::isSpawner(QcBlockId block) const

Returns whether block is a spawner block.

void QcSpawners::noteBlock(QcBlockPos pos, QcBlockId before, QcBlockId after)

The block at pos changed from before to after (QcServerWorld::setBlock).

void QcSpawners::noteChunk(QcChunkPos pos, const QcChunk &chunk, quint32 sections)

The chunk chunk at pos entered the world: entries for its spawner blocks in the sections marked in sections.

QList<QcBlockPos> QcSpawners::positions() const

Returns every entry in position order (a stable order for the rules' random draws).

QList<QcBlockPos> QcSpawners::positionsIn(QcChunkPos pos) const

Returns the positions of the spawners in the chunk at pos.

void QcSpawners::restore(const QList<QcSpawners::Entry> &entries, const QcChunk &chunk)

Puts back the saved entries where chunk still has a spawner block (others are dropped).

QList<QcSpawners::Entry> QcSpawners::savedOf(QcChunkPos pos) const

Returns the entries of the chunk at pos in position order, to be saved; takeChunk() also forgets them.

bool QcSpawners::set(const QcSpawners::Entry &entry)

Replaces the entry at a spawner block with entry (/setblock with a kind, the world generator); returns false where no spawner block is.

qsizetype QcSpawners::size() const

Returns the number of spawners.

QList<QcBlockPos> QcSpawners::takeChanges()

Returns the spawners whose kind changed, appeared or went since the last call (clients are told; a new delay or confined alone is no change).

QList<QcSpawners::Entry> QcSpawners::takeChunk(QcChunkPos pos)

Returns the entries of the chunk at pos in position order and forgets them.

Member Variable Documentation

const quint32 QcSpawners::firstDelay

Ticks a new spawner waits before its first cycle (the reference's 20).

const quint32 QcSpawners::maxDelay

Longest delay kept from a save (damaged values are cut to it).