QtCraft API C++ classes QML types Handbook

QcPlantManager Class

Living plants on the server: leaves of trees decay when no trunk is near any more, and planted saplings grow into the tree feature they name. More...

Header: #include <server/plants/QcPlantManager.h>

Public Types

struct Actions
BreakBlock
LoadedFunction
SetBlock

Public Functions

void blockRemoved(QcBlockPos pos, QcBlockId previous, const QcBlockAccess &world)
bool canPlant(QcBlockId sapling, std::optional<QcBlockId> ground) const
bool isLeaves(QcBlockId block) const
bool isTrunk(QcBlockId block) const
qsizetype pendingCheckCount() const
void saplingPlaced(QcBlockEntities &entities, QcBlockPos pos, QcBlockId sapling)
void setLeafLimits(qint64 decays, qint64 checks, qint64 pending)
void tick(const QcBlockAccess &world, QcBlockEntities &entities, double dt, const QcPlantManager::Actions &actions)

Static Public Members

const int leafReach
const int maxChecksPerTick
const double maxDecayDelay
const int maxDecaysPerTick
const int maxPendingChecks
const double minDecayDelay
const double recheckSeconds
const double retrySeconds

Detailed Description

Trunks and leaves are the blocks that the tree features of the content use.

Leaves are only checked after a trunk block nearby was removed, a few at a time and with a short random delay, so felling a tree makes its crown fall apart gradually. Saplings grow only while their chunk is loaded; their timers are block entities (QcBlockEntities::Sapling).

Member Type Documentation

[alias] QcPlantManager::BreakBlock

Removes a block as if it broke by itself, dropping its items.

[alias] QcPlantManager::LoadedFunction

Whether the chunk of a position is loaded.

[alias] QcPlantManager::SetBlock

Sets a block and tells the clients; returns false when it could not be set.

Member Function Documentation

void QcPlantManager::blockRemoved(QcBlockPos pos, QcBlockId previous, const QcBlockAccess &world)

Tells the manager that the block previous at pos of world was removed.

bool QcPlantManager::canPlant(QcBlockId sapling, std::optional<QcBlockId> ground) const

Returns whether sapling may stand on ground; false for blocks that are not saplings.

bool QcPlantManager::isLeaves(QcBlockId block) const

Returns whether block is leaves.

bool QcPlantManager::isTrunk(QcBlockId block) const

Returns whether block is a trunk block that holds leaves.

qsizetype QcPlantManager::pendingCheckCount() const

Returns the number of leaf checks waiting.

void QcPlantManager::saplingPlaced(QcBlockEntities &entities, QcBlockPos pos, QcBlockId sapling)

Starts the growth timer of the sapling block just placed at pos (a random time of its definition) in entities.

void QcPlantManager::setLeafLimits(qint64 decays, qint64 checks, qint64 pending)

Sets the leaf limits: decays and checks per tick and pending checks waiting.

void QcPlantManager::tick(const QcBlockAccess &world, QcBlockEntities &entities, double dt, const QcPlantManager::Actions &actions)

Decays leaves and grows the saplings of entities in the order they were planted, by dt seconds in world, with actions.

Member Variable Documentation

const int QcPlantManager::leafReach

Leaves stay as long as a trunk block lies within this many blocks along every axis.

const int QcPlantManager::maxPendingChecks

Leaf checks waiting at most by default (QcServerLimits::leafPendingChecks).

const double QcPlantManager::recheckSeconds

Leaves next to unloaded chunks are checked again after this many seconds.

const double QcPlantManager::retrySeconds

A sapling without room to grow tries again after this many seconds.