Minecraft stronghold
- direction is the cardinal direction the player is facing;
- axis is the horizontal axis and the direction along this axis that the player is tooking towards ("negative Z", "positive Z", "negative X", or "positive X");
- yaw is the player's yaw, 0 meaning facing South (positive is to the West, negative is to the East);
- pitch is the player's pitch, 0 meaning looking horizontally (positive is down, negative is up).
Roll | Pitch | Yaw |
Locate Minecraft stronghold from Eye of Ender throws
Eye of Ender Throws: (X, Z, Yaw)
Yaw is Direction in XZ plane.
Locate Minecraft stronghold from Eye of Ender throws by least-square intersection of lines
Implement using 3D vixtor.py
python library.
import numpy as np
import pandas as pd
# Create DataFrame
df = pd.DataFrame({
'x': [96, -304, -281],
'z': [298, 127, 1844],
'heading': [35.8, 20.2, 109.4]
})
# Convert degrees to radians and calculate unit vectors
df['radians'] = np.radians(df['heading'])
df['unit_x'] = -np.sin(df['radians'])
df['unit_z'] = np.cos(df['radians'])
# Number of lines and dimension
k = df.shape[0]
dimension = 2
# Extract matrices a and n
a = df[['x', 'z']].values.T
n = df[['unit_x', 'unit_z']].values.T
# Initialize matrices R and q
R = np.zeros((dimension, dimension))
q = np.zeros(dimension)
# Generating a system of linear equations, with Rp = q
for i in range(k):
R += np.eye(dimension) - np.outer(n[:, i], n[:, i].T)
q += (np.eye(dimension) - np.outer(n[:, i], n[:, i].T)) @ a[:, i]
# Calculate the least squares fit best point
p_hat = np.linalg.pinv(R) @ q
# Convert the solution to a DataFrame for plotting
df_p = pd.DataFrame(p_hat.reshape(1, -1), columns=['x', 'z'])
print(df_p)
Reading
X, Y, Z
, Roll
, Yaw
and Pitch
.
import mcpi.minecraft as minecraft
mc = minecraft.Minecraft.create()
# Get the player's position
pos = mc.player.getTilePos()
# Print the player's x,y,z
print("X:", pos.x)
print("Y:", pos.y)
print("Z:", pos.z)
# Get the player's rotation
rot = mc.player.getRotation()
# Print the player's roll, yaw and pitch
print("Roll:", rot.roll)
print("Yaw:", rot.yaw)
print("Pitch:", rot.pitch)
# We need only X, Z, and Yaw
print(pos.x, pos.z, rot.yaw)
Minecraft
uses angle as Degree
, while Numpy
uses it as Radian
.
import numpy as np
def convert_minecraft_to_numpy(yaw, pitch):
"""Converts Minecraft yaw and pitch to a numpy array.
Args:
yaw: The Minecraft yaw angle in degrees.
pitch: The Minecraft pitch angle in degrees.
Returns:
A numpy array containing the yaw and pitch angles in radians.
"""
yaw = yaw * np.pi / 180.0
pitch = pitch * np.pi / 180.0
return np.array([yaw, pitch])
def convert_numpy_to_minecraft(yaw, pitch):
"""Converts numpy yaw and pitch to Minecraft angles.
Args:
yaw: The numpy yaw angle in radians.
pitch: The numpy pitch angle in radians.
Returns:
A tuple containing the yaw and pitch angles in degrees.
"""
yaw = yaw * 180.0 / np.pi
pitch = pitch * 180.0 / np.pi
return yaw, pitch