116 lines
3.1 KiB
Python
116 lines
3.1 KiB
Python
from re import findall
|
|
from math import floor
|
|
|
|
commands = True
|
|
|
|
starting_x = 0
|
|
starting_z = 0
|
|
|
|
max_invisible = 0
|
|
min_visible = 32
|
|
|
|
target = "spawner"
|
|
|
|
|
|
def obtain_coordinates(message: str) -> tuple[int, int]:
|
|
regex = r"[^\d]*?(-?\d+)[^\d]+?(-?\d+)[^\d]*"
|
|
user_input = input(message)
|
|
matches = findall(regex, user_input)
|
|
|
|
if len(matches) < 1:
|
|
print("Incorrect format")
|
|
return obtain_coordinates(message)
|
|
|
|
raw_coordinates = matches[0]
|
|
return (int(raw_coordinates[0]), int(raw_coordinates[1]))
|
|
|
|
|
|
def scan_render_distance(render_distance: int) -> bool:
|
|
user_input = input(
|
|
f"Set your render distance to {render_distance}. " +
|
|
f"Open the pie chart and check if {target} is present." +
|
|
"Enter Y if it is, otherwise N.\n")
|
|
|
|
if len(user_input) < 1:
|
|
print("Incorrect format")
|
|
return scan_render_distance(render_distance)
|
|
|
|
first_character = user_input[0].lower()
|
|
if first_character == 'y':
|
|
return True
|
|
if first_character == 'n':
|
|
return False
|
|
|
|
print("Incorrect format")
|
|
return scan_render_distance(render_distance)
|
|
|
|
|
|
def scan_axis(x: int, z: int) -> bool:
|
|
assert x == 0 or z == 0
|
|
assert x > -2 and x < 2
|
|
assert z > -2 and z < 2
|
|
|
|
print(f"Go to X: {starting_x + (x * 16)} Z: {starting_z + (z * 16)}")
|
|
|
|
if z == -1:
|
|
print("Alternatively, NORTH (negative Z) of original chunk")
|
|
if z == 1:
|
|
print("Alternatively, SOUTH (positive Z) of original chunk")
|
|
if x == -1:
|
|
print("Alternatively, WEST (negative X) of original chunk")
|
|
if x == 1:
|
|
print("Alternatively, EAST (positive X) of original chunk")
|
|
|
|
if commands:
|
|
print(f"/tp {starting_x + (x * 16)} ~ {starting_z + (z * 16)}")
|
|
|
|
if not scan_render_distance(max_invisible):
|
|
return False
|
|
|
|
print(
|
|
f"Go to X: {starting_x + (x * 16 * (min_visible + 1))} Z: {starting_z + (z * 16 * (min_visible + 1))}"
|
|
)
|
|
if commands:
|
|
print(
|
|
f"/tp {starting_x + (x * 16 * (min_visible + 1))} ~ {starting_z + (z * 16 * (min_visible + 1))}"
|
|
)
|
|
|
|
input("-- Search finished --")
|
|
exit()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
starting_coordinates = obtain_coordinates(
|
|
"Please enter the coordinates as two whole numbers, X and Z, " +
|
|
"without decimal points, separated by a single space.\n")
|
|
|
|
starting_x = starting_coordinates[0]
|
|
starting_z = starting_coordinates[1]
|
|
print(f"X: {starting_x} Z: {starting_z}")
|
|
|
|
within_32 = scan_render_distance(min_visible)
|
|
if not within_32:
|
|
print(
|
|
f"Target {target} does not exist within 65x65 chunk area. Unlucky :("
|
|
)
|
|
exit()
|
|
|
|
while (min_visible - max_invisible) > 1:
|
|
scan_distance = floor((min_visible + max_invisible) / 2)
|
|
visible = scan_render_distance(scan_distance)
|
|
if visible:
|
|
min_visible = scan_distance
|
|
else:
|
|
max_invisible = scan_distance
|
|
|
|
assert max_invisible < min_visible
|
|
|
|
print(
|
|
f"Target {target} is {min_visible} chunks / {min_visible * 16} blocks away.\n"
|
|
)
|
|
|
|
scan_axis(-1, 0)
|
|
scan_axis(1, 0)
|
|
scan_axis(0, -1)
|
|
scan_axis(0, 1)
|