View on GitHub

minecraft_stronghold

Locate Minecraft stronghold from ender pearl throws by least-square intersection of lines

Minecraft stronghold

Facing direction (Towards axis) (yaw/pitch) The orientation of the player:


Roll Pitch Yaw
3 3 3


Locate Minecraft stronghold from Eye of Ender throws

image image image

Eye of Ender Throws: (X, Z, Yaw)
Yaw is Direction in XZ plane.

image image

Locate Minecraft stronghold from Eye of Ender throws by least-square intersection of lines

image

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