Player
The player API inherits functions from the living entity API
The player API is accessed through the player
global. Like so: player:isGliding()
Player information that isn't synced between clients is kept in the host API. Examples of unsynced data are: Creative flying, status effects, and remaining air amount.
There are times during a script's functioning where the script will run, but the player global will be empty. This will cause the "Tried to access the EntityAPI before its initialization" error. To solve this, move the player API call into a protected event. If you wish to initialize a check during the initialization phase of a script (outside any other event) you can use the entity_init
event.
For most other circumstances you will want the tick
event, as checks like player:isGliding()
will be updated once a game tick inside that event. (There are 20 ticks in a second, and this is how often Minecraft updates information- some player functions work better in a tick event for this reason).
All provided examples assume you're using a tick event.
To reiterate:
player:isGliding() -- will error
function events.entity_init()
player:isGliding() -- will not error, but will only play once
end
player:isGliding() -- will error
function events.tick()
player:isGliding() -- won't error, and will update once a tick
end
player:isGliding() -- will error
Player Transformations
getPos()
Gets the position of the entity in the world
If delta is passed in, then it will be used to linearly interpolate the position of the entity between the previous tick and the current tick
The default value of delta is 1
Example:
player:getPos()
getRot()
Gets the rotation of the entity in degrees
If delta is passed in, then it will be used to linearly interpolate the rotation of the entity between the previous tick and the current tick
The default value of delta is 1
Example:
player:getRot()
getBodyYaw()
Gets the yaw of this entity's body in degrees
If delta is passed in, then it will be used to linearly interpolate the rotation of the body between the previous tick and the current tick
The default value of delta is 1
Example:
player:getBodyYaw()
getLookDir()
Returns a unit vector pointing in the direction that this entity is looking
See the blue line in the F3+B screen for an example
Example:
player:getLookDir()
getVelocity()
Gets the current velocity of this entity in world coordinates, calculated as its position this tick minus its position last tick
Example:
player:getVelocity()
Gets the current velocity of this entity in world coordinates, calculated as its position this tick minus its position last tick
Player Actions
getPose()
Returns the current pose of the player
For players this can be one of: "STANDING", "FALL_FLYING", "SLEEPING", "SWIMMING", "SPIN_ATTACK", or "CROUCHING"
Example:
player:getPose() == "CROUCHING"
isCrouching()
Returns true if this entity is visually sneaking
Example:
player:isCrouching()
isGliding()
Returns if this entity is gliding with an elytra
Example:
player:isGliding()
isFishing()
Returns if the player is currently fishing
Example:
player:isFishing()
isBlocking()
Return if this entity is blocking with a shield
Example:
player:isBlocking()
isVisuallySwimming()
Returns if this entity have the swimming pose
Example:
player:isVisuallySwimming()
isClimbing()
Returns true if the entity is currently using a climbable block, like a ladder or vine
Example:
player:isClimbing()
isSneaking()
Returns true if this entity is logically sneaking (can't fall from blocks edges, can't see nameplate behind walls, etc)
Example:
player:isSneaking()
isSprinting()
Returns true if this entity is currently sprinting
Example:
player:isSprinting()
riptideSpinning()
Returns if this entity is riptide spinning
Example:
player:riptideSpinning()
Returns if this entity is riptide spinning
Player Data
isLoaded()
Checks if this entity object is still being updated and loaded
A non loaded entity would be someone who is in another dimension or out of the render distance for example
Example:
player:isLoaded()
getNbt()
Gets a table containing the NBT of this entity
Please note that not all values in the entity's NBT may be synced, as some are handled only on server side
Example:
player:getNbt()
getChargedAttackDelay()
Returns the delay (in ticks) of charged attacks
Example:
player:getChargedAttackDelay()
getExperienceProgress()
Gets the progress of the way towards the player's next level, as a value from 0 to 1
Example:
player:getExperienceProgress()
getExperienceLevel()
Gets the player's current level
Example:
player:getExperienceLevel()
getShoulderEntity()
Returns a table of the nbt of this entity left or right shoulder entity
Example:
player:getShoulderEntity()
getTeamInfo()
Returns a table with information about the team of this player
Returns nil if the player doesnt have a team
Example:
player:getTeamInfo()
getFood()
Gets the current food level of the player, from 0 to 20
Example:
player:getfood()
getGamemode()
Returns "SURVIVAL", "CREATIVE", "ADVENTURE", or "SPECTATOR" depending on the player's gamemode
If the gamemode is unknown, returns nil
Example:
player:getGamemode()
getSaturation()
Gets the current saturation level of the player
Example:
player:getSaturation()
getExhaustion()
Gets the current exhaustion level of the player
Example:
player:getExhaustion()
getAbsorptionAmount()
Returns the amount of this entity's absorption (yellow hearts)
Example:
player:getAbsorptionAmount()
getArmor()
Returns the amount of armor points this entity has
Example:
player:getArmor()
getMaxHealth()
Returns the maximum amount of health this entity can have
Example:
player:getMaxHealth()
getHealth()
Returns the amount of health this entity has remaining
Example:
player:getHealth()
getDeathTime()
Returns the number of ticks this entity has been dead for
Example:
player:getDeathTime()
getStingerCount()
Returns the number of bee stingers sticking out of this entity
Example:
player:getStingercount()
getArrowCount()
Returns the number of arrows sticking out of this entity
Example:
player:getArrowCount()
getEntityCategory()
Returns the category of this entity
The categories are: "ARTHROPOD", "UNDEAD", "WATER", "ILLAGER" and by default, "UNDEFINED"
Example:
player:getEntityCategory() == "UNDEAD"
isSensitiveToWater()
Returns if this entity takes damage to water
Example:
player:isSensitiveToWater()
getName()
Gets the name of this entity, if it has a custom name
If it doesn't, returns a translated form of getType()
Example:
player:getName()
isAlive()
Returns whether this entity is alive or not
Example:
player:isAlive()
getType()
Gets the Minecraft identifier of this entity
For instance, "minecraft:pig" Example:
player:getType() == "minecraft:player"