QtCraft API C++ classes QML types Handbook

QcEntities Class

The entity register of a world (decision E-364): every entity is a QcEntity of one kind and lives in the table of its kind, which also carries the kind's own behaviour (QcMobManager: creature AI and spawning; QcItemEntityManager: items falling, merging and ageing; QcFallingBlockManager; QcArmourStandManager; QcMovingBlocks; QcMinecartManager: carts on rails; QcExperienceOrbManager; QcProjectileManager: arrows; QcPrimedExplosives: lit explosives; QcBoatManager: boats). More...

Header: #include <server/entities/QcEntities.h>

Public Types

ChunkLoadedFunction
Clients

Public Functions

void applyLimits(const QcServerLimits &limits)
QcBoatManager &boats()
const QcBoatManager &boats() const
std::optional<QcAabb> boxOf(const QcEntity &entity) const
const QcEntities::Clients &clients() const
QcMobManager &creatures()
const QcMobManager &creatures() const
bool diedThisTick(quint32 id) const
void displace(QcEntity &entity, const QcVec3 &delta) const
QcPrimedExplosives &explosives()
const QcPrimedExplosives &explosives() const
QcFallingBlockManager &fallingBlocks()
const QcFallingBlockManager &fallingBlocks() const
void forEach(const Visit &visit)
void forEach(const Visit &visit) const
void forEachBody(const Visit &visit)
void forEachBody(const Visit &visit) const
void forgetDeaths()
QcHangingManager &hangings()
const QcHangingManager &hangings() const
QcItemEntityManager &items()
const QcItemEntityManager &items() const
void markStale(quint32 id) const
QcMinecartManager &minecarts()
const QcMinecartManager &minecarts() const
QcMovingBlocks &movingBlocks()
const QcMovingBlocks &movingBlocks() const
quint32 newId()
void noteDeath(quint32 id)
QcExperienceOrbManager &orbs()
const QcExperienceOrbManager &orbs() const
bool overlapsLiving(const QList<QcAabb> &boxes) const
QcProjectileManager &projectiles()
const QcProjectileManager &projectiles() const
QSet<QcChunkPos> settle(const QcEntities::ChunkLoadedFunction &isLoaded, quint64 loadedEpoch)
QcArmourStandManager &stands()
const QcArmourStandManager &stands() const

Static Public Members

QcChunkPos chunkOf(const QcEntity &entity)
void settle(List &entities, const QcEntities::ChunkLoadedFunction &isLoaded)

Detailed Description

Players are the clients of the server and are only visited here. What exists once for all kinds lives in this class: ids, visiting every entity in a fixed order, the chunk an entity belongs to and whether it rests there, the box of a body, moving a body from outside (pistons), knowing which clients must hear of an entity again.

Member Type Documentation

[alias] QcEntities::ChunkLoadedFunction

Returns whether the chunk is loaded.

[alias] QcEntities::Clients

The clients of the server.

Member Function Documentation

void QcEntities::applyLimits(const QcServerLimits &limits)

Hands the entity limits of the config (limits) to the tables of the kinds (decision E-349).

QcBoatManager &QcEntities::boats()

Returns the table of the boats.

const QcBoatManager &QcEntities::boats() const

Returns the table of the boats.

std::optional<QcAabb> QcEntities::boxOf(const QcEntity &entity) const

Returns where the body of entity is in the world; nothing for sliding blocks, frames and paintings (hangings) and for creatures of a kind the content does not know.

[static] QcChunkPos QcEntities::chunkOf(const QcEntity &entity)

Returns the chunk entity belongs to: the one holding its feet.

const QcEntities::Clients &QcEntities::clients() const

Returns the clients, whose players are entities too (only playing, living ones are visited).

QcMobManager &QcEntities::creatures()

Returns the table of the creatures (AI and spawning).

const QcMobManager &QcEntities::creatures() const

Returns the table of the creatures (AI and spawning).

bool QcEntities::diedThisTick(quint32 id) const

Returns whether the entity id died in this tick.

void QcEntities::displace(QcEntity &entity, const QcVec3 &delta) const

Moves the body of entity by delta from outside its own motion (a piston pushed it); its kind takes note: the player gets his new position, an item stops resting, a stand is sent again. A player who rides a minecart stays in it: only the cart moves (decision E-382); the same for the driver of a boat (decision E-920).

QcPrimedExplosives &QcEntities::explosives()

Returns the table of the lit explosives.

const QcPrimedExplosives &QcEntities::explosives() const

Returns the table of the lit explosives.

QcFallingBlockManager &QcEntities::fallingBlocks()

Returns the table of the falling blocks.

const QcFallingBlockManager &QcEntities::fallingBlocks() const

Returns the table of the falling blocks.

template <typename Visit> void QcEntities::forEach(const Visit &visit)

Visits every entity with visit in a fixed order: creatures, players (those playing and alive), falling blocks, sliding blocks, items, armour stands, minecarts, experience orbs, projectiles, lit explosives, frames and paintings, boats; each kind in the order of its table. visit takes a QcEntity and must not add or remove entities.

template <typename Visit> void QcEntities::forEach(const Visit &visit) const

Visits every entity in the same order, read-only.

template <typename Visit> void QcEntities::forEachBody(const Visit &visit)

Visits the bodies only with visit: every kind but sliding blocks, which only show a move.

template <typename Visit> void QcEntities::forEachBody(const Visit &visit) const

Visits the bodies only, read-only.

void QcEntities::forgetDeaths()

Forgets the deaths of the tick.

QcHangingManager &QcEntities::hangings()

Returns the table of the item frames and paintings.

const QcHangingManager &QcEntities::hangings() const

Returns the table of the item frames and paintings.

QcItemEntityManager &QcEntities::items()

Returns the table of the dropped items.

const QcItemEntityManager &QcEntities::items() const

Returns the table of the dropped items.

void QcEntities::markStale(quint32 id) const

Clients that know the entity id get its spawn again (a new look, armour, pose or place).

QcMinecartManager &QcEntities::minecarts()

Returns the table of the minecarts.

const QcMinecartManager &QcEntities::minecarts() const

Returns the table of the minecarts.

QcMovingBlocks &QcEntities::movingBlocks()

Returns the table of the blocks a piston slides.

const QcMovingBlocks &QcEntities::movingBlocks() const

Returns the table of the blocks a piston slides.

quint32 QcEntities::newId()

Returns a new id for any entity, players included; never given twice while the world is open.

void QcEntities::noteDeath(quint32 id)

The entity id died in this tick: its removal tells clients to play the death animation.

QcExperienceOrbManager &QcEntities::orbs()

Returns the table of the experience orbs.

const QcExperienceOrbManager &QcEntities::orbs() const

Returns the table of the experience orbs.

bool QcEntities::overlapsLiving(const QList<QcAabb> &boxes) const

Returns whether any of boxes (world space) overlaps a living body: a playing player or a creature.

QcProjectileManager &QcEntities::projectiles()

Returns the table of the projectiles (arrows).

const QcProjectileManager &QcEntities::projectiles() const

Returns the table of the projectiles (arrows).

[static] template <typename List> void QcEntities::settle(List &entities, const QcEntities::ChunkLoadedFunction &isLoaded)

Rests the entities of one table whose chunk is not loaded (isLoaded) and wakes the others (tests of a kind's behaviour on its own).

QSet<QcChunkPos> QcEntities::settle(const QcEntities::ChunkLoadedFunction &isLoaded, quint64 loadedEpoch)

Rests every entity whose chunk is not loaded (isLoaded) and wakes the others; runs at the start of every tick after the chunks loaded, so all kinds rest by the same rule. Players never rest, nor do sliding blocks (a piston moves them only within loaded chunks and they last three ticks); lit explosives, frames and paintings are never touched. loadedEpoch changes whenever a chunk enters or leaves the world (QcServerWorld::loadedEpoch): while it stays, only entities that are new or changed their chunk are looked up. Returns the chunks of the entities looked up that rest (strays: in a chunk that is not loaded, decision E-374).

QcArmourStandManager &QcEntities::stands()

Returns the table of the armour stands.

const QcArmourStandManager &QcEntities::stands() const

Returns the table of the armour stands.