Skip to content

Instantly share code, notes, and snippets.

@skairunner
Created January 14, 2016 18:45
Show Gist options
  • Save skairunner/0d259c9e75ffbca3094e to your computer and use it in GitHub Desktop.
Save skairunner/0d259c9e75ffbca3094e to your computer and use it in GitHub Desktop.
minecraft recipe calculator
#
# Minecraft Recipe Calculator
# by Skyyrunner (fluffyterran at gmail dot com)
#
import json
import fractions
from pprint import pprint
import sys
data = json.loads(open(sys.argv[1]).read())
basicingredients = data["BasicIngredients"]
processing = data["Processing"]
recipes = data["Recipes"]
# preprocessing: eg, "ingredient": "2/3" should be converted into a fraction
for r in recipes:
recipe = recipes[r]
for item in recipe:
if type(recipe[item]) == str:
recipe[item] = fractions.Fraction(recipe[item])
# for performance, should cache multi-step recipes.
memo = {}
# return required inputs
def calculate(item):
if item in basicingredients:
return {item: 1}
if item in memo:
return memo[item]
required = {}
for ing in recipes[item]:
if "processing::" in ing:
proc = ing.split("::")[-1]
if proc in processing:
try:
required[ing] += recipes[item][ing]
except:
required[ing] = recipes[item][ing]
else:
raise KeyError("%s not in processing methods" % proc)
else:
num = recipes[item][ing]
needed = calculate(ing)
for thing in needed:
try:
required[thing] += needed[thing] * num
except:
required[thing] = needed[thing] * num
memo[item] = required
return required
import math
markdown = True
def prettyprint(recipe):
recipe = sorted(recipe, key=lambda x: x[1], reverse=True)
processes = []
for i in recipe:
if "processing::" in i[0]:
processes.append((i[0].split("::")[-1], i[1]))
else:
if markdown:
print(" %s: %d" % (i[0].rjust(25), math.ceil(i[1])))
else:
print("%s: %d" % (i[0].rjust(25), math.ceil(i[1])))
if len(processes):
print("Processing required:")
for proc in processes:
if markdown:
print(" %s: %d operations" % (proc[0].rjust(25), math.ceil(proc[1])))
else:
print("%s: %d operations" % (proc[0].rjust(25), math.ceil(proc[1])))
def excelprint(recipe):
recipe = sorted(recipe, key=lambda x: x[1], reverse=True)
for i in recipe:
print("%s\\t%d" % (i[0], math.ceil(i[1])))
recipe = calculate(sys.argv[2]).items()
prettyprint(recipe)
{
"BasicIngredients": ["pulverized tin", "pulverized silver", "glowstone dust",
"RF", "diamond", "ghast tear", "blaze powder", "slimeball", "ender pearl",
"mushroom", "sugar", "spider eye", "pulverized iron", "obsidian", "purified crushed uranium",
"plutonium_alt", "emerald", "sulfur", "electrotine", "coal", "pulverized shiny metal",
"pulverized lead", "redstone", "iridium dust", "terrasteel ingot", "void metal ingot",
"cobblestone", "manasteel ingot", "thaumium ingot", "nether star", "pulverized gold",
"draconium dust", "awakened draconium ingot", "dragon heart", "uranium dust",
"lapis lazuli", "flint", "water", "glass", "pulverized copper", "raw rubber",
"cobblestone"],
"Processing": ["furnace", "magma crucible", "compressor", "metal former",
"thermal centrifuge", "canning machine", "ic2 reactor", "fluid transposer"
, "pulverizer", "TE induction smelter", "alloy smelter", "smeltery pouring",
"ritual of awakening", "assembly table", "molecular transformer", "carpenter",
"thermonic fabricator"],
"Recipes": {
"creative energy cell": {
"lumium block": 4,
"enhanced galgadorian block": 28,
"pellet of rtg fuel": 8,
"resonant energy cell frame (full)": 16,
"draconic flux capacitor": 16,
"quantum solar panel": 9
},
"EU": {
"RF": 4
},
"lumium block": {
"lumium ingot": 9
},
"lumium ingot": {
"lumium blend": 1,
"processing::furnace": 1
},
"lumium blend": {
"pulverized tin": "3/4",
"pulverized silver": "1/4",
"energized glowstone": 250
},
"energized glowstone": {
"glowstone dust": "1/250",
"RF": "20000/250",
"processing::magma crucible": "1/250"
},
"enhanced galgadorian block": {
"enhanced galgadorian metal": 9
},
"enhanced galgadorian metal": {
"large lump of galgador": 1,
"processing::furnace": "0.5"
},
"large lump of galgador": {
"lump of galgador": 9
},
"lump of galgador": {
"glowstone dust": "1.5",
"block of diamond": "0.5",
"eye of galgador": "1.5",
"stabilized metal": 1
},
"block of diamond": {
"diamond": 9
},
"eye of galgador": {
"magma cream": 4,
"ghast tear": 2,
"eye of ender": 1,
"fermented spider eye": 2
},
"eye of ender": {
"ender pearl": 1,
"blaze powder": 1
},
"magma cream": {
"blaze powder": 1,
"ender pearl": 1
},
"fermented spider eye": {
"mushroom": 1,
"sugar": 1,
"spider eye": 1
},
"stabilized metal": {
"iron ingot": 1,
"hardened mesh": "1/5",
"refined hardener": "3/5"
},
"iron ingot": {
"pulverized iron": 1,
"processing::furnace": 1
},
"hardened mesh": {
"iron bars": 5,
"refined hardener": 4
},
"iron bars": {
"iron ingot": "6/16"
},
"refined hardener": {
"raw hardener": 1,
"processing::furnace": 1
},
"raw hardener": {
"obsidian": 2,
"diamond": "1/2"
},
"pellet of rtg fuel": {
"dense iron plate": 6,
"plutonium": 3
},
"dense iron plate": {
"iron plate": 9,
"processing::compressor": 1,
"EU": 512
},
"iron plate": {
"iron ingot": 1,
"processing::metal former": 1,
"EU": 2048
},
"plutonium": {
"tiny pile of plutonium": 9
},
"tiny pile of plutonium": {
"fuel rod (depleted mox)": "1/28",
"EU": "22016/28",
"processing::thermal centrifuge": "1/28"
},
"thermal centrifuge heatup": {
"EU": 7680
},
"fuel rod (depleted mox)": {
"fuel rod (mox)": 1,
"processing::ic2 reactor": 1
},
"fuel rod (mox)": {
"mox nuclear fuel": 1,
"fuel rod (empty)": 1,
"processing::canning machine": 1
},
"fuel rod (empty)": {
"iron plate": 1,
"processing::metal former": 1,
"EU": 2016
},
"tiny pile of uranium": {
"purified crushed uranium": "1/47",
"processing::thermal centrifuge": "1/47",
"EU": "22016/47"
},
"uranium": {
"tiny pile of uranium": 9
},
"mox nuclear fuel": {
"plutonium_alt": 3,
"uranium": 6
},
"resonant energy cell frame (full)": {
"resonant energy cell frame (empty)": 1,
"destabilized redstone": 4000,
"RF": 16000,
"processing::fluid transposer": 1
},
"resonant energy cell frame (empty)": {
"emerald": 1,
"enderium ingot": 4,
"hardened glass": 4
},
"enderium ingot": {
"pyrotheum dust": "0.5",
"enderium blend": 1,
"RF": 4000,
"processing::TE induction smelter": "0.5"
},
"pyrotheum dust": {
"pulverized coal": 1,
"sulfur": 1,
"blaze powder": 1,
"electrotine": 1
},
"pulverized coal": {
"coal": 1,
"RF": 2400,
"processing::pulverizer": 1
},
"enderium blend": {
"pulverized tin": "2/4",
"pulverized shiny metal": "1/4",
"pulverized silver": "1/4",
"resonant ender": 250
},
"resonant ender": {
"ender pearl": "1/250",
"RF": "1/20000",
"processing::magma crucible": "1/250"
},
"hardened glass": {
"pulverized obsidian": 2,
"pulverized lead": "0.5",
"processing::TE induction smelter": "0.5",
"RF": 2000
},
"pulverized obsidian": {
"obsidian": 1,
"RF": 1000,
"processing::pulverizer": "1/4"
},
"destabilized redstone": {
"redstone": "1/100",
"RF": "80",
"processing::magma crucible": "1/100"
},
"draconic flux capacitor": {
"awakened core": 1,
"awakened draconium ingot": 4,
"draconic energy core": 3,
"wyvern flux capacitor": 1,
"RF": 250000000
},
"awakened core": {
"wyvern core": 4,
"iridium ingot": 1,
"bedrockium ingot": 1,
"terrasteel ingot": 1,
"void metal ingot": 1,
"awakened draconium block": 1
},
"iridium ingot": {
"iridium dust": 1,
"processing::furnace": 1
},
"bedrockium ingot": {
"mox nuclear fuel": 1,
"processing::furnace": 1
},
"wyvern core": {
"draconic core": 4,
"fluxed electrum ingot": 1,
"vibrant alloy": 1,
"manasteel ingot": 1,
"thaumium ingot": 1,
"nether star": 1
},
"draconic core": {
"diamond": 1,
"gold ingot": 4,
"draconium ingot": 4
},
"gold ingot": {
"pulverized gold": 1,
"processing::furnace": 1
},
"draconium ingot": {
"draconium dust": 1,
"processing::furnace": 1
},
"fluxed electrum ingot": {
"pyrotheum dust": "0.5",
"fluxed electrum blend": 1,
"processing::TE induction smelter": "0.5",
"RF": 4000
},
"fluxed electrum blend": {
"electrum blend": 1,
"destabilized redstone": 200,
"processing::fluid transposer": 1
},
"vibrant alloy": {
"energetic alloy": 1,
"ender pearl": 1,
"RF": 10000,
"processing::alloy smelter": 1
},
"energetic alloy": {
"glowstone dust": 1,
"redstone": 1,
"gold ingot": 1,
"processing::alloy smelter": 1,
"RF": 10000
},
"draconic energy core": {
"awakened core": 1,
"molten draconium": 5184,
"processing::smeltery pouring": 1
},
"molten draconium": {
"draconium dust": "1/144"
},
"wyvern flux capacitor": {
"wyvern energy core": 4,
"wyvern core": 1,
"draconium ingot": 4
},
"wyvern energy core": {
"wyvern core": 1,
"destabilized redstone": 7200,
"processing::smeltery pouring": 1
},
"awakened draconium ingot": {
"awakened draconium block": "1/9"
},
"awakened draconium block": {
"dragon heart": "1/4",
"draconic core": 4,
"charged draconium block": 1,
"processing::ritual of awakening": "1/4"
},
"charged draconium block": {
"RF": 100000000
},
"draconium block": {
"draconium ingot": 9
},
"electrum blend": {
"pulverized gold": "0.5",
"pulverized silver": "0.5"
},
"quantum solar panel": {
"ultimate hybrid solar panel": 8,
"quantum core": 1
},
"quantum core": {
"eye of ender": 1,
"nether star": 4,
"enriched sunnarium alloy": 4
},
"enriched sunnarium alloy": {
"enriched sunnarium": 4,
"sunnarium alloy": 1
},
"enriched sunnarium": {
"irradiant uranium": 8,
"sunnarium": 1
},
"irradiant uranium": {
"uranium ingot": 1,
"glowstone dust": 4,
"RF": 100000,
"processing::assembly table": 1
},
"uranium ingot": {
"uranium dust": 1,
"processing::furnace": 1
},
"sunnarium": {
"glowstone dust": 4,
"EU": 9000000,
"processing::molecular transformer": 1
},
"sunnarium alloy": {
"iridium reinforced plate": 8,
"sunnarium": 1
},
"iridium reinforced plate": {
"advanced alloy": 4,
"iridium ore": 4,
"diamond": 1
},
"iridium ore": {
"pellet of rtg fuel": 1,
"mox nuclear fuel": 1,
"RF": 80000000,
"processing::assembly table": 1
},
"advanced alloy": {
"mixed metal ingot": 1,
"processing::compressor": 1,
"EU": 512
},
"mixed metal ingot": {
"iron plate": 3,
"bronze plate": 3,
"tin plate": 3
},
"bronze plate": {
"bronze ingot": 1,
"processing::compressor": 1,
"EU": 512
},
"bronze ingot": {
"tin ingot": "1/4",
"copper ingot": "3/4",
"processing::alloy smelter": "1/4",
"RF": 4000
},
"tin ingot": {
"pulverized tin": 1,
"processing::furnace": 1
},
"copper ingot": {
"pulverized copper": 1,
"processing::furnace": 1
},
"tin plate": {
"tin ingot": 1,
"processing::compressor": 1,
"EU": 512
},
"bronze plate": {
"bronze ingot": 1,
"processing::compressor": 1,
"EU": 512
},
"ultimate hybrid solar panel": {
"lapis lazuli block": 1,
"coal chunk": 3,
"enriched sunnarium alloy": 2,
"advanced solar panel": 1
},
"ultimate hybrid solar panel (alt)": {
"hybrid solar panel": 8,
"advanced circuit": 1
},
"lapis lazuli block": {
"lapis lazuli": 9
},
"coal chunk": {
"obsidian": 1,
"compressed coal ball": 8
},
"compressed coal ball": {
"coal ball": 1,
"processing::compressor": 1,
"EU": 512
},
"coal ball": {
"pulverized coal": 8,
"flint": 1
},
"advanced solar panel": {
"irradiant glass": 3,
"advanced alloy": 2,
"advanced circuit": 2,
"irradiant reinforced plate": 1,
"solar panel": 1
},
"irradiant glass": {
"reinforced glass": 1,
"irradiant uranium": "2/6",
"glowstone dust": "1/6"
},
"irradiant reinforced plate": {
"sunnarium piece": 1,
"redstone": 4,
"lapis lazuli": 2,
"diamond": 1,
"reinforced iridium-iron plate": 1
},
"sunnarium piece": {
"glowstone dust": 1,
"processing::molecular transformer": 1,
"EU": 1000000
},
"reinforced iridium-iron plate": {
"advanced alloy": 4,
"iridium-iron plate": 1,
"carbon plate": 4
},
"iridium-iron plate": {
"iron ingot": 8,
"iridium ingot": 1
},
"carbon plate": {
"raw carbon mesh": 1,
"processing::compressor": 1,
"EU": 512
},
"raw carbon mesh": {
"raw carbon fibre": 2
},
"raw carbon fibre": {
"pulverized coal": 4
},
"advanced circuit": {
"redstone chipset": 4,
"intricate circuit board": 2,
"basic capacitor": 2
},
"redstone chipset": {
"redstone": 1,
"processing::assembly table": 1,
"RF": 100000
},
"intricate circuit board": {
"processing::carpenter": 1,
"redstone": 6,
"gold ingot": 3,
"water": 1000
},
"basic capacitor": {
"signalum nugget": 4,
"redstone chipset": 2,
"lapis electron tube": 1
},
"signalum ingot": {
"bronze ingot": "3/4",
"silver ingot": "1/4",
"redstone": "10/4",
"RF": 32000,
"processing::alloy smelter": "1/4"
},
"lapis electron tube": {
"processing::thermonic fabricator": "1/4",
"glass": "1/8",
"lapis lazuli": "5/4",
"redstone": "2/4"
},
"signalum nugget": {
"signalum ingot": "1/9"
},
"solar panel": {
"glass": 3,
"pulverized coal": 3,
"electronic circuit": 2,
"generator": 1
},
"electronic circuit": {
"insulated copper wire": 6,
"redstone": 2,
"iron plate": 1
},
"insulated copper wire": {
"rubber bar": 1,
"copper cable": 1
},
"copper cable": {
"copper ingot": "1/3",
"processing::metal former": "1/3",
"EU": "2048/3"
},
"rubber bar": {
"raw rubber": 1,
"processing::furnace": 1
},
"copper ingot": {
"pulverized copper": 1,
"processing::furnace": 1
},
"generator": {
"iron furnace": 1,
"re-battery": 1,
"iron plate": 3
},
"iron furnace": {
"iron plate": 5,
"furnace": 1
},
"furnace": {
"cobblestone": 72
},
"re-battery": {
"insulated tin cable": 1,
"tin item casing": 4,
"electrotine": 2
},
"insulated tin cable": {
"rubber bar": 1,
"tin cable": 1
},
"tin cable": {
"tin ingot": "1/3",
"processing::metal former": "1/3",
"EU": "2048/3"
},
"tin item casing": {
"tin plate": "1/2",
"processing::metal former": "1/2",
"EU": 2048
},
"silver ingot": {
"pulverized silver": 1,
"processing::furnace": 1
},
"reinforced glass": {
"glass": 7,
"advanced alloy": "2/7"
},
"hybrid solar panel": {
"carbon plate": 2,
"lapis lazuli block": 1,
"iridium reinforced plate": 2,
"advanced solar panel": 1,
"advanced circuit": 2,
"enriched sunnarium": 1
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment