diff --git a/Finder.py b/Finder.py new file mode 100644 index 0000000..e1ad30a --- /dev/null +++ b/Finder.py @@ -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] \ No newline at end of file diff --git a/Random.py b/Random.py index 47aba55..ded5e8b 100644 --- a/Random.py +++ b/Random.py @@ -11,4 +11,7 @@ class PseudoRandom: return (self.next//65536) % 32768 def randminmax(self,min,max): - return (self.rand() % (max - min +1)) + min \ No newline at end of file + return (self.rand() % (max - min +1)) + min + + def reset(self): + self.next = self.seed \ No newline at end of file diff --git a/main.py b/main.py index 5584508..659a69e 100644 --- a/main.py +++ b/main.py @@ -1,50 +1,55 @@ +from Finder import Finder 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!): ")) 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") 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") +mode_max = 3 +mode = 0 -for s in range(0, len(stronghold_rings)): - ring = stronghold_rings[s] +while mode < 1 or mode > mode_max: + 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): - dist = pr.randminmax(ring[1],ring[2]) +finder = Finder(worldseed,superflat) - if superflat != True: - 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 +if mode == 1: + out = finder.findAll() +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]) - pos = np.round(pos,2) + out = finder.findRing(ring) +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) \ No newline at end of file + +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])) \ No newline at end of file