Skip to content

Instantly share code, notes, and snippets.

@ObKo
Last active September 1, 2015 17:58
Show Gist options
  • Save ObKo/8a23afaa7463d2ad2458 to your computer and use it in GitHub Desktop.
Save ObKo/8a23afaa7463d2ad2458 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
# To use this script,
# - remove all lines except data lines for small ores and save it as .csv with ";" separator (e.g. small.csv)
# - remove all lines except data lines for mix ores and save it as .csv with ";" separator (e.g. mix.csv)
# - ./gen-cfg.py small.csv mix.csv
# - Script should create 4 files: small.cfg mix.cfg small_dim.cfg mix_dim.cfg
# - Copy small.cfg into worldgen { ore { small { custom { } } } } and rename id from 1 to 9 (1 -> 01 2 -> 02) (I'm so lazy...)
# - Copy small_dim.cfg into worldgen { dimensions { ore { small { custom { } } } } } and rename id from 1 to 9 (1 -> 01 2 -> 02)
# - Copy mix.cfg into worldgen { ore { mix { custom { } } } } and rename id from 1 to 9 (1 -> 01 2 -> 02) (I'm so lazy...)
# - Copy mix_dim.cfg into worldgen { dimensions { ore { mix { custom { } } } } } and rename id from 1 to 9 (1 -> 01 2 -> 02)
# - Adjust I:AmountOfCustomLargeVeinSlots_16 / I:AmountOfCustomSmallOreSlots_16
# - Add B:ore.mix.custom.xx_false=true into worldgen (GT will auto-generate those, but with =false)
import sys, re
SMALL_ORE_DEF_TEMPLATE = """
{o.number} {{
I:Amount_0={o.amount}
B:Mars_false=false
I:MaxHeight_0={o.maxHeight}
I:MinHeight_0={o.minHeight}
B:Moon_false=false
B:Nether_false=false
S:Ore_NULL={o.name}
B:Overworld_false=false
B:TheEnd_false=false
}}"""
MIX_ORE_DEF_TEMPLATE = """
{o.number} {{
B:Asteroid_false=false
I:Density_0={o.density}
B:EndAsteroid_false=false
B:Mars_false=false
I:MaxHeight_0={o.maxHeight}
I:MinHeight_0={o.minHeight}
B:Moon_false=false
B:Nether_false=false
S:OrePrimaryLayer_NULL={o.primary}
S:OreSecondaryLayer_NULL={o.secondary}
S:OreSporadiclyInbetween_NULL={o.inbetween}
S:OreSporaticlyAround_NULL={o.around}
B:Overworld_false=false
I:RandomWeight_0={o.weight}
I:Size_0={o.size}
B:TheEnd_false=false
}}"""
ORE_DIM_TEMPLATE = """
{o.number} {{
B:Caves_false={d[4]}
B:Nether_false={d[1]}
B:Overworld_false={d[0]}
B:The_End_false={d[2]}
B:Twilight_Forest_false={d[3]}
B:moon.moon_false={d[5]}
B:planet.asteroids_false={d[7]}
B:planet.mars_false={d[6]}
}}"""
ORE_HEIGHT_REGEX = "(\d+)\s*-\s*(\d+)\s*\((\d+)\)"
class SmallOre:
def __init__(self, number, dim, name, string):
self.name = name
self.number = number
self.dim = ["false", "false", "false", "false", "false", "false", "false", "false"]
self.dim[dim] = "true"
m = re.match(ORE_HEIGHT_REGEX, string)
if m != None:
self.minHeight = int(m.group(1))
self.maxHeight = int(m.group(2))
self.amount = int(m.group(3))
def __str__(self):
return SMALL_ORE_DEF_TEMPLATE.format(o = self)
def dim_str(self):
return ORE_DIM_TEMPLATE.format(o = self, d = self.dim)
class MixOre:
def __init__(self, number, dim, primary, secondary, inbetween, around, size, density, string):
self.number = number
self.dim = ["false", "false", "false", "false", "false", "false", "false", "false"]
self.dim[dim] = "true"
self.primary = primary
self.secondary = secondary
self.inbetween = inbetween
self.around = around
self.size = size
self.density = density
m = re.match(ORE_HEIGHT_REGEX, string)
if m != None:
self.minHeight = int(m.group(1))
self.maxHeight = int(m.group(2))
self.weight = int(m.group(3))
else:
print(string)
def __str__(self):
return MIX_ORE_DEF_TEMPLATE.format(o = self)
def dim_str(self):
return ORE_DIM_TEMPLATE.format(o = self, d = self.dim)
sores = []
mores = []
f = open(sys.argv[1])
number = 0
for line in f:
arr = line.split(";")
name = arr[0].replace(" ", "")
arr = arr[1:]
dim = 0
for s in arr:
s = s.strip()
if s != "":
sores.append(SmallOre(number, dim, name, s))
number = number + 1
dim = dim + 1
f = open(sys.argv[2])
number = 0
for line in f:
arr = line.split(";")
size = int(arr[1])
density = int(arr[2])
primary = arr[3].replace(" ", "").strip()
secondary = arr[4].replace(" ", "").strip()
inbetween = arr[5].replace(" ", "").strip()
around = arr[6].replace(" ", "").strip()
arr = arr[7:]
dim = 0
for s in arr:
s = s.strip()
if s != "":
mores.append(MixOre(number, dim, primary, secondary, inbetween, around, size, density, s))
number = number + 1
dim = dim + 1
f = open("small.cfg", "w")
for o in sores:
f.write(str(o) + "\n")
f = open("small_dim.cfg", "w")
for o in sores:
f.write(o.dim_str() + "\n")
f = open("mix.cfg", "w")
for o in mores:
f.write(str(o) + "\n")
f = open("mix_dim.cfg", "w")
for o in mores:
f.write(o.dim_str() + "\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment