location – Locations

The location module contains objects for tracking and analyzing locations.

class bravo.location.Location[source]

Bases: object

The position and orientation of an entity.

classmethod at_block(x, y, z)[source]

Pinpoint a location at a certain block.

This constructor is intended to aid in pinpointing locations at a specific block rather than forcing users to do the pixel<->block maths themselves. Admittedly, the maths in question aren’t hard, but there’s no reason to avoid this encapsulation.

clamp()[source]

Force this location to be sane.

Forces the position and orientation to be sane, then fixes up location-specific things, like stance.

Returns:bool indicating whether this location had to be altered
distance(other)[source]

Return the distance between this location and another location.

in_front_of(distance)[source]

Return a Location a certain number of blocks in front of this position.

The orientation of the returned location is identical to this position’s orientation.

Parameters:distance (int) – the number of blocks by which to offset this position
save_to_packet()[source]

Returns a position/look/grounded packet.

class bravo.location.Orientation[source]

Bases: bravo.location.Orientation

The angles corresponding to the heading of an entity.

Theta and phi are very much like the theta and phi of spherical coordinates, except that phi’s zero is perpendicular to the XZ-plane rather than pointing straight up or straight down.

Orientation is stored in floating-point radians, for simplicity of computation. Unfortunately, no wire protocol speaks radians, so several conversion methods are provided for sanity and convenience.

The from_degs() and to_degs() methods provide integer degrees. This form is called “yaw and pitch” by protocol documentation.

classmethod from_degs(yaw, pitch)[source]

Create an Orientation from integer degrees.

to_degs()[source]

Return this orientation as integer degrees.

to_fracs()[source]

Return this orientation as fractions of a byte.

class bravo.location.Position[source]

Bases: bravo.location.Position

The coordinates pointing to an entity.

Positions are always stored as integer absolute pixel coordinates.

distance(other)[source]

Return the distance between this position and another, in absolute pixels.

classmethod from_player(x, y, z)[source]

Create a Position from floating-point block coordinates.

heading(other)[source]

Return the heading from this position to another, in radians.

This is a wrapper for the common atan2() expression found in games, meant to help encapsulate semantics and keep copy-paste errors from happening.

to_block()[source]

Return this position as block coordinates.

to_player()[source]

Return this position as floating-point block coordinates.