Skip to main content

Overview

The Player API provides functionality for player entities in Minecraft Community Edition, including movement, inventory management, abilities, experience, food, and multiplayer synchronization.

Class Hierarchy

Player Class

Represents a player entity in the game. Header: Minecraft.World/Player.h
Inherits: Mob, CommandSender

Constants

Core Members

Constructor

constructor
Creates a new player in the specified world.Parameters:
  • level - World to spawn player in

Inventory & Items

shared_ptr<ItemInstance>
Gets the currently selected/held item.Returns: Item in selected hotbar slot, or null
void
Removes one of the selected item from inventory.
shared_ptr<ItemInstance>
Gets armor piece at slot.Parameters:
  • pos - Armor slot (0=helmet, 1=chest, 2=legs, 3=boots)
int
Gets total armor defense points.Returns: Defense value (0-20)
float
Gets armor coverage as percentage.Returns: Coverage (0.0-1.0)
Slot*
Gets inventory slot by ID.Parameters:
  • slotId - Slot index

Item Usage

shared_ptr<ItemInstance>
Gets item currently being used (eating, blocking, etc.).
int
Gets ticks remaining for item use.
bool
Checks if player is using an item.
int
Gets ticks item has been in use.
void
Begins using an item.Parameters:
  • instance - Item to use
  • duration - Max use duration in ticks
void
Cancels item usage.
void
Completes item usage (bow release, finish eating).
bool
Checks if player is blocking with shield/sword.

Movement & Abilities

void
Handles player movement input.Parameters:
  • xa - Strafe input (-1 to 1)
  • ya - Forward input (-1 to 1)
Abilities
Player abilities structure:
void
Called when abilities are updated.Note: Override to sync abilities in multiplayer

Combat

void
Plays arm swing animation.
void
Attacks an entity.Parameters:
  • entity - Target to attack
void
Plays critical hit effects.
void
Plays magic critical hit effects (enchanted weapon).
float
Gets block breaking speed multiplier.Returns: Speed based on tool, enchantments, effects
bool
Checks if player can break this block type.

Health & Damage

int
Gets maximum health.Returns: 20 (10 hearts) by default
bool
Applies damage to player.Parameters:
  • source - Damage source
  • dmg - Damage amount
Returns: true if damage was applied
void
Handles player death.Parameters:
  • source - Cause of death
void
Respawns player at spawn point.
bool
Checks if player is hurt (health < max).

Food & Exhaustion

FoodData*
Gets food/hunger data.Returns: Pointer to FoodData structure
bool
Checks if player can eat.Parameters:
  • magicalItem - Can eat even when full? (golden apple)
void
Adds exhaustion (decreases food over time).Parameters:
  • amount - Exhaustion amount
Examples: 0.025 per meter walked, 0.1 per meter sprinted

Experience

void
Adds experience points.Parameters:
  • i - XP amount to add
void
Removes experience levels.Parameters:
  • amount - Levels to remove
Use case: Enchanting, anvil repairs
int
Gets XP needed to reach next level.Returns: XP requirement for current level

Sleeping

BedSleepingResult
Attempts to sleep in a bed.Parameters:
  • x, y, z - Bed position
  • testUse - Only test, don’t actually sleep
Returns: Result enum (OK, NOT_POSSIBLE_NOW, TOO_FAR_AWAY, etc.)
void
Wakes player from bed.Parameters:
  • forcefulWakeUp - Skip wake animation
  • updateLevelList - Update world’s sleeping player list
  • saveRespawnPoint - Set spawn to this bed
bool
Checks if player is sleeping.
bool
Checks if player has slept long enough to skip night.
int
Gets sleep animation timer.
Pos*
Gets bed respawn position.
void
Sets respawn point.

Containers & Interaction

bool
Opens a container inventory.Returns: true if opened successfully
bool
Opens furnace UI.
bool
Opens dispenser/dropper UI.
bool
Opens brewing stand UI.
bool
Opens trading UI with villager.
bool
Opens enchantment table UI.
bool
Opens crafting table UI.
void
Closes current container.

Dropping Items

shared_ptr<ItemEntity>
Drops selected item stack.
shared_ptr<ItemEntity>
Drops specific item.
shared_ptr<ItemEntity>
Drops item with optional randomized position.

Statistics

void
Awards a statistic/achievement.Parameters:
  • stat - Statistic to increment
  • param - Additional data
int
Gets player score.Returns: Score value (used as death counter)

Identity & Customization

wstring
Gets player username.
wstring
Gets display name (console gamertag/PSN ID).
PlayerUID
Gets Xbox User ID (XUID).
void
Sets XUID.
wstring
Gets unique player UUID.
void
Sets custom player skin.
DWORD
Gets current custom skin ID.
void
Sets custom cape.

Permissions & Privileges

bool
Checks if player can break blocks.
bool
Checks if PvP is allowed for this player.
bool
Checks if flight is allowed.
bool
Checks if player has operator privileges.
void
Sets a privilege flag.

Dimension Travel

void
Teleports player to another dimension.Parameters:
  • i - Dimension ID (0=Overworld, -1=Nether, 1=End)
void
Handles portal travel timer.
bool
Is player standing in a portal?
float
Portal animation timer (0-1).

MultiplayerLocalPlayer Class

Client-side multiplayer player with network synchronization. Header: Minecraft.Client/MultiplayerLocalPlayer.h
Inherits: LocalPlayer

Constructor

constructor
Creates a multiplayer client player.Parameters:
  • minecraft - Game instance
  • level - World
  • user - User profile
  • connection - Server connection

Network Synchronization

void
Sends position/rotation update to server.Note: Called automatically when position changes significantly
void
Updates player and sends position packets.Automatically sends position every 20 ticks or when changed.

Methods

void
Sends chat message to server.
void
Swings arm and notifies server.
void
Requests respawn from server.
void
Sets health from server update.Parameters:
  • newHealth - New health value
  • damageSource - Source of damage for telemetry

Example Usage

Basic Player Access

Inventory Manipulation

Experience & Levels

Combat & Damage

Movement & Abilities

Food & Hunger

See Also

  • Entity API - Base entity functionality
  • Mob API - Living entity features
  • Level API - Player management in worlds
  • Inventory API - Item and container management