QcFallingBlockManager Class
Blocks that fall (sand, gravel) while nothing holds them (decision E-055). More...
| Header: | #include <server/blocks/QcFallingBlockManager.h> |
Public Types
| struct | Landing |
Public Functions
| qsizetype | adopt(const QList<QcFallingBlock> &falling, const std::function<quint32 ()> &nextEntityId) |
| const QList<QcFallingBlock> & | all() const |
| QList<QcFallingBlock> & | editableAll() |
| bool | isFull() const |
| qsizetype | removeInChunk(QcChunkPos chunk) |
| void | restore(const QList<QcFallingBlock> &falling, const std::function<quint32 ()> &nextEntityId) |
| void | setMaxFalling(qsizetype limit) |
| void | start(QcBlockPos from, QcBlockId block, quint32 id) |
| QList<QcFallingBlockManager::Landing> | tick(const QcBlockAccess &world, double dt) |
Static Public Members
| bool | isPassable(const QcBlockAccess &world, QcBlockPos pos) |
| const int | maxDirectDrop |
| const int | maxFalling |
| const double | maxSeconds |
| std::optional<QcBlockPos> | restingCell(const QcBlockAccess &world, QcBlockPos from) |
| bool | shouldFall(const QcBlockAccess &world, QcBlockPos pos) |
| const double | size |
Detailed Description
A falling block is an entity with the shared physics; where it comes to rest it becomes its block again if the cell is free (air, liquid, replaceable), otherwise it drops as items. Only blocks in loaded chunks move. Their number is bounded; beyond it a block drops straight to where it would land.
Member Function Documentation
qsizetype QcFallingBlockManager::adopt(const QList<QcFallingBlock> &falling, const std::function<quint32 ()> &nextEntityId)
Adds falling with ids from nextEntityId, like restore() without clearing first (a chunk came back, decision E-374). Returns how many were left out at the limit.
const QList<QcFallingBlock> &QcFallingBlockManager::all() const
Returns every falling block.
QList<QcFallingBlock> &QcFallingBlockManager::editableAll()
Returns the falling blocks for moving them from outside (pistons push them); never add or remove through it.
bool QcFallingBlockManager::isFull() const
Returns whether no more blocks may fall at once.
[static] bool QcFallingBlockManager::isPassable(const QcBlockAccess &world, QcBlockPos pos)
Returns whether a falling block may move into the cell pos of world (air, liquid, replaceable blocks).
qsizetype QcFallingBlockManager::removeInChunk(QcChunkPos chunk)
Removes the blocks falling inside chunk. Returns how many.
[static] std::optional<QcBlockPos> QcFallingBlockManager::restingCell(const QcBlockAccess &world, QcBlockPos from)
Returns the cell of world a block let go at from comes to rest in, scanning down; std::nullopt below the world or in unloaded chunks.
void QcFallingBlockManager::restore(const QList<QcFallingBlock> &falling, const std::function<quint32 ()> &nextEntityId)
Replaces all falling blocks with falling (from a save); ids come from nextEntityId.
void QcFallingBlockManager::setMaxFalling(qsizetype limit)
Sets the falling blocks at once at most to limit.
[static] bool QcFallingBlockManager::shouldFall(const QcBlockAccess &world, QcBlockPos pos)
Returns whether the block at pos of world would start falling now (it falls and the cell below is passable; below the lowest layer is the void, decision E-288).
void QcFallingBlockManager::start(QcBlockPos from, QcBlockId block, quint32 id)
Starts block falling as entity id in the cell from (the caller removes the block there).
QList<QcFallingBlockManager::Landing> QcFallingBlockManager::tick(const QcBlockAccess &world, double dt)
Runs one tick of dt seconds of physics in world for the blocks that do not rest (QcEntities::settle). Returns the blocks that came to rest. Blocks that fall below QcWorld::voidLimitY disappear, resting ones too (decision E-288).
Member Variable Documentation
const int QcFallingBlockManager::maxDirectDrop
Scan depth for blocks that land without becoming entities.
const int QcFallingBlockManager::maxFalling
Falling blocks at once by default (QcServerLimits::fallingBlocks).
const double QcFallingBlockManager::maxSeconds
A block still falling after this long (stuck on something) drops as items.
const double QcFallingBlockManager::size
Edge length of the falling cube, a little less than a block so it slides into one-wide shafts.