search modes
This commit is contained in:
parent
6b577fa5fe
commit
848887faa4
|
@ -0,0 +1,87 @@
|
||||||
|
from Random import PseudoRandom
|
||||||
|
import numpy as np
|
||||||
|
import math
|
||||||
|
|
||||||
|
stronghold_rings = [
|
||||||
|
[3,1408,2688],
|
||||||
|
[6,4480,5760],
|
||||||
|
[10,7552,8832],
|
||||||
|
[15,10624,11904],
|
||||||
|
[21,13696,14976],
|
||||||
|
[28,16768,18048],
|
||||||
|
[36,19840,21120],
|
||||||
|
[9,22912,24192]
|
||||||
|
]
|
||||||
|
|
||||||
|
bedrock_max = -58
|
||||||
|
overworld_min = -62
|
||||||
|
|
||||||
|
|
||||||
|
class Finder:
|
||||||
|
def __init__(self,worldseed,superflat):
|
||||||
|
self.worldseed = worldseed
|
||||||
|
self.superflat = superflat
|
||||||
|
self.pr = PseudoRandom(worldseed)
|
||||||
|
|
||||||
|
def getSeed(self):
|
||||||
|
return self.worldseed
|
||||||
|
|
||||||
|
|
||||||
|
def findRingUnsafe(self, ring_num): #carefull! this one does NOT set random to the correct values before doing anything
|
||||||
|
out = []
|
||||||
|
ring = stronghold_rings[ring_num-1]
|
||||||
|
|
||||||
|
angle = self.pr.rand()
|
||||||
|
angle = (angle / 32767) * (math.pi*2)
|
||||||
|
|
||||||
|
for a in range(1, ring[0]+1):
|
||||||
|
dist = self.pr.randminmax(ring[1],ring[2])
|
||||||
|
|
||||||
|
if self.superflat != True:
|
||||||
|
self.pr.randminmax(bedrock_max+1,overworld_min+68) #mineclone would do height calculations here, and uses "random" numbers if world is NOT superflat
|
||||||
|
#however, that changed the next number, so I have to do that here as well
|
||||||
|
|
||||||
|
pos = np.array([math.cos(angle) * dist , math.sin(angle) * dist])
|
||||||
|
pos = np.round(pos,2)
|
||||||
|
|
||||||
|
out.append(pos)
|
||||||
|
|
||||||
|
angle = math.fmod(angle + ((math.pi*2) / ring[0]), math.pi*2)
|
||||||
|
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def findRing(self,ring_num): #when you aren't in this class, you may only use this method
|
||||||
|
self.pr.reset()
|
||||||
|
for i in range(0,ring_num-1):
|
||||||
|
self.pr.rand()
|
||||||
|
for p in range(0, stronghold_rings[i][0]):
|
||||||
|
self.pr.rand()
|
||||||
|
if not self.superflat:
|
||||||
|
self.pr.rand()
|
||||||
|
|
||||||
|
return self.findRingUnsafe(ring_num)
|
||||||
|
|
||||||
|
def findAll(self):
|
||||||
|
out = []
|
||||||
|
for i in range(1,len(stronghold_rings)+1):
|
||||||
|
out += self.findRing(i)
|
||||||
|
|
||||||
|
self.pr.reset()
|
||||||
|
return out
|
||||||
|
|
||||||
|
def findNearestX(self,pos, amount):
|
||||||
|
positions = []
|
||||||
|
distances = []
|
||||||
|
for i in range(0,amount):
|
||||||
|
positions.append(None)
|
||||||
|
distances.append(0xffff)
|
||||||
|
|
||||||
|
for stronghold in self.findAll():
|
||||||
|
if (np.linalg.norm(stronghold-pos) < max(distances)):
|
||||||
|
maxindex = distances.index(max(distances))
|
||||||
|
distances[maxindex] = np.linalg.norm(stronghold-pos)
|
||||||
|
positions[maxindex] = stronghold
|
||||||
|
|
||||||
|
|
||||||
|
return [positions,distances]
|
|
@ -12,3 +12,6 @@ class PseudoRandom:
|
||||||
|
|
||||||
def randminmax(self,min,max):
|
def randminmax(self,min,max):
|
||||||
return (self.rand() % (max - min +1)) + min
|
return (self.rand() % (max - min +1)) + min
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
|
self.next = self.seed
|
71
main.py
71
main.py
|
@ -1,50 +1,55 @@
|
||||||
|
from Finder import Finder
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import math
|
|
||||||
from Random import PseudoRandom
|
|
||||||
|
|
||||||
stronghold_rings = [
|
|
||||||
[3,1408,2688],
|
|
||||||
[6,4480,5760],
|
|
||||||
[10,7552,8832],
|
|
||||||
[15,10624,11904],
|
|
||||||
[21,13696,14976],
|
|
||||||
[28,16768,18048],
|
|
||||||
[36,19840,21120],
|
|
||||||
[9,22912,24192]
|
|
||||||
]
|
|
||||||
|
|
||||||
bedrock_max = -58
|
|
||||||
overworld_min = -62
|
|
||||||
|
|
||||||
worldseed = int(input("Please enter your world seed (No text seeds, numberic form only!): "))
|
worldseed = int(input("Please enter your world seed (No text seeds, numberic form only!): "))
|
||||||
print("\nEnter 'Y' if your world is superflat, anything else if its not!")
|
print("\nEnter 'Y' if your world is superflat, anything else if its not!")
|
||||||
print("If you don't specify this correctly, you'll get wrong coords!\n")
|
print("If you don't specify this correctly, you'll get wrong coords!\n")
|
||||||
|
|
||||||
superflat = input("Superflat? :") == 'Y'
|
superflat = input("Superflat? :") == 'Y'
|
||||||
|
|
||||||
pr = PseudoRandom(worldseed)
|
|
||||||
|
|
||||||
print("Starting looking for strongholds on world with seed {seed}, superflat: {superflat}".format(seed=worldseed,superflat=superflat))
|
|
||||||
print("\n\n")
|
print("\n\n")
|
||||||
|
|
||||||
|
mode_max = 3
|
||||||
|
mode = 0
|
||||||
|
|
||||||
for s in range(0, len(stronghold_rings)):
|
while mode < 1 or mode > mode_max:
|
||||||
ring = stronghold_rings[s]
|
print("""
|
||||||
|
Which Search-Mode would you like to use?\n
|
||||||
|
\t1: All strongholds\n
|
||||||
|
\t2: Strongholds within ring\n
|
||||||
|
\t3: nearest x strongholds\n\n
|
||||||
|
""")
|
||||||
|
|
||||||
angle = pr.rand()
|
mode = int(input("Please select your mode: "))
|
||||||
|
|
||||||
angle = (angle / 32767) * (math.pi*2)
|
#would like to use match cases here, but python 3.9 isn't old enoght *yet*
|
||||||
|
out = []
|
||||||
|
|
||||||
for a in range(1, ring[0]+1):
|
finder = Finder(worldseed,superflat)
|
||||||
dist = pr.randminmax(ring[1],ring[2])
|
|
||||||
|
|
||||||
if superflat != True:
|
if mode == 1:
|
||||||
pr.randminmax(bedrock_max+1,overworld_min+68) #mineclone would do height calculations here, and uses "random" numbers if world is NOT superflat
|
out = finder.findAll()
|
||||||
#however, that changed the next number, so I have to do that here as well
|
elif mode == 2:
|
||||||
|
ring = 0
|
||||||
|
while ring < 1 or ring > 8:
|
||||||
|
ring = int(input("Please enter your ring: "))
|
||||||
|
|
||||||
pos = np.array([math.cos(angle) * dist , math.sin(angle) * dist])
|
out = finder.findRing(ring)
|
||||||
pos = np.round(pos,2)
|
else:
|
||||||
|
x = int(input("Please enter your x coordinate: "))
|
||||||
|
z = int(input("Please enter your z coordinate: "))
|
||||||
|
amount = int(input("How many strongholds would you like to find: "))
|
||||||
|
|
||||||
print("found stronghold in the {ring}th stronghold ring! Position: {pos}".format(ring=s+1,pos=str(pos)))
|
out =finder.findNearestX(np.array([x,z]),amount)
|
||||||
|
|
||||||
angle = math.fmod(angle + ((math.pi*2) / ring[0]), math.pi*2)
|
|
||||||
|
print("Done looking for your strongholds! Here is a list of coordinates: ")
|
||||||
|
|
||||||
|
if mode != 3:
|
||||||
|
for coordinate in out:
|
||||||
|
print(str(coordinate))
|
||||||
|
else:
|
||||||
|
positions = out[0]
|
||||||
|
distances = out[1]
|
||||||
|
|
||||||
|
for i in range(0, len(positions)):
|
||||||
|
print("{pos} Distance: {dis}".format(pos=positions[i],dis=distances[i]))
|
Loading…
Reference in New Issue