14. API - Players

The player module defines the Players class, which is available via the players attribute, the Player class, which represents an arbitrary player in the world, and the HostPlayer class which represents the player on the host machine (accessible via the player attribute).

Note

All items in this module are available from the picraft namespace without having to import picraft.player directly.

The following items are defined in the module:

14.1. Player

class picraft.player.Player(connection, player_id)[source]

Represents a player within the game world.

Players are uniquely identified by their player_id. Instances of this class are available from the players mapping. It provides properties to query and manipulate the position and settings of the player.

direction

The direction the player is facing as a unit vector.

This property can be queried to retrieve a unit Vector pointing in the direction of the player’s view.

Warning

Player direction is only supported on Raspberry Juice.

heading

The direction the player is facing in clockwise degrees from South.

This property can be queried to determine the direction that the player is facing. The value is returned as a floating-point number of degrees from North (i.e. 180 is North, 270 is East, 0 is South, and 90 is West).

Warning

Player heading is only supported on Raspberry Juice.

pitch

The elevation of the player’s view in degrees from the horizontal.

This property can be queried to determine whether the player is looking up (values from 0 to -90) or down (values from 0 down to 90). The value is returned as floating-point number of degrees from the horizontal.

Warning

Player pitch is only supported on Raspberry Juice.

player_id

Returns the integer ID of the player on the server.

pos

The precise position of the player within the world.

This property returns the position of the selected player within the Minecraft world, as a Vector instance. This is the precise position of the player including decimal places (representing portions of a tile). You can assign to this property to reposition the player.

tile_pos

The position of the player within the world to the nearest block.

This property returns the position of the selected player in the Minecraft world to the nearest block, as a Vector instance. You can assign to this property to reposition the player.

14.2. HostPlayer

class picraft.player.HostPlayer(connection)[source]

Represents the host player within the game world.

An instance of this class is accessible as the Game.player attribute. It provides properties to query and manipulate the position and settings of the host player.

autojump

Write-only property which sets whether the host player autojumps.

When this property is set to True (which is the default), the host player will automatically jump onto blocks when it runs into them (unless the blocks are too high to jump onto).

Warning

Player settings are only supported on Minecraft Pi edition.

Note

Unfortunately, the underlying protocol provides no means of reading a world setting, so this property is write-only (attempting to query it will result in an AttributeError being raised).

direction

The direction the player is facing as a unit vector.

This property can be queried to retrieve a unit Vector pointing in the direction of the player’s view.

Warning

Player direction is only supported on Raspberry Juice.

heading

The direction the player is facing in clockwise degrees from South.

This property can be queried to determine the direction that the player is facing. The value is returned as a floating-point number of degrees from North (i.e. 180 is North, 270 is East, 0 is South, and 90 is West).

Warning

Player heading is only supported on Raspberry Juice.

pitch

The elevation of the player’s view in degrees from the horizontal.

This property can be queried to determine whether the player is looking up (values from 0 to -90) or down (values from 0 down to 90). The value is returned as floating-point number of degrees from the horizontal.

Warning

Player pitch is only supported on Raspberry Juice.

pos

The precise position of the player within the world.

This property returns the position of the selected player within the Minecraft world, as a Vector instance. This is the precise position of the player including decimal places (representing portions of a tile). You can assign to this property to reposition the player.

tile_pos

The position of the player within the world to the nearest block.

This property returns the position of the selected player in the Minecraft world to the nearest block, as a Vector instance. You can assign to this property to reposition the player.