Перейти к основному содержанию

Player

Module used to manipulate local player. Player is also an entity in Minecraft, so you can use all the functions from Entity module as well. To get player's entity uid, call Player.getLocal or Player.getServer depends on usage. Most of the methods are client-side, use PlayerActor instead.

Index

Interfaces

PlayerExhaustion

PlayerExhaustion:

Interface used to manipulate player's exhaustion.

@deprecated

get

  • get(): number

  • Returns number

    Player's current exhaustion.

set

  • set(value: number): void
  • Sets player's exhaustion.


    Parameters

    • value: number

      exhaustion value to be set

    Returns void

PlayerExperience

PlayerExperience:

Interface used to manipulate player's experience.

@deprecated

add

  • add(exp: number): void
  • Adds specified amount of experience to the current value.


    Parameters

    • exp: number

      amount to be added

    Returns void

get

  • get(): number

  • Returns number

    Player's current experience.

set

  • set(exp: number): void
  • Sets player's experience.


    Parameters

    • exp: number

      experience value to be set

    Returns void

PlayerFlying

PlayerFlying:

Interface used to manipulate player's flying ability and state.

@deprecated

get

  • get(): boolean

  • Returns boolean

    true if player is flying, false otherwise.

getEnabled

  • getEnabled(): boolean

  • Returns boolean

    true if player is allowed to fly, false otherwise.

set

  • set(enabled: boolean): void
  • Changes player's current flying state, call Player.PlayerFlying.setEnabled to be able to set this property to true.


    Parameters

    • enabled: boolean

      whether the player should fly or not

    Returns void

setEnabled

  • setEnabled(enabled: boolean): void
  • Enables or disables player's ability to fly.


    Parameters

    • enabled: boolean

      whether the player can fly or not

    Returns void

PlayerHealth

PlayerHealth:

Interface used to manipulate player's health.

@deprecated

get

  • get(): number

  • Returns number

    Player's current health.

set

  • set(value: number): void
  • Sets player's health.


    Parameters

    • value: number

      health value to be set

    Returns void

PlayerHunger

PlayerHunger:

Interface used to manipulate player's hunger.

@deprecated

get

  • get(): number

  • Returns number

    Player's current hunger.

set

  • set(value: number): void
  • Sets player's hunger.


    Parameters

    • value: number

      hunger value to be set

    Returns void

PlayerLevel

PlayerLevel:

Interface used to manipulate player's level.

@deprecated

add

  • add(level: number): void
  • Adds specified amount of level to the current value.


    Parameters

    • level: number

      amount to be added

    Returns void

get

  • get(): number

  • Returns number

    Player's current level.

set

  • set(level: number): void
  • Sets player's level.


    Parameters

    • level: number

      level value to be set

    Returns void

PlayerSaturation

PlayerSaturation:

Interface used to manipulate player's saturation.

@deprecated

get

  • get(): number

  • Returns number

    Player's current saturation.

set

  • set(value: number): void
  • Sets player's saturation.


    Parameters

    • value: number

      saturation value to be set

    Returns void

PlayerScore

PlayerScore:

Interface used to manipulate player's score.

@deprecated

Consider using Player.getScore.

get

  • get(): number

  • Returns number

    Player's current score.

PointedData

PointedData:

Entity pointed data, which is used in Player.getPointed.

block

block: Tile

Pointed block data, if player doesn't look at the block, air block is returned.

entity

entity: number

Pointed entity, if no entity's pointed, returns -1.

pos

Pointed block position.

vec

vec: Vector

Look vector.

Functions

addExperience

  • addExperience(exp: number): void
  • Adds specified amount of experience to the current value.

    @deprecated

    Client-side only, use PlayerActor.addExperience instead.


    Parameters

    • exp: number

      amount to be added

    Returns void

addItemToInventory

  • addItemToInventory(id: number, count: number, data: number, extra?: ItemExtraData, preventDrop?: boolean): void
  • Adds items to player's inventory, stacking them if possible.

    @deprecated

    Client-side only, use PlayerActor.addItemToInventory instead.


    Parameters

    • id: number

      item ID

    • count: number

      item count

    • data: number

      item data

    • optionalextra: ItemExtraData

      item extra

    • optionalpreventDrop: boolean

      if set to false, function drops items that could not be added to player's inventory, destroys them otherwise

    Returns void

addLevel

  • addLevel(level: number): void
  • Adds specified amount of level to the current value.

    @deprecated

    Client-side only, use PlayerActor.setLevel instead.


    Parameters

    • level: number

      amount to be added

    Returns void

addPosition

  • addPosition(x: number, y: number, z: number): void
  • Changes current player position by specified vector.

    @deprecated

    Client-side only, use Entity.addPosition instead.


    Parameters

    • x: number
    • y: number
    • z: number

    Returns void

addVelocity

  • addVelocity(x: number, y: number, z: number): void
  • Updates current entity's velocity by specified values.

    @deprecated

    Client-side only, use Entity.addVelocity instead.


    Parameters

    • x: number
    • y: number
    • z: number

    Returns void

decreaseCarriedItem

  • decreaseCarriedItem(count?: number): void
  • Decreases carried item count by specified number.

    @deprecated

    Client-side only, use PlayerActor.setInventorySlot or Entity.setCarriedItem instead.


    Parameters

    • optionalcount: number

      amount of items to decrease carried item by, default value is 1

    Returns void

exhaustion

experience

flying

get

  • get(): number
  • Gets server player uid or local one if client connected to remote server and client uid is available.


    Returns number

    -1 if there is no player, for example, on dedicated servers

getArmorSlot


  • Parameters

    • slot: number

      armor slot ID, should be one of the EArmorType values.

    Returns ItemInstance

    Information about item in the specified armor slot.

getBooleanAbility

  • getBooleanAbility(ability: string): number
  • Gets one of the player's abilities in a boolean form.

    @since

    2.0.3b33


    Parameters

    • ability: string

      ability name constant, should be one of the EPlayerAbility constants

    Returns number

    Current value of the ability in a boolean form.

getCarriedItem

getDimension

  • getDimension(): number

  • Returns number

    Current dimension numeric uid, one of the EDimension values or custom dimension ID.

getExhaustion

  • getExhaustion(): number

  • Returns number

    Player's current exhaustion.

getExperience

  • getExperience(): number

  • Returns number

    Player's current experience.

getFloatAbility

  • getFloatAbility(ability: string): number
  • Gets one of the player's abilities in a form of floating-point number.

    @since

    2.0.3b33


    Parameters

    • ability: string

      ability name constant, should be one of the EPlayerAbility constants

    Returns number

    Current value of the ability in a form of floating-point number.

getFlying

  • getFlying(): boolean

  • Returns boolean

    true if player is flying, false otherwise.

getFlyingEnabled

  • getFlyingEnabled(): boolean

  • Returns boolean

    true if player is allowed to fly, false otherwise.

getHealth

  • getHealth(): number

  • Returns number

    Player's current health.

getHunger

  • getHunger(): number

  • Returns number

    Player's current hunger.

getInventory

  • getInventory(loadPart: any, handleEnchant: any, handleNames: any): void
  • @deprecated

    Consider use Player.getInventorySlot instead.


    Parameters

    • loadPart: any
    • handleEnchant: any
    • handleNames: any

    Returns void

getInventorySlot


  • Parameters

    • slot: number

      slot ID, from 0 to 36

    Returns ItemInstance

    Information about item in the specified inventory slot.

getLevel

  • getLevel(): number

  • Returns number

    Player's current level.

getLocal

  • getLocal(): number
  • Gets local player entity uid, which can be used in various client operations with player, like Player.getPointed.

    @since

    2.3.1b115


    Returns number

    -1 if there is no player, for example, on dedicated servers

getOffhandItem


  • Returns ItemInstance

    Player's current offhand item information.

getPointed

  • Fetches information about the objects player is currently pointing.


    Returns PointedData

getPosition


  • Returns Vector

    Current player's position.

getSaturation

  • getSaturation(): number

  • Returns number

    Player's current saturation.

getScore

  • getScore(): number

  • Returns number

    Player's current score.

getSelectedSlotId

  • getSelectedSlotId(): number

  • Returns number

    Currently selected inventory slot, from 0 to 8.

getServer

  • getServer(): number
  • Gets player entity uid, which can be used in various server operations with player, like Player.addItemToInventory.

    @since

    2.3.1b115


    Returns number

    -1 if there is no player, for example, on dedicated servers

getVelocity

  • Get player's velocity.


    Returns Vector

    Currently Vector containing player's velocity.

health

hunger

isPlayer

  • isPlayer(entityUid: number): boolean
  • @deprecated

    Works only with local player, use Entity.getType instead.


    Parameters

    • entityUid: number

    Returns boolean

    true if specified entity is of player type, false otherwise.

level

localPlayerTurn

  • localPlayerTurn(deltaX: number, deltaY: number): void
  • Simulates local player rotation by specified delta.

    @since

    2.4.0b120 (implemented in 2.3.1b116)


    Parameters

    • deltaX: number

      horizontal radians offset

    • deltaY: number

      vertical radians offset

    Returns void

resetCameraEntity

  • resetCameraEntity(): void
  • Resets player's camera if it was previously set to another entity.


    Returns void

resetFov

  • resetFov(): void
  • Resets view zoom to the default value.


    Returns void

saturation

score

setAbility

  • setAbility(ability: string, value: number | boolean): void
  • Sets some of the player's abilities. If the argument is of type boolean, sets the ability as the boolean one, otherwise as numeric one.

    @since

    2.0.3b33

    @deprecated

    Parameters

    • ability: string

      ability name constant, should be one of the EPlayerAbility constants

    • value: number | boolean

      the value to be set for the ability; can be either boolean or number, depending on the ability

    Returns void

setArmorSlot

  • setArmorSlot(slot: number, id: number, count: number, data: number, extra?: ItemExtraData): void
  • Sets contents of the specified armor slot.

    @deprecated

    Client-side only, use PlayerActor.setArmor instead.


    Parameters

    • slot: number

      armor slot ID, should be one of the EArmorType values

    • id: number

      item ID

    • count: number

      item count

    • data: number

      item data

    • optionalextra: ItemExtraData

      item extra

    Returns void

setCameraEntity

  • setCameraEntity(entityUid: number): void
  • Sets player's camera to the specified entity.


    Parameters

    • entityUid: number

      entity uid

    Returns void

setCarriedItem

  • setCarriedItem(id: number, count: number, data: number, extra?: ItemExtraData): void

setExhaustion

  • setExhaustion(value: number): void
  • Sets player's exhaustion.

    @since

    2.0.1b17 (not worked before)

    @deprecated

    Client-side only, use PlayerActor.setExhaustion instead.


    Parameters

    • value: number

      exhaustion value to be set

    Returns void

setExperience

  • setExperience(exp: number): void
  • Sets player's experience.

    @deprecated

    Client-side only, use PlayerActor.setExperience instead.


    Parameters

    • exp: number

      experience value to be set

    Returns void

setFlying

  • setFlying(enabled: boolean): void
  • Changes player's current flying state, call Player.setFlyingEnabled to be able to set this property to true.


    Parameters

    • enabled: boolean

      whether the player should fly or not

    Returns void

setFlyingEnabled

  • setFlyingEnabled(enabled: boolean): void
  • Enables or disables player's ability to fly.

    @deprecated

    Client-side only, use PlayerActor.setCanFly instead.


    Parameters

    • enabled: boolean

      whether the player can fly or not

    Returns void

setFov

  • setFov(fov: number): void
  • Sets view zoom, to reset value call Player.resetFov.


    Parameters

    • fov: number

      view zoom, default zoom is about 70

    Returns void

setHealth

  • setHealth(value: number): void

setHunger

  • setHunger(value: number): void
  • Sets player's hunger.

    @since

    2.0.1b17 (not worked before)

    @deprecated

    Client-side only, use PlayerActor.setHunger instead.


    Parameters

    • value: number

      hunger value to be set

    Returns void

setInventorySlot

  • setInventorySlot(slot: number, id: number, count: number, data: number, extra?: ItemExtraData): void
  • Sets contents of the specified inventory slot.

    @deprecated

    Client-side only, use PlayerActor.setInventorySlot instead.


    Parameters

    • slot: number

      slot ID, from 0 to 36

    • id: number

      item ID

    • count: number

      item count

    • data: number

      item data

    • optionalextra: ItemExtraData

      item extra

    Returns void

setLevel

  • setLevel(level: number): void
  • Sets player's level.

    @deprecated

    Client-side only, use PlayerActor.setLevel instead.


    Parameters

    • level: number

      level value to be set

    Returns void

setOffhandItem

  • setOffhandItem(id: number, count: number, data: number, extra?: ItemExtraData): void
  • Sets current offhand item for the player.

    @deprecated

    Client-side only, use Entity.setOffhandItem instead.


    Parameters

    • id: number

      item ID

    • count: number

      item count

    • data: number

      item data

    • optionalextra: ItemExtraData

      item extra

    Returns void

setPosition

  • setPosition(x: number, y: number, z: number): void
  • Sets specified coordinates as player's position.

    @deprecated

    Client-side only, use Entity.setPosition instead.


    Parameters

    • x: number
    • y: number
    • z: number

    Returns void

setSaturation

  • setSaturation(value: number): void
  • Sets player's saturation.

    @since

    2.0.1b17 (not worked before)

    @deprecated

    Client-side only, use PlayerActor.setSaturation instead.


    Parameters

    • value: number

      saturation value to be set

    Returns void

setSelectedSlotId

  • setSelectedSlotId(slot: number): void
  • Selects currently selected inventory slot.


    Parameters

    • slot: number

      slot ID to be selected, from 0 to 8

    Returns void

setVelocity

  • setVelocity(x: number, y: number, z: number): void
  • Set player's velocity using velocity vector.

    @deprecated

    Client-side only, use Entity.setVelocity instead.


    Parameters

    • x: number

      velocity

    • y: number

      velocity

    • z: number

      velocity

    Returns void