QcHandActions Class
What the local player's hand does: the block and the entity under the crosshair, mining the targeted block (survival progress and hit sounds, instant breaking in creative mode), using the held item on a block, an entity or itself, drawing and releasing a launcher (QcClientLauncher) and attacking. More...
| Header: | #include <clientcore/player/QcHandActions.h> |
Public Types
| struct | View |
| Cue | |
| enum class | HandEffect { None, Handled, Swing, Use, UsedBlock, …, Refused } |
| Predictor | |
| Sender |
Public Functions
| QcHandActions(const QcHandActions::View &view, QcClientGameMode &gameMode, QcHandActions::Sender send, QcHandActions::Cue cue, QcHandActions::Predictor predict) | |
| QcHandActions::HandEffect | attack() |
| void | clearTarget() |
| double | drawProgress(double alpha) const |
| void | dropDraw() |
| void | endUse(QcMsg::DrawLauncher::Action action, bool send) |
| void | holdUse() |
| bool | isMining() const |
| double | miningProgress() const |
| bool | miningRequested() const |
| void | refreshTarget(const QcClientWorld &world, const QcContentRegistry &content) |
| void | setMining(bool mining) |
| QcHandActions::HandEffect | strike(const QcClientWorld &world, const QcContentRegistry &content) |
| const std::optional<QcRaycastHit> & | target() const |
| std::optional<quint32> | targetEntity() const |
| void | tickLauncher(const QcContentRegistry &content, double serverTicks) |
| QcHandActions::HandEffect | tickUse(const QcClientWorld &world, const QcContentRegistry &content) |
| QcHandActions::HandEffect | updateMining(const QcClientWorld &world, const QcContentRegistry &content) |
| QcHandActions::HandEffect | use(const QcClientWorld &world, const QcContentRegistry &content) |
| bool | useHeld() const |
Static Public Members
| const double | attackReach |
| const int | miningHitTicks |
| const int | useRepeatTicks |
Detailed Description
Sends its requests through the sender; the server decides and answers. The blocks a break or a placement is expected to set (QcBlockForecast) go to the predictor first, which shows them at once and numbers the request (decision E-853). What an action means for the arm and the screens it returns as a HandEffect, which the session applies.
Member Type Documentation
[alias] QcHandActions::Cue
Plays a sound.
enum class QcHandActions::HandEffect
What an action did beyond its requests, for the session to apply after them.
| Constant | Value | Description |
|---|---|---|
QcHandActions::HandEffect::None | 0 | Nothing was done. |
QcHandActions::HandEffect::Handled | 1 | Done without a visible effect (a launcher draws). |
QcHandActions::HandEffect::Swing | 2 | The arm swings (a strike, a throw, a block broken at once). |
QcHandActions::HandEffect::Use | 3 | The arm makes the use motion. |
QcHandActions::HandEffect::UsedBlock | 4 | Use motion; the player used a block, so a machine screen it opens shows again. |
QcHandActions::HandEffect::UsedEntity | 5 | Use motion; the player used an entity, so a machine or trading screen it opens shows again. |
QcHandActions::HandEffect::Refused | 6 | Nothing was done because the mode forbids it (adventure allow-lists, decision E-735); the HUD says so. |
[alias] QcHandActions::Predictor
Shows the blocks an action is expected to set and returns the number the request carries (QcMsg::FinishMining::sequence, QcMsg::UseItem::sequence); 0 when nothing is predicted.
[alias] QcHandActions::Sender
Sends a request to the server.
Member Function Documentation
QcHandActions::QcHandActions(const QcHandActions::View &view, QcClientGameMode &gameMode, QcHandActions::Sender send, QcHandActions::Cue cue, QcHandActions::Predictor predict)
view: what the hand reads of the player and the world; gameMode: the rules and the instant breaking of creative mode; send: how requests reach the server; cue: where the mining sounds go; predict: where predicted blocks go (all the session's, never empty).
QcHandActions::HandEffect QcHandActions::attack()
Hits the targeted entity. Returns Swing, or None without one.
void QcHandActions::clearTarget()
Forgets the targeted block.
double QcHandActions::drawProgress(double alpha) const
Returns the progress of the drawn launcher alpha into the tick, negative when none is drawn.
void QcHandActions::dropDraw()
A draw ends without the player's word: the server refused it or the player died. The button may stay held; only a new press draws again.
void QcHandActions::endUse(QcMsg::DrawLauncher::Action action, bool send)
The use button released or cancelled (action): the repeats stop and a drawn launcher shoots or lets go (decision E-425); the server hears of it only while send (the session plays).
void QcHandActions::holdUse()
The use button was pressed (after its first use()): from now on tickUse repeats the use until endUse (decision E-885).
bool QcHandActions::isMining() const
Returns whether a block is being mined (survival) right now.
double QcHandActions::miningProgress() const
Returns the progress of the mining, 0 to 1.
bool QcHandActions::miningRequested() const
Returns whether mining is requested (setMining()).
void QcHandActions::refreshTarget(const QcClientWorld &world, const QcContentRegistry &content)
Aims again in world (blocks of content) from the predicted eye along the intent; clearTarget() while there is no world.
void QcHandActions::setMining(bool mining)
While mining, the targeted block is mined; progress runs from 0 to 1 and resets on target change. Releasing ends the pace of held instant breaking, so the next press breaks at once.
See also isMining().
QcHandActions::HandEffect QcHandActions::strike(const QcClientWorld &world, const QcContentRegistry &content)
The mining button was just pressed: in creative mode the aimed block of world (blocks of content) breaks now instead of at the next tick, at the pace of updateMining (decision E-853). Returns Swing when it broke.
const std::optional<QcRaycastHit> &QcHandActions::target() const
Returns the block the player looks at (within reach); nothing without one.
std::optional<quint32> QcHandActions::targetEntity() const
Returns the entity under the crosshair when it is closer than the targeted block; nothing without one.
void QcHandActions::tickLauncher(const QcContentRegistry &content, double serverTicks)
Once per tick: the launcher's draw (items of content) and the cooldowns of throwing (serverTicks per tick). A draw whose launcher left the hand is cancelled, also towards the core, which slows the player while a draw runs (decision E-986).
QcHandActions::HandEffect QcHandActions::tickUse(const QcClientWorld &world, const QcContentRegistry &content)
Once per tick after the aim, in world with content: while the use button is held and no mining is wanted, uses the held item again every useRepeatTicks ticks, but only where a repeat is wanted (repeatsUse). Returns the effect of the use; None otherwise.
QcHandActions::HandEffect QcHandActions::updateMining(const QcClientWorld &world, const QcContentRegistry &content)
Once per tick after the prediction: aims again and advances or changes the mining in world with content. Returns Swing when a block broke at once (creative mode), Refused while the mode forbids mining the aimed block (adventure mode: no mining at all, no cracks or sounds).
QcHandActions::HandEffect QcHandActions::use(const QcClientWorld &world, const QcContentRegistry &content)
Uses the held item on the targeted entity, the block face or itself, in world with content. Returns None when nothing was used, Refused when the mode forbids the item to act on the block (food is eaten instead).
bool QcHandActions::useHeld() const
Returns whether the use button is held (holdUse()).
Member Variable Documentation
const double QcHandActions::attackReach
Melee reach of the player.
const int QcHandActions::miningHitTicks
Mining strikes make a sound every this many ticks.
const int QcHandActions::useRepeatTicks
While the use button is held, the use repeats every this many ticks (decision E-885).