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.hInherits:
Mob, CommandSender
Constants
Core Members
Constructor
Creates a new player in the specified world.Parameters:
level- World to spawn player in
Inventory & Items
Gets the currently selected/held item.Returns: Item in selected hotbar slot, or null
Removes one of the selected item from inventory.
Gets armor piece at slot.Parameters:
pos- Armor slot (0=helmet, 1=chest, 2=legs, 3=boots)
Gets total armor defense points.Returns: Defense value (0-20)
Gets armor coverage as percentage.Returns: Coverage (0.0-1.0)
Gets inventory slot by ID.Parameters:
slotId- Slot index
Item Usage
Gets item currently being used (eating, blocking, etc.).
Gets ticks remaining for item use.
Checks if player is using an item.
Gets ticks item has been in use.
Begins using an item.Parameters:
instance- Item to useduration- Max use duration in ticks
Cancels item usage.
Completes item usage (bow release, finish eating).
Checks if player is blocking with shield/sword.
Movement & Abilities
Handles player movement input.Parameters:
xa- Strafe input (-1 to 1)ya- Forward input (-1 to 1)
Player abilities structure:
Called when abilities are updated.Note: Override to sync abilities in multiplayer
Combat
Plays arm swing animation.
Attacks an entity.Parameters:
entity- Target to attack
Plays critical hit effects.
Plays magic critical hit effects (enchanted weapon).
Gets block breaking speed multiplier.Returns: Speed based on tool, enchantments, effects
Checks if player can break this block type.
Health & Damage
Gets maximum health.Returns: 20 (10 hearts) by default
Applies damage to player.Parameters:
source- Damage sourcedmg- Damage amount
true if damage was appliedHandles player death.Parameters:
source- Cause of death
Respawns player at spawn point.
Checks if player is hurt (health < max).
Food & Exhaustion
Gets food/hunger data.Returns: Pointer to FoodData structure
Checks if player can eat.Parameters:
magicalItem- Can eat even when full? (golden apple)
Adds exhaustion (decreases food over time).Parameters:
amount- Exhaustion amount
Experience
Adds experience points.Parameters:
i- XP amount to add
Removes experience levels.Parameters:
amount- Levels to remove
Gets XP needed to reach next level.Returns: XP requirement for current level
Sleeping
Attempts to sleep in a bed.Parameters:
x, y, z- Bed positiontestUse- Only test, don’t actually sleep
Wakes player from bed.Parameters:
forcefulWakeUp- Skip wake animationupdateLevelList- Update world’s sleeping player listsaveRespawnPoint- Set spawn to this bed
Checks if player is sleeping.
Checks if player has slept long enough to skip night.
Gets sleep animation timer.
Gets bed respawn position.
Sets respawn point.
Containers & Interaction
Opens a container inventory.Returns:
true if opened successfullyOpens furnace UI.
Opens dispenser/dropper UI.
Opens brewing stand UI.
Opens trading UI with villager.
Opens enchantment table UI.
Opens crafting table UI.
Closes current container.
Dropping Items
Drops selected item stack.
Drops specific item.
Drops item with optional randomized position.
Statistics
Awards a statistic/achievement.Parameters:
stat- Statistic to incrementparam- Additional data
Gets player score.Returns: Score value (used as death counter)
Identity & Customization
Gets player username.
Gets display name (console gamertag/PSN ID).
Gets Xbox User ID (XUID).
Sets XUID.
Gets unique player UUID.
Sets custom player skin.
Gets current custom skin ID.
Sets custom cape.
Permissions & Privileges
Checks if player can break blocks.
Checks if PvP is allowed for this player.
Checks if flight is allowed.
Checks if player has operator privileges.
Sets a privilege flag.
Dimension Travel
Teleports player to another dimension.Parameters:
i- Dimension ID (0=Overworld, -1=Nether, 1=End)
Handles portal travel timer.
Is player standing in a portal?
Portal animation timer (0-1).
MultiplayerLocalPlayer Class
Client-side multiplayer player with network synchronization. Header:Minecraft.Client/MultiplayerLocalPlayer.hInherits:
LocalPlayer
Constructor
Creates a multiplayer client player.Parameters:
minecraft- Game instancelevel- Worlduser- User profileconnection- Server connection
Network Synchronization
Sends position/rotation update to server.Note: Called automatically when position changes significantly
Updates player and sends position packets.Automatically sends position every 20 ticks or when changed.
Methods
Sends chat message to server.
Swings arm and notifies server.
Requests respawn from server.
Sets health from server update.Parameters:
newHealth- New health valuedamageSource- 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