QcLiquidFlow Class
Flowing liquids on the server (decision E-054). More...
| Header: | #include <server/blocks/QcLiquidFlow.h> |
Public Types
| struct | TickResult |
| SetFunction |
Public Functions
| void | clear() |
| quint64 | droppedCount() const |
| void | forgetChunk(QcChunkPos chunk) |
| bool | hasDueSteps(quint64 now) const |
| qsizetype | plannedCount() const |
| QList<QcBlockPos> | plannedPositions() const |
| bool | schedule(const QcBlockAccess &world, QcBlockPos pos, quint64 now) |
| void | setMaxPlanned(qsizetype limit) |
| QHash<QcChunkPos, QList<QcBlockPos>> | takeChunks(const QSet<QcChunkPos> &chunks) |
| QcLiquidFlow::TickResult | tick(quint64 now, const QcBlockAccess &world, const QcLiquidFlow::SetFunction &set, int budget = maxStepsPerTick) |
Static Public Members
| bool | canFlowInto(const QcBlockAccess &world, QcBlockPos pos, QcBlockId state) |
| bool | canReplace(const QcContentRegistry &content, std::optional<QcBlockId> block, QcBlockId state) |
| QcVec3 | current(const QcBlockAccess &world, QcBlockPos pos) |
| std::optional<QcBlockId> | fedState(const QcBlockAccess &world, QcBlockPos pos, QcBlockId id) |
| bool | flows(const QcContentRegistry &content, QcBlockId id) |
| bool | isFalling(const QcContentRegistry &content, QcBlockId id) |
| bool | isSource(const QcContentRegistry &content, QcBlockId id) |
| int | level(const QcContentRegistry &content, QcBlockId id) |
| const qsizetype | maxPlanned |
| const int | maxStepsPerTick |
| std::optional<QcBlockId> | reaction(const QcBlockAccess &world, QcBlockPos pos, QcBlockId id) |
| QList<QcBlockFace> | spreadFaces(const QcBlockAccess &world, QcBlockPos pos, QcBlockId spread) |
| QcBlockId | stateWith(const QcContentRegistry &content, QcBlockId id, int level, bool falling) |
Detailed Description
A liquid block with a flow definition takes a flow step ticks server ticks after something next to it changed: a flowing part (level > 0) takes the level of its best feeder plus one, falls back to nothing without one, and becomes a source between two sources over solid ground when the liquid is infinite; then the liquid falls into the cell below if it can and otherwise (and always for sources) spreads sideways one level further, up to its distance, preferring the sides that lead to the nearest drop. Liquids touching another liquid they react with turn into the reaction's block. Steps are planned per position (each at most once) and worked off in order of their due tick, at most a budget per tick; everything a step changes plans its neighbours.
Member Type Documentation
[alias] QcLiquidFlow::SetFunction
Replaces the block at a position (the caller breaks washable blocks first and tells clients).
Member Function Documentation
[static] bool QcLiquidFlow::canFlowInto(const QcBlockAccess &world, QcBlockPos pos, QcBlockId state)
Returns whether the liquid may flow into pos of world as state (air, replaceable or washable blocks, or a weaker part of the same liquid).
[static] bool QcLiquidFlow::canReplace(const QcContentRegistry &content, std::optional<QcBlockId> block, QcBlockId state)
Returns whether the liquid may flow as state into a cell holding block inside the world height, by the blocks of content (std::nullopt: not loaded; the caller checks the world height, as canFlowInto() does).
void QcLiquidFlow::clear()
Drops every planned step.
[static] QcVec3 QcLiquidFlow::current(const QcBlockAccess &world, QcBlockPos pos)
Returns the horizontal direction (unit length, or zero) the liquid at pos of world pushes floating things: down the slope of its surface towards shallower parts of the same liquid and open cells, like the reference game (decision E-296). Zero for still liquid and cells that hold no liquid.
quint64 QcLiquidFlow::droppedCount() const
Returns the plans dropped because the plan was full.
[static] std::optional<QcBlockId> QcLiquidFlow::fedState(const QcBlockAccess &world, QcBlockPos pos, QcBlockId id)
Returns the state the flowing (non-source) liquid id at pos of world takes from its feeders, air without any; std::nullopt while a neighbour that decides it is not loaded.
[static] bool QcLiquidFlow::flows(const QcContentRegistry &content, QcBlockId id)
Returns whether the block id of content is a liquid that flows (rules, shared with tests).
void QcLiquidFlow::forgetChunk(QcChunkPos chunk)
Drops the planned steps inside chunk (it was generated again).
bool QcLiquidFlow::hasDueSteps(quint64 now) const
Returns whether a planned step is due at now.
[static] bool QcLiquidFlow::isFalling(const QcContentRegistry &content, QcBlockId id)
Returns whether the liquid id of content is falling.
[static] bool QcLiquidFlow::isSource(const QcContentRegistry &content, QcBlockId id)
Returns whether the liquid id of content is a source.
[static] int QcLiquidFlow::level(const QcContentRegistry &content, QcBlockId id)
Returns the level property of the liquid id of content (0 for a source).
qsizetype QcLiquidFlow::plannedCount() const
Returns the number of planned steps.
QList<QcBlockPos> QcLiquidFlow::plannedPositions() const
Returns the positions with a planned step.
[static] std::optional<QcBlockId> QcLiquidFlow::reaction(const QcBlockAccess &world, QcBlockPos pos, QcBlockId id)
Returns what the liquid id at pos of world turns into because it touches a liquid it reacts with.
bool QcLiquidFlow::schedule(const QcBlockAccess &world, QcBlockPos pos, quint64 now)
Plans a step for the liquid at pos of world after its flow ticks, counted from now. Returns false for blocks that do not flow, positions already planned and when the plan is full.
void QcLiquidFlow::setMaxPlanned(qsizetype limit)
Sets the planned steps at most to limit.
[static] QList<QcBlockFace> QcLiquidFlow::spreadFaces(const QcBlockAccess &world, QcBlockPos pos, QcBlockId spread)
Returns the sides the liquid at pos of world spreads to as spread: of the sides it can flow into, those whose way leads to the nearest drop within the liquid's dropSearch blocks and the reach left to spread (decision E-103), or all of them when no drop is that near.
[static] QcBlockId QcLiquidFlow::stateWith(const QcContentRegistry &content, QcBlockId id, int level, bool falling)
Returns the state of the liquid of id in content with level and the flag falling.
QHash<QcChunkPos, QList<QcBlockPos>> QcLiquidFlow::takeChunks(const QSet<QcChunkPos> &chunks)
Returns the planned steps inside chunks by chunk and takes them out (they leave the world, decision E-374); they come back as block updates, which plan them again.
QcLiquidFlow::TickResult QcLiquidFlow::tick(quint64 now, const QcBlockAccess &world, const QcLiquidFlow::SetFunction &set, int budget = maxStepsPerTick)
Runs the steps due at now in world, at most budget, setting blocks with set. Returns what they did.
Member Variable Documentation
const qsizetype QcLiquidFlow::maxPlanned
Planned steps at most by default (QcServerLimits::liquidPlannedSteps); further plans are dropped (the cell flows again when touched).
const int QcLiquidFlow::maxStepsPerTick
Flow steps per server tick at most by default (QcServerLimits::liquidStepsPerTick); the rest waits for the next tick.