Last active
October 18, 2015 10:11
-
-
Save ObKo/5c8e276b6fdc04c6b9d0 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python3 | |
# To use this script, | |
# - Prepare modpack, so no id will be changed in future. | |
# - Install MetaDump mod - http://unmined.intro.hu/metadump | |
# - Run minecraft. MetaDump will flood .minecraft folder with JSON dumps, we need metadump-blocks-1.7.10-gregtech-MC1710.json | |
# - 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) | |
# - Prepare WorldGeneration.cfg template (template for GT 5.09.08 - http://pastebin.com/zR250y3S: | |
# - set all default ore generation to false | |
# - Place @AMOUNT@ instead of I:AmountOfCustomLargeVeinSlots_16 / I:AmountOfCustomSmallOreSlots_16 | |
# - Place @ENABLE_MIX@ instead of B:ore.mix.custom.*_false=false lines | |
# - Place @ENABLE_SMALL@ instead of B:ore.small.custom.*_false=false lines | |
# - Place @GEN_SMALL@ instead of content of ore/small/custom section | |
# - Place @GEN_MIX@ instead of content of ore/mix/custom section | |
# - Place @DIM_MIX@ instead of content of dimensions/ore/mix/custom section | |
# - Place @DIM_SMALL@ instead of content of dimensions/ore/small/custom section | |
# - ./gen-cfg.py metadump-blocks-1.7.10-gregtech-MC1710.json template.cfg small.csv mix.csv | |
import sys, re | |
import json | |
oreMap = {} | |
SMALL_ORE_DEF_TEMPLATE = """ | |
{o.number:02} {{ | |
I:Amount_0={o.amount} | |
B:Asteroid_false={d[6]} | |
B:EndAsteroid_false={d[2]} | |
B:Mars_false={d[5]} | |
I:MaxHeight_0={o.maxHeight} | |
I:MinHeight_0={o.minHeight} | |
B:Moon_false={d[4]} | |
B:Nether_false=false | |
I:Ore_-1={o.name} | |
B:Overworld_false=false | |
B:TheEnd_false=false | |
}}""" | |
MIX_ORE_DEF_TEMPLATE = """ | |
{o.number:02} {{ | |
B:Asteroid_false={d[6]} | |
I:Density_0={o.density} | |
B:EndAsteroid_false={d[2]} | |
B:Mars_false={d[5]} | |
I:MaxHeight_0={o.maxHeight} | |
I:MinHeight_0={o.minHeight} | |
B:Moon_false={d[4]} | |
B:Nether_false=false | |
I:OrePrimaryLayer_-1={o.primary} | |
I:OreSecondaryLayer_-1={o.secondary} | |
I:OreSporadiclyInbetween_-1={o.inbetween} | |
I:OreSporaticlyAround_-1={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:02} {{ | |
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[4]} | |
B:planet.asteroids_false={d[6]} | |
B:planet.mars_false={d[5]} | |
}}""" | |
ORE_HEIGHT_REGEX = "(\d+)\s*-\s*(\d+)\s*\((\d+)\)" | |
AMOUNT_TEMPLATE = """I:AmountOfCustomLargeVeinSlots_16={mixCount} | |
I:AmountOfCustomSmallOreSlots_16={smallCount}""" | |
ENABLE_MIX_TEMPLATE = " B:ore.mix.custom.{id:02}_false=true" | |
ENABLE_SMALL_TEMPLATE = " B:ore.small.custom.{id:02}_false=true" | |
def name2id(name): | |
if not (name in oreMap): | |
print("Can't find id for ore \"" + name + "\"") | |
return -1 | |
else: | |
return oreMap[name] | |
class SmallOre: | |
def __init__(self, number, dim, name, string): | |
self.name = name2id(name) | |
self.number = number | |
self.dim = ["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, d = self.dim) | |
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"] | |
self.dim[dim] = "true" | |
self.primary = name2id(primary) | |
self.secondary = name2id(secondary) | |
self.inbetween = name2id(inbetween) | |
self.around = name2id(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, d = self.dim) | |
def dim_str(self): | |
return ORE_DIM_TEMPLATE.format(o = self, d = self.dim) | |
with open(sys.argv[1]) as metaFile: | |
metaData = json.load(metaFile) | |
oreBlocks = [] | |
for block in metaData["Blocks"]: | |
if block["Name"] == "gregtech:gt.blockores": | |
print("Found GT ores block: " + str(block["Id"])) | |
oreBlocks = block["SubBlocks"] | |
if len(oreBlocks) == 0: | |
print("Can't parse GT ore ids!") | |
sys.exit() | |
for block in oreBlocks: | |
if block["ItemDamage"] < 1000: | |
# Remove " Ore" from name | |
name = block["DisplayName"] | |
if name[len(name)-4:] == " Ore": | |
name = name[:-4] | |
oreMap[name] = block["ItemDamage"] | |
print(name + " = " + str(block["ItemDamage"])) | |
sores = [] | |
mores = [] | |
template = open(sys.argv[2]).read() | |
f = open(sys.argv[3]) | |
number = 0 | |
for line in f: | |
arr = line.split(";") | |
#name = arr[0].replace(" ", "") | |
name = arr[0].strip() | |
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[4]) | |
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() | |
primary = arr[3] | |
secondary = arr[4].strip() | |
inbetween = arr[5].strip() | |
around = arr[6].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 | |
amountStr = AMOUNT_TEMPLATE.format(mixCount = len(mores), smallCount = len(sores)) | |
smallEnableStr = [] | |
for i in range(0, len(sores)): | |
smallEnableStr.append(ENABLE_SMALL_TEMPLATE.format(id = i)) | |
mixEnableStr = [] | |
for i in range(0, len(mores)): | |
mixEnableStr.append(ENABLE_MIX_TEMPLATE.format(id = i)) | |
smallEnableStr.sort() | |
mixEnableStr.sort() | |
smallGenStr = [] | |
smallDimStr = [] | |
for o in sores: | |
smallGenStr.append(str(o)) | |
smallDimStr.append(o.dim_str()) | |
mixGenStr = [] | |
mixDimStr = [] | |
for o in mores: | |
mixGenStr.append(str(o)) | |
mixDimStr.append(o.dim_str()) | |
f = open("WorldGeneration.cfg", "w") | |
template = template.replace("@AMOUNT@", amountStr) | |
template = template.replace("@ENABLE_SMALL@", "\n".join(smallEnableStr)) | |
template = template.replace("@ENABLE_MIX@", "\n".join(mixEnableStr)) | |
template = template.replace("@GEN_SMALL@", "\n".join(smallGenStr)) | |
template = template.replace("@GEN_MIX@", "\n".join(mixGenStr)) | |
template = template.replace("@DIM_SMALL@", "\n".join(smallDimStr)) | |
template = template.replace("@DIM_MIX@", "\n".join(mixDimStr)) | |
f.write(template) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment