QtCraft API C++ classes QML types Handbook

QcBlockEntities Class

State that belongs to single blocks of the world (decision E-357), filed by chunk so that it moves, drops, is forgotten, saved and loaded with its chunk: the contents of containers (chests, barrels, hoppers with their cooldown, dispensers) and machines (furnaces), the timers of growing saplings, the memory of circuit components (torches burning out, openers last seen powered, pistons in the middle of extending) and the scheduled ticks of components. More...

Header: #include <server/blockentities/QcBlockEntities.h>

Public Types

struct Chunk
struct ChunkIndex
struct Container
struct Limits
struct Machine
struct Memory
struct Sapling
struct Spill
enum class SaplingStep { Keep, Remove, Grew }

Public Functions

bool carriesContents(QcBlockPos pos, QcBlockId block) const
std::optional<QcBlockEntities::Chunk> chunk(QcChunkPos pos) const
void chunkArrived(const QcChunk &chunk, quint32 sections)
const QcBlockEntities::ChunkIndex *chunkIndex(QcChunkPos pos) const
void chunkLeft(QcChunkPos pos)
QList<QcChunkPos> chunks() const
void clear()
QcBlockEntities::Container *container(QcBlockPos pos)
const QcBlockEntities::Container *container(QcBlockPos pos) const
qsizetype containerCount() const
int containerSlots(QcBlockId block) const
const QcContentRegistry &content() const
bool ensure(QcBlockPos pos, QcBlockId block)
QList<QcItemStack> fillPortable(QcBlockPos pos, const QcItemStack &stack)
void forEachMachine(Visit visit)
void forgetChunk(QcChunkPos chunk)
bool isContainerTableFull() const
bool isMachineTableFull() const
bool isPortable(QcBlockId block) const
bool isSapling(QcBlockId block) const
const QcBlockEntities::Limits &limits() const
QcBlockEntities::Machine *machine(QcBlockPos pos)
const QcBlockEntities::Machine *machine(QcBlockPos pos) const
qsizetype machineCount() const
const QcMachineDefinition *machineOf(QcBlockId block) const
const QcBlockEntities::Memory *memory(QcBlockPos pos) const
QcBlockEntities::Memory &memoryAt(QcBlockPos pos)
QString nameAt(QcBlockPos pos) const
void placed(QcBlockPos pos, QcBlockId before, QcBlockId after)
bool plantSapling(QcBlockPos pos, double remaining)
void prune(quint64 now, quint64 torchWindow, quint64 extensionTicks)
bool putContainer(const QcBlockEntities::Container &container)
bool putMachine(const QcBlockEntities::Machine &machine)
bool putSapling(QcBlockEntities::Sapling sapling)
void reconcile(const QcChunk &chunk)
void relocate(QcBlockPos from, QcBlockPos to)
void removeSapling(QcBlockPos pos)
const QcBlockEntities::Sapling *sapling(QcBlockPos pos) const
QcBlockEntities::Sapling *saplingByOrder(quint64 order)
qsizetype saplingCount() const
QList<quint64> saplingOrders() const
QList<QcBlockEntities::Sapling> saplingsInOrder() const
QcSignalSchedule &schedule()
const QcSignalSchedule &schedule() const
void setLimits(const QcBlockEntities::Limits &limits)
bool setName(QcBlockPos pos, const QString &name)
void setSaplingRemaining(QcBlockPos pos, double remaining)
QList<QcBlockEntities::Spill> takeSpills()
void tickSaplings(Visit visit)

Detailed Description

The kind of an entry comes from the block data: a block with container has a container, one with machine a machine, one with sapling may have a timer.

QcServerWorld keeps it in step with the blocks: a block set anywhere runs placed(), which drops what no longer fits the new block (contents spill, to be dropped as items by the caller) and creates the containers and machines of the new block; a chunk entering the world gets the containers and machines of its blocks; a chunk generated again forgets everything of the old one. Pistons move every entry of a cell with relocate().

Member Type Documentation

enum class QcBlockEntities::SaplingStep

What growSaplings-like ticks tell tickSaplings() about one sapling.

ConstantValueDescription
QcBlockEntities::SaplingStep::Keep0The timer goes on; the walk goes to the next sapling.
QcBlockEntities::SaplingStep::Remove1The timer ends.
QcBlockEntities::SaplingStep::Grew2The timer ends and the walk goes on after this sapling, because growing changed the world (and may have ended other timers).

Member Function Documentation

bool QcBlockEntities::carriesContents(QcBlockPos pos, QcBlockId block) const

Returns whether block is a portable container and the one at pos holds anything: broken, it then drops as its item carrying the contents instead of its usual drop.

std::optional<QcBlockEntities::Chunk> QcBlockEntities::chunk(QcChunkPos pos) const

Returns a copy of what the chunk at pos holds (tests and checks), or nothing when it holds nothing.

void QcBlockEntities::chunkArrived(const QcChunk &chunk, quint32 sections)

The chunk entered the world: reconcile() and the missing containers and machines of the blocks in its marked sections (bit n: section n).

const QcBlockEntities::ChunkIndex *QcBlockEntities::chunkIndex(QcChunkPos pos) const

Returns the positions of the entries of the chunk at pos (null for none; valid until the next change).

void QcBlockEntities::chunkLeft(QcChunkPos pos)

The chunk at pos left the world (QcServerWorld::unloadChunk): containers that hold nothing and rest and machines that are idle go; they come back with their blocks when the chunk arrives.

QList<QcChunkPos> QcBlockEntities::chunks() const

Returns the chunks with entries (scheduled ticks are kept by the schedule).

void QcBlockEntities::clear()

Forgets every entry and every scheduled tick.

QcBlockEntities::Container *QcBlockEntities::container(QcBlockPos pos)

Returns the container at pos, or null when there is none.

const QcBlockEntities::Container *QcBlockEntities::container(QcBlockPos pos) const

Returns the container at pos, or null when there is none.

qsizetype QcBlockEntities::containerCount() const

Returns the number of containers.

int QcBlockEntities::containerSlots(QcBlockId block) const

Returns the number of container slots the block data gives block (0: no container).

const QcContentRegistry &QcBlockEntities::content() const

Returns the content registry the block data comes from.

bool QcBlockEntities::ensure(QcBlockPos pos, QcBlockId block)

Creates the container or machine of block at pos unless there is one. Returns false when the block holds none or the limit of its kind is reached.

QList<QcItemStack> QcBlockEntities::fillPortable(QcBlockPos pos, const QcItemStack &stack)

The portable container just placed at pos takes the contents its item stack carries (decision E-832); returns what does not fit its slots or must not lie in it, to be dropped.

template <typename Visit> void QcBlockEntities::forEachMachine(Visit visit)

Calls visit with Machine & for every machine (QcMachineRules::tick).

void QcBlockEntities::forgetChunk(QcChunkPos chunk)

Forgets everything of chunk without spilling (it was generated again).

bool QcBlockEntities::isContainerTableFull() const

Returns whether the container table has reached its limit.

bool QcBlockEntities::isMachineTableFull() const

Returns whether the machine table has reached its limit.

bool QcBlockEntities::isPortable(QcBlockId block) const

Returns whether block is a portable container (a backpack, decision E-832).

bool QcBlockEntities::isSapling(QcBlockId block) const

Returns whether the block data marks block as a sapling.

const QcBlockEntities::Limits &QcBlockEntities::limits() const

Returns the limits of the tables.

See also setLimits().

QcBlockEntities::Machine *QcBlockEntities::machine(QcBlockPos pos)

Returns the machine at pos, or null when there is none.

const QcBlockEntities::Machine *QcBlockEntities::machine(QcBlockPos pos) const

Returns the machine at pos, or null when there is none.

qsizetype QcBlockEntities::machineCount() const

Returns the number of machines.

const QcMachineDefinition *QcBlockEntities::machineOf(QcBlockId block) const

Returns the machine the block data gives block, or null when it is none.

const QcBlockEntities::Memory *QcBlockEntities::memory(QcBlockPos pos) const

Returns the memory of the component at pos, or null when it has none.

QcBlockEntities::Memory &QcBlockEntities::memoryAt(QcBlockPos pos)

Returns the memory of the component at pos, created when it has none.

QString QcBlockEntities::nameAt(QcBlockPos pos) const

Returns the custom name of the container or machine at pos (decision E-873); empty for none or without one.

void QcBlockEntities::placed(QcBlockPos pos, QcBlockId before, QcBlockId after)

The block at pos changed from before to after (QcServerWorld::setBlock): spills the contents of a machine that is no machine any more and of a container that is none or smaller (a portable container that leaves spills as its item carrying the contents, decision E-832), creates the container or machine of the new block, ends a sapling's timer and forgets the memory that does not fit the new kind of component. Scheduled ticks stay: they look at whatever block is there when they run.

bool QcBlockEntities::plantSapling(QcBlockPos pos, double remaining)

Starts the timer of the sapling block just placed at pos with remaining seconds. Returns false (with a warning) when too many grow.

void QcBlockEntities::prune(quint64 now, quint64 torchWindow, quint64 extensionTicks)

Drops memories that ran out at tick now: torches that have not gone out within torchWindow ticks, ended burnouts and extensions that lasted extensionTicks; empty ones go. Ended hopper cooldowns are cleared.

bool QcBlockEntities::putContainer(const QcBlockEntities::Container &container)

Takes container with its contents for setting up and loading; replaces one at the same position. The limits refuse only placing: what a save holds always comes back. Returns false for a container without slots.

bool QcBlockEntities::putMachine(const QcBlockEntities::Machine &machine)

Takes machine with its contents for setting up and loading, like putContainer(). Returns true.

bool QcBlockEntities::putSapling(QcBlockEntities::Sapling sapling)

Takes sapling from a save with its order (also beyond the limit). Returns false when its position or order is taken.

void QcBlockEntities::reconcile(const QcChunk &chunk)

Fits what is kept for chunk to its blocks (a mod took a block away, a save from another version): as placed() would for each entry.

void QcBlockEntities::relocate(QcBlockPos from, QcBlockPos to)

Moves everything of the cell from to to (a piston pushed its block, decision E-337), entry by entry unless to has one of that kind already.

void QcBlockEntities::removeSapling(QcBlockPos pos)

Ends the timer of the sapling at pos.

const QcBlockEntities::Sapling *QcBlockEntities::sapling(QcBlockPos pos) const

Returns the timer of the sapling at pos, or null when there is none.

QcBlockEntities::Sapling *QcBlockEntities::saplingByOrder(quint64 order)

Returns the sapling with order (null once it is gone; valid until it is removed).

qsizetype QcBlockEntities::saplingCount() const

Returns the number of growing saplings.

QList<quint64> QcBlockEntities::saplingOrders() const

Returns the orders of all growing saplings, in planting order.

QList<QcBlockEntities::Sapling> QcBlockEntities::saplingsInOrder() const

Returns all growing saplings in the order they were planted.

QcSignalSchedule &QcBlockEntities::schedule()

Returns the scheduled ticks of circuit components, one per position.

const QcSignalSchedule &QcBlockEntities::schedule() const

Returns the scheduled ticks of circuit components, one per position.

void QcBlockEntities::setLimits(const QcBlockEntities::Limits &limits)

Sets the limits of the tables.

See also limits().

bool QcBlockEntities::setName(QcBlockPos pos, const QString &name)

Gives the container or machine at pos the custom name (a block placed from a named item). Returns false when there is none.

void QcBlockEntities::setSaplingRemaining(QcBlockPos pos, double remaining)

Sets the seconds remaining of the sapling at pos.

QList<QcBlockEntities::Spill> QcBlockEntities::takeSpills()

Returns the contents spilled since the last call, oldest first.

template <typename Visit> void QcBlockEntities::tickSaplings(Visit visit)

Calls visit with Sapling & for every sapling in planting order and acts on the SaplingStep it returns.