Represents a player within the world.

Hierarchy

Constructors

Properties

dimension: Dimension

Remarks

Dimension that the entity is currently within.

Throws

This property can throw when used.

id: string

Remarks

Unique identifier of the entity. This identifier is intended to be consistent across loads of a world instance. No meaning should be inferred from the value and structure of this unique identifier - do not parse or interpret it.

Throws

This property can throw when used.

location: Vector3

Remarks

Current location of the entity.

Throws

This property can throw when used.

name: string

Remarks

Name of the player.

Throws

This property can throw when used.

nameTag: string

Remarks

Given name of the entity.

This property can't be edited in read-only mode.

typeId: string

Remarks

Unique identifier of the type of the entity - for example, 'minecraft:skeleton'.

Throws

This property can throw when used.

Methods

  • Returns Vector3

    Remarks

    Returns the current location of the head component of this entity.

    This function can't be called in read-only mode.

    Throws

    This function can throw errors.

  • Returns Vector3

    Remarks

    Returns the current velocity vector of the entity.

    This function can't be called in read-only mode.

    Throws

    This function can throw errors.

  • Returns Vector3

    Remarks

    Returns the current view direction of the entity.

    This function can't be called in read-only mode.

    Throws

    This function can throw errors.

  • Parameters

    • commandString: string

      Command to run. Note that command strings should not start with slash.

    Returns Promise<CommandResult>

    For commands that return data, returns a JSON structure with command response values.

    Remarks

    Runs a particular command asynchronously from the context of this entity. Note that there is a maximum queue of 128 asynchronous commands that can be run in a given tick.

    This function can't be called in read-only mode.

    Throws

    This function can throw errors.

  • Parameters

    Returns void

    Remarks

    Sends a message to the player.

    This function can't be called in read-only mode.

    Throws

    This method can throw if the provided RawMessage is in an invalid format. For example, if an empty name string is provided to score.

    Example

    nestedTranslation.ts

           // Displays "Apple or Coal"
    let rawMessage = {
    translate: "accessibility.list.or.two",
    with: { rawtext: [{ translate: "item.apple.name" }, { translate: "item.coal.name" }] },
    };
    player.sendMessage(rawMessage);

    Example

    scoreWildcard.ts

           // Displays the player's score for objective "obj". Each player will see their own score.
    const rawMessage = { score: { name: "*", objective: "obj" } };
    world.sendMessage(rawMessage);

    Example

    simpleString.ts

           // Displays "Hello, world!"
    world.sendMessage("Hello, world!");

    Example

    translation.ts

           // Displays "First or Second"
    const rawMessage = { translate: "accessibility.list.or.two", with: ["First", "Second"] };
    player.sendMessage(rawMessage);