QtCraft API C++ classes QML types Handbook

QcPlayerHealth Class

Health and food of the players (decision E-367): regeneration and starvation, damage (with armour, knockback and the short invulnerability after a hit), falls, the void, death with its drops and message, respawning, eating, and telling the player. More...

Header: #include <server/gameplay/QcPlayerHealth.h>

Public Types

enum class DamageKind { Unblockable, Armoured, Command, Void, Effect, …, Drowning }

Public Functions

void afterMove(QcServerClient &client, bool wasOnGround, bool wasInWater, double previousY)
void consume(QcServerClient &client)
QcHurtWindow::Take damage(QcServerClient &client, double amount, const QcVec3 &knockback, QcPlayerHealth::DamageKind kind = DamageKind::Unblockable, quint32 creature = 0)
void drink(QcServerClient &client, const QcItemDefinition &held)
void respawn(QcServerClient &client)
void sendFood(QcServerClient &client)
void sendHealth(QcServerClient &client, bool hurt = false, std::optional<float> hurtFrom = {})
void tick()

Static Public Members

const double fallDamageThreshold
void knock(QcServerClient &client, const QcVec3 &direction, double strength = 1.0)
const double voidDamage
const int voidDamageIntervalTicks

Detailed Description

Member Type Documentation

enum class QcPlayerHealth::DamageKind

Whether armour takes part of the damage and wears down (decision E-234): blows of creatures and contact with damaging blocks are armoured; falls are not.

Command damage (/kill) also reaches invulnerable players (creative mode, decision E-282); so does the void, which in addition ignores the short invulnerability after a hit and has its own death message (decision E-288). Damage of a status effect is unblockable with a death message of its own (decision E-450). A creature's blow and a creature's shot are armoured; a player they kill hears who it was (decision E-873, the creature passed with the damage). Drowning is unblockable with a death message of its own (decision E-955).

ConstantValueDescription
QcPlayerHealth::DamageKind::Unblockable0Armour takes nothing (falls).
QcPlayerHealth::DamageKind::Armoured1Armour takes its part (contact with damaging blocks).
QcPlayerHealth::DamageKind::Command2A command (/kill); also reaches invulnerable players.
QcPlayerHealth::DamageKind::Void3The void; also reaches invulnerable players, with its own death message.
QcPlayerHealth::DamageKind::Effect4A status effect; unblockable, with its own death message.
QcPlayerHealth::DamageKind::Blow5A creature's blow; armoured.
QcPlayerHealth::DamageKind::Shot6A creature's shot; armoured.
QcPlayerHealth::DamageKind::Drowning7Drowning; unblockable, with its own death message.

Member Function Documentation

void QcPlayerHealth::afterMove(QcServerClient &client, bool wasOnGround, bool wasInWater, double previousY)

Applies the fall damage of client after a movement step that started at height previousY, wasOnGround and wasInWater telling where it stood before.

void QcPlayerHealth::consume(QcServerClient &client)

Eats the food client holds or puts on the held armour.

QcHurtWindow::Take QcPlayerHealth::damage(QcServerClient &client, double amount, const QcVec3 &knockback, QcPlayerHealth::DamageKind kind = DamageKind::Unblockable, quint32 creature = 0)

Hurts the player client by amount of kind, pushed by knockback, and returns how the hit took: during the invulnerability after a hurt (game rule playerInvulnerabilityTicks) only a stronger hit takes, with the difference, silent and without the push (QcHurtWindow, decision E-429). creature is the entity id of the creature that deals a Blow or a Shot (0: none, a dispenser's or a player's arrow); a death by this very hit names it (decision E-873).

void QcPlayerHealth::drink(QcServerClient &client, const QcItemDefinition &held)

Drinks the drink held by client (milk clears the status effects, decision E-500) and leaves its container.

[static] void QcPlayerHealth::knock(QcServerClient &client, const QcVec3 &direction, double strength = 1.0)

Pushes the player client along direction with strength times a blow's push (a projectile's knockback, decision E-427, also without damage).

void QcPlayerHealth::respawn(QcServerClient &client)

Brings the dead player client back at the spawn.

void QcPlayerHealth::sendFood(QcServerClient &client)

Sends client its food points.

void QcPlayerHealth::sendHealth(QcServerClient &client, bool hurt = false, std::optional<float> hurtFrom = {})

Sends client its health; with hurt as a fresh hit from the world yaw hurtFrom (none: without a direction), so the client tilts the view (decision E-971).

void QcPlayerHealth::tick()

Timers, hunger and the void for every playing player in a simulated tick.

Member Variable Documentation

const double QcPlayerHealth::fallDamageThreshold

A fall higher than this many blocks hurts, one point per block beyond.