gregtechdotpy
gregtechdotpy
Code in GregHell
1 post
Freshman at John Jay College, starting to blog my coding projects!
Don't wanna be here? Send us removal request.
gregtechdotpy · 1 month ago
Text
5/12/2025
Today I got hooked on the idea of taking the Gregtech New Horizons modpack for Minecraft and making a program that would combine a lot of different necessary calculators into it. Online I found a spreadsheet (https://docs.google.com/spreadsheets/d/1HgrUWh39L4zA4QDWOSHOovPek1s1eAK1VsZQy_D0zjQ/edit#gid=962322443) that helped with balancing how many coke ovens to water to boilers you need for steam production (something that involves an unnecessary amount of variables, but welcome to GTNH), and decided that I wanted to convert it as my first bite, along with a calculator for how many blocks I would need to build different tank sizes. Eventually I want to move it to a website, but for now it is hosted on my GitHub (https://github.com/lokon100/greghell) while I am starting it!
I haven’t worked in Python for a bit so it was great to come back to it and look at it with fresh eyes, especially for how I stored my variables! I stored my static variables in Pandas Series and Dataframes, which kept it pretty neat and organized.
The “new thing” I decided to look into was how to streamline having a user choose something from a list, and after some searching around I landed on this solution from StackOverflow (https://stackoverflow.com/questions/37565793/how-to-let-the-user-select-an-input-from-a-finite-list) that shows how to have a user choose from a dictionary index. I modified the code so that it would work from a list instead of an index, and it worked perfectly for inputting variables at the beginning of a run!
def selectFromList(options, name="option"):     index = 0     print('Select a ' + name + ':')     for optionName in options:         index = index + 1         print(str(index) + ') ' + optionName)     inputValid = False     while not inputValid:         inputRaw = input(name + ': ')         inputNo = int(inputRaw) - 1         if inputNo > -1 and inputNo < len(options):             selected = options[inputNo]             break         else:             print('Please select a valid ' + name + ' number')     return selected
Rereading my code a bit after I finished it I realized that not very much is different between the two “pressure types” of boilers, and I actually managed to knock a chunk of it off to streamline it which always feels pretty nice! Note to self- always check whether the only difference between your functions is one variable, because you can always just feed those in versus writing out a whole second function and using if loops!
I also noticed that three of the variables would probably never change, so I commented out the input lines and put in static values so that I could have ease of using it for now, but when I finish and publish the sets of calculators I can make it so that everyone can adjust it.
def boiler_math(pressure):     boilerSize = uf.selectFromList(boilerVars['Shape'].tolist())     timeFrame = uf.selectFromList(timeTicks.index.to_list())     fuelType = uf.selectFromList(ovenProd.index.to_list())     numBoilers = int(input("How many boilers?"))     numWater = int(input("How many water tanks?"))     numOvens = int(input("How many coke ovens?"))     rainMod = float(input("What is the rain modifier?"))     if pressure == "high":         solidWater, solidSteam, waterProd = boiler_high(boilerSize, timeFrame, fuelType, numBoilers, numWater, numOvens,rainMod)         liquidWater, liquidSteam, waterProd = boiler_high(boilerSize, timeFrame, 'creosote', numBoilers, numWater, numOvens,rainMod)         totalWater = waterProd-(solidWater+liquidWater)         totalSteam = solidSteam+liquidSteam         print("Total Water Difference: " + str(totalWater) + " Total Steam Production: " + str(totalSteam))     if pressure == "low":         solidWater, solidSteam, waterProd = boiler_low(boilerSize, timeFrame, fuelType, numBoilers, numWater, numOvens,rainMod)         liquidWater, liquidSteam, waterProd = boiler_low(boilerSize, timeFrame, 'creosote', numBoilers, numWater, numOvens,rainMod)         totalWater = waterProd-(solidWater+liquidWater)         totalSteam = solidSteam+liquidSteam         print("Total Water Difference: " + str(totalWater) + " Total Steam Production: " + str(totalSteam)) def boiler_low(boilerSize, timeFrame, fuelType, numBoilers, numWater, numOvens, rainMod):     tanks = boilerVars.loc[boilerVars['Shape'] == boilerSize, 'Size'].iloc[0]     lpMod = boilerVars.loc[boilerVars['Shape'] == boilerSize, 'LP'].iloc[0]     numTicks = timeTicks.loc[timeFrame]     burnTime = fuelTimes.loc[fuelType]     fuelConsumption = lpMod*numTicks/burnTime*numBoilers     steamProduction = tanks*numTicks*10*numBoilers     waterConsumption = steamProduction/150     ovenProduction = ovenProd.loc[fuelType]*numTicks*numOvens     waterProduction = numWater*rainMod*1.25*numTicks     fuelDifference = ovenProduction-fuelConsumption     waterDifference = waterProduction-waterConsumption     print("For " + fuelType + " use")     print("Fuel Difference: " + str(fuelDifference) + " Water Difference: " + str(waterDifference) + " Steam Production: " + str(steamProduction))     return waterConsumption, steamProduction, waterProduction def boiler_high(boilerSize, timeFrame, fuelType, numBoilers, numWater, numOvens, rainMod):     tanks = boilerVars.loc[boilerVars['Shape'] == boilerSize, 'Size'].iloc[0]     hpMod = boilerVars.loc[boilerVars['Shape'] == boilerSize, 'HP'].iloc[0]     numTicks = timeTicks.loc[timeFrame]     burnTime = fuelTimes.loc[fuelType]     fuelConsumption = hpMod*numTicks/burnTime*numBoilers     steamProduction = tanks*numTicks*10*numBoilers     waterConsumption = steamProduction/150     ovenProduction = ovenProd.loc[fuelType]*numTicks*numOvens     waterProduction = numWater*rainMod*1.25*numTicks     fuelDifference = ovenProduction-fuelConsumption     waterDifference = waterProduction-waterConsumption     print("For " + fuelType + " use")     print("Fuel Difference: " + str(fuelDifference) + " Water Difference: " + str(waterDifference) + " Steam Production: " + str(steamProduction))     return waterConsumption, steamProduction, waterProduction
Vs
def boiler_math():     pressure = uf.selectFromList(["LP", "HP"])     boilerSize = uf.selectFromList(boilerVars['Shape'].tolist())     timeFrame = "hour"                                              #uf.selectFromList(timeTicks.index.to_list())     fuelType = uf.selectFromList(ovenProd.index.to_list())     numBoilers = 1                                                  #int(input("How many boilers?"))     numWater = int(input("How many water tanks?"))     numOvens = int(input("How many coke ovens?"))     rainMod = 0.8                                                   #float(input("What is the rain modifier?"))     solidWater, solidSteam, waterProd = boiler_vars(boilerSize, timeFrame, fuelType, numBoilers, numWater, numOvens,rainMod, pressure)     liquidWater, liquidSteam, waterProd = boiler_vars(boilerSize, timeFrame, 'creosote', numBoilers, numWater, numOvens,rainMod, pressure)     totalWater = waterProd-(solidWater+liquidWater)     totalSteam = solidSteam+liquidSteam     print("Total Water Difference: " + str(totalWater) + " Total Steam Production: " + str(totalSteam)) def boiler_vars(boilerSize, timeFrame, fuelType, numBoilers, numWater, numOvens, rainMod, pressure):     tanks = boilerVars.loc[boilerVars['Shape'] == boilerSize, 'Size'].iloc[0]     lpMod = boilerVars.loc[boilerVars['Shape'] == boilerSize, pressure].iloc[0]     numTicks = timeTicks.loc[timeFrame]     burnTime = fuelTimes.loc[fuelType]     fuelConsumption = lpMod*numTicks/burnTime*numBoilers     steamProduction = tanks*numTicks*10*numBoilers     waterConsumption = steamProduction/150     ovenProduction = ovenProd.loc[fuelType]*numTicks*numOvens     waterProduction = numWater*rainMod*1.25*numTicks     fuelDifference = ovenProduction-fuelConsumption     waterDifference = waterProduction-waterConsumption     print("For " + fuelType + " use")     print("Fuel Difference: " + str(fuelDifference) + " Water Difference: " + str(waterDifference) + " Steam Production: " + str(steamProduction))     return waterConsumption, steamProduction, waterProduction
1 note · View note