Last active
April 22, 2024 04:42
-
-
Save lhw/7547d1b3b3f9abfcd29a61c4ef13338a to your computer and use it in GitHub Desktop.
Source: https://www.reddit.com/r/feedthebeast/comments/46s645/immersive_engineering_vein_calculator/ from /u/xavion - repl.it was down this is a copy from the Google cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python port of https://gist.github.com/ApocDev/7d43dfccd00269670de7 | |
class JavaRandom(): | |
def __init__(self, seed): | |
self.seed = (seed ^ 0x5DEECE66D) & ((1<<48) - 1) | |
def NextInt(self): | |
return self.Next(32) | |
def NextDouble(self): | |
return ((self.Next(26) << 27) + self.Next(27))/(1<<53) | |
def Next(self, bits): | |
self.seed = (self.seed * 0x5DEECE66D + 0xB) & ((1<<48) - 1) | |
return self.seed >> (48 - bits) | |
PosX = 0 | |
PosZ = 0 | |
ChunkRadius = 10 | |
SEED = 1 | |
IncludePlatinum = False | |
VeinToFind = "Uranium" | |
VeinChance = {} | |
def getRandomMineral(x, z): | |
seed = 940610 | |
RNG = JavaRandom(SEED + x * x * 4987142 + x * 5947611 + z * z * 4392871 + z * 389711 ^ seed) | |
dd = RNG.NextDouble() | |
if dd > 0.125: | |
return None | |
else: | |
query = RNG.NextInt() | |
weight = abs(query % sum(VeinChance.values())) | |
for v in VeinChance: | |
weight -= VeinChance[v] | |
if weight < 0: | |
return v | |
return None | |
def getInt(prompt = ""): | |
num = input(prompt) | |
while not isinstance(num, int): | |
try: | |
num = int(num) | |
except ValueError: | |
num = input("Please enter an integer") | |
return num | |
def getBool(prompt = ""): | |
ans = input(prompt + "Y/N") | |
while not isinstance(ans, bool): | |
if ans.lower() in ["n", "no"]: | |
ans = False | |
elif ans.lower() in ["y", "yes"]: | |
ans = True | |
else: | |
ans = input("Please enter Yes/No") | |
return ans | |
def setup(): | |
global SEED, IncludePlatinum, PosX, PosZ, ChunkRadius, VeinToFind | |
SEED = getInt("What is your seed? ") | |
IncludePlatinum = getBool("Does platinum spawn? (No in Infinity)") | |
PosX = getInt("What is your X position? ") | |
PosZ = getInt("What is your Z position? ") | |
ChunkRadius = getInt("How many chunks away do you want to search? Suggested values < 24 ") | |
veins = ["iron", "magnetite", "pyrite", "bauxite", "copper", "cassiterite", "gold", "nickel", "uranium", "quartzite", "galena", "lead", "silver", "lapis", "coal", "any", "all"] | |
VeinToFind = input("What vein are you looking for? ") | |
while not (VeinToFind.lower() in veins or (IncludePlatinum and VeinToFind.lower() == "platinum")): | |
VeinToFind = input("Please enter a valid vein (or any/all)") | |
def main(): | |
VeinChance["Iron"] = 25 | |
VeinChance["Magnetite"] = 25 | |
VeinChance["Pyrite"] = 20 | |
VeinChance["Bauxite"] = 20 | |
VeinChance["Copper"] = 30 | |
VeinChance["Cassiterite"] = 15 | |
VeinChance["Gold"] = 20 | |
VeinChance["Nickel"] = 20 | |
if IncludePlatinum: | |
VeinChance["Platinum"] = 5 | |
VeinChance["Uranium"] = 10 | |
VeinChance["Quartzite"] = 5 | |
VeinChance["Galena"] = 15 | |
VeinChance["Lead"] = 10 | |
VeinChance["Silver"] = 10 | |
VeinChance["Lapis"] = 10 | |
VeinChance["Coal"] = 25 | |
chunkX = PosX >> 4 | |
chunkZ = PosZ >> 4 | |
for x in range(-ChunkRadius, ChunkRadius): | |
for z in range(-ChunkRadius, ChunkRadius): | |
mineral = getRandomMineral(chunkX + x, chunkZ + z) | |
if mineral != None and (VeinToFind.lower() in ["any", "all"] or mineral.lower() == VeinToFind.lower()): | |
print("Chunk {0}, {1} has {2}".format(((chunkX + x) << 4), ((chunkZ + z) << 4), mineral)) | |
setup() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment