Faucet Mod SDK 1.0.0
Modding API for Minecraft Legacy Console Edition
Loading...
Searching...
No Matches
Player Class Reference

Base class for all player types (Local, Server, Remote). More...

#include <SDK.h>

Inheritance diagram for Player:

Public Member Functions

float getHealth () const
 Get the player's current health.
void setHealth (float health)
 Set the player's health directly.
float getMaxHealth () const
 Get the player's maximum health.
bool hurt (DamageSource *source, float amount)
 Apply damage from a damage source.
void heal (float amount)
 Heal the player by a given amount.
int getFoodLevel () const
 Get the player's current food level.
int getExperienceLevel () const
 Get the player's experience level.
void giveExperienceLevels (int amount)
 Give experience levels to the player.
wstring getName () const
 Get the player's username.
bool isSneaking () const
 Check if the player is currently sneaking.
bool isSprinting () const
 Check if the player is currently sprinting.
bool isFlying () const
 Check if the player is flying.
void setFlying (bool flying)
 Set the player's flying state.
double getX () const
 Get the player's current X position.
double getY () const
 Get the player's current Y position (feet level).
double getZ () const
 Get the player's current Z position.
void teleportTo (double x, double y, double z)
 Teleport the player to a world position.
virtual shared_ptr< ItemInstance > getCarriedItem ()
 Get the item currently held in the player's hand.
class Inventory * getInventory ()
 Add an item to the player's inventory.
virtual void respawn ()
 Trigger the player's respawn.
void kill ()
 Kill the player immediately. Triggers death screen.
virtual void playSound (int soundId, float volume, float pitch)
 Play a sound effect at the player's position.
bool hasPermission (class EGameCommand command)
 Check whether this player has a given game permission.

Public Attributes

double x
 X coordinate (double precision).
double y
 Y coordinate (feet position).
double z
 Z coordinate.
float yRot
 Yaw rotation in degrees.
float xRot
 Pitch rotation in degrees.

Detailed Description

Base class for all player types (Local, Server, Remote).

Don't use this directly — use MultiplayerLocalPlayer (client) or ServerPlayer (server) for concrete player references.

Definition at line 475 of file SDK.h.

Member Function Documentation

◆ getCarriedItem()

virtual shared_ptr< ItemInstance > Player::getCarriedItem ( )
virtual

Get the item currently held in the player's hand.

Returns
ItemInstance pointer, or nullptr if hand is empty.

Reimplemented in LocalPlayer.

◆ getExperienceLevel()

int Player::getExperienceLevel ( ) const

Get the player's experience level.

Returns
XP level.

◆ getFoodLevel()

int Player::getFoodLevel ( ) const

Get the player's current food level.

Returns
Food level (0–20).

◆ getHealth()

float Player::getHealth ( ) const

Get the player's current health.

Returns
Health points (0.0 = dead, 20.0 = full with no buffs).

◆ getInventory()

class Inventory * Player::getInventory ( )

Add an item to the player's inventory.

Example
// Give the player a diamond sword (item ID 276)
auto sword = std::make_shared<ItemInstance>(276, 1, 0);
player->getInventory()->add(sword);

◆ getMaxHealth()

float Player::getMaxHealth ( ) const

Get the player's maximum health.

Returns
Max health (default 20.0, affected by Absorption etc.).

◆ getName()

wstring Player::getName ( ) const

Get the player's username.

Returns
Wide string username.

◆ giveExperienceLevels()

void Player::giveExperienceLevels ( int amount)

Give experience levels to the player.

Parameters
amountNumber of levels to add (can be negative).

◆ hasPermission()

bool Player::hasPermission ( class EGameCommand command)

Check whether this player has a given game permission.

Parameters
commandThe permission/command to check.
Returns
true if allowed.

◆ heal()

void Player::heal ( float amount)

Heal the player by a given amount.

Parameters
amountHalf-hearts to restore.

◆ hurt()

bool Player::hurt ( DamageSource * source,
float amount )

Apply damage from a damage source.

Respects armor, effects, and god-mode. Prefer this over setHealth() when simulating real damage, as it triggers death/hurt animations.

Parameters
sourceDamage source (can be nullptr for generic damage).
amountDamage in half-hearts.
Returns
true if the damage was applied.

◆ isFlying()

bool Player::isFlying ( ) const

Check if the player is flying.

Returns
true if flying.

◆ isSneaking()

bool Player::isSneaking ( ) const

Check if the player is currently sneaking.

Returns
true if sneaking.

◆ isSprinting()

bool Player::isSprinting ( ) const

Check if the player is currently sprinting.

Returns
true if sprinting.

◆ playSound()

virtual void Player::playSound ( int soundId,
float volume,
float pitch )
virtual

Play a sound effect at the player's position.

Parameters
soundIdSound ID.
volumeVolume multiplier (1.0 = normal).
pitchPitch multiplier (1.0 = normal).

Reimplemented in LocalPlayer.

◆ setFlying()

void Player::setFlying ( bool flying)

Set the player's flying state.

Parameters
flyingTrue to enable flight.

◆ setHealth()

void Player::setHealth ( float health)

Set the player's health directly.

Does not trigger death events if set to 0 — use hurt() for that. Clamped to [0, getMaxHealth()] internally.

Parameters
healthNew health value.
Example
player->setHealth(20.0f); // Full heal
player->setHealth(1.0f); // Half a heart

◆ teleportTo()

void Player::teleportTo ( double x,
double y,
double z )

Teleport the player to a world position.

Parameters
x,y,zTarget coordinates.

The documentation for this class was generated from the following file: