3D position with world reference, yaw, and pitch

Location

A Location represents a position in a world with rotation angles. It is used for teleportation, block lookups, spawning, and spatial calculations.


Constructor

Location(x=0.0, y=0.0, z=0.0, world=None, yaw=0.0, pitch=0.0)

Create a new location.

loc = Location(100, 64, -200, "world")
loc = Location(0, 64, 0, "world_nether", yaw=90, pitch=-45)

Attributes

x

X coordinate (East-West).

y

Y coordinate (altitude).

z

Z coordinate (North-South).

world

The world this location is in.

yaw

Horizontal rotation in degrees. 0 = South, 90 = West, 180 = North, 270 = East.

pitch

Vertical rotation in degrees. 0 = level, -90 = straight up, 90 = straight down.


Methods

add

new_loc = location.add(x, y, z)

Create a new location with the given offsets added. This is synchronous — no await needed.

above = player.location.add(0, 2, 0)

Arithmetic Operators

Location supports +, -, *, and / operators with Location or Vector operands.

Addition (+)

# Location + Location
new_loc = player.location + Location(1, 0, 0)

# Location + Vector (common for directional offsets)
spawn_pos = player.location + player.look_direction * 3

Subtraction (-)

offset = loc_a - loc_b  # Location representing the difference

The result preserves the world, yaw, and pitch of the left-hand operand.

Multiplication (*)

scaled = location * 2.0  # Scale coordinates by a factor

Division (/)

halved = location / 2.0  # Divide coordinates by a factor

normalize

normalized = location.normalize()

Return a new location with the XYZ components normalized to a unit vector. Synchronous.

midpoint

mid = location.midpoint(other)

Return the midpoint between this location and another. Synchronous.

center = loc_a.midpoint(loc_b)

clone

copy = location.clone()

Create an independent copy of this location. Synchronous.

distance

d = location.distance(other)

Calculate the Euclidean distance to another location. Synchronous.

dist = player.location.distance(spawn_location)
if dist < 10:
    await player.send_message("You're near spawn!")

distance_squared

d2 = location.distance_squared(other)

Calculate the squared distance to another location. Synchronous. Faster than distance() when you only need to compare distances (avoids square root).

# More efficient than: if loc.distance(other) < 10
if loc.distance_squared(other) < 100:
    ...

Indexing & Iteration

Location supports indexing, iteration, and unpacking:

# Index access
x = loc[0]  # x
y = loc[1]  # y
z = loc[2]  # z

# Unpacking
x, y, z = loc

# Splat
block = await world.block_at(*loc)

# Length
len(loc)  # 3