-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add optional conversion to MineClone2, along with a few related fixes.
- Loading branch information
1 parent
3553351
commit 6a52293
Showing
7 changed files
with
2,235 additions
and
21 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
|
||
def preprocess(lines, flags): | ||
output = [] | ||
skip_level = 0 | ||
for line in lines: | ||
line = line.split("//")[0].strip() # Remove comment | ||
if line == "": | ||
continue | ||
if line[0] == "#": | ||
if line.startswith("#ifdef"): | ||
cond = line[7:].strip() | ||
if skip_level > 0 or cond not in flags: | ||
skip_level += 1 | ||
elif line.startswith("#else"): | ||
if skip_level == 0: | ||
skip_level = 1 | ||
elif skip_level == 1: | ||
skip_level = 0 | ||
elif line.startswith("#endif"): | ||
if skip_level > 0: | ||
skip_level -= 1 | ||
continue | ||
if skip_level == 0: | ||
output.append(line) | ||
return output | ||
|
||
def get_id(name_id_mapping, name): | ||
try: | ||
# if the name of the node is known then return the location with the name_id_mapping list | ||
return name_id_mapping.index(name) | ||
except: | ||
# else add the name of the node to the list then return the location | ||
name_id_mapping.append(name) | ||
return len(name_id_mapping)-1 | ||
|
||
def read_content(flags): | ||
with open("mcl2_map_content.txt", "r") as f: | ||
lines = f.readlines() | ||
|
||
lines = preprocess(lines, flags) | ||
# if you map to air, then unknown blocks will be ignored | ||
name_id_mapping = ["air"] | ||
# name_id_mapping = ["mcblock:unknown"] | ||
bd = {} # bd is block data, and keeps a list of the node names in the block | ||
# iterate through all the lines in the map_content.txt file | ||
for line in lines: | ||
s = line.split("\t") | ||
if len(s) >= 2: | ||
r = s[1].split(" ") | ||
if len(r) == 0: | ||
print(line) | ||
raise ValueError("Malformed data") | ||
name = r[0] | ||
param2 = 0 | ||
for i in range(1, len(r)): | ||
if r[i] != "": | ||
param2 = int(r[i]) | ||
break | ||
t = s[0].split(" ") | ||
if len(t) == 2: | ||
for data in t[1].split(","): | ||
key = (int(t[0]), int(data)) | ||
if key not in bd: | ||
bd[key] = (get_id(name_id_mapping, name), param2) | ||
elif len(t) == 1: | ||
for data in range(16): | ||
key = (int(t[0]), data) | ||
if key not in bd: | ||
bd[key] = (get_id(name_id_mapping, name), param2) | ||
|
||
#blocks_len = max([i[0] for i in bd.keys()])+1 | ||
blocks_len = 4096 | ||
blocks = [[(0, 0)]*16 for i in range(blocks_len)] | ||
for (id, data), value in bd.items(): | ||
blocks[id][data] = value | ||
return name_id_mapping, blocks |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/bin/env python | ||
|
||
import os | ||
import stat | ||
import sys | ||
import logging | ||
from block import * | ||
import content_mcl2 | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
|
||
if (sys.version_info < (3, 0)): | ||
print("This script does not work with Python < 3.0, sorry.") | ||
exit(1) | ||
|
||
if not os.path.exists(sys.argv[1]): | ||
print("The provided minecraft world path does not exist.") | ||
exit(1) | ||
|
||
if not os.path.exists(sys.argv[2]): | ||
os.makedirs(sys.argv[2]) | ||
|
||
if os.path.exists(sys.argv[2] + "map.sqlite"): | ||
print("A minetest world already exists - refusing to overwrite it.") | ||
exit(1) | ||
|
||
if not os.path.exists(sys.argv[2] + "/world.mt"): | ||
with open(sys.argv[2] + "/world.mt", "w") as wo: | ||
wo.write("backend = sqlite3\n") | ||
wo.write("gameid = MineClone2\n") | ||
|
||
if not os.path.exists(sys.argv[2] + "/worldmods"): | ||
os.makedirs(sys.argv[2]+"/worldmods") | ||
if not os.path.exists(sys.argv[2] + "/worldmods/mcimport"): | ||
os.makedirs(sys.argv[2]+"/worldmods/mcimport") | ||
if not os.path.exists(sys.argv[2]+"/worldmods/mcimport/init.lua"): | ||
with open(sys.argv[2]+"/worldmods/mcimport/init.lua", "w") as sn: | ||
sn.write("-- map conversion requires a special water level\n") | ||
sn.write("minetest.set_mapgen_params({water_level = -2})\n\n") | ||
sn.write("-- prevent overgeneration in incomplete chunks, and allow lbms to work\n") | ||
sn.write("minetest.set_mapgen_params({chunksize = 1})\n\n") | ||
sn.write("-- comment the line below if you want to enable mapgen (will destroy things!)\n") | ||
sn.write("minetest.set_mapgen_params({mgname = \"singlenode\"})\n\n") | ||
sn.write("-- below lines will recalculate lighting on map block load\n") | ||
sn.write("minetest.register_on_generated(function(minp, maxp, seed)\n") | ||
sn.write(" local vm = minetest.get_voxel_manip(minp, maxp)\n") | ||
sn.write(" vm:set_lighting({day = 15, night = 0}, minp, maxp)\n") | ||
sn.write(" vm:update_liquids()\n") | ||
sn.write(" vm:write_to_map()\n") | ||
sn.write(" vm:update_map()\n") | ||
sn.write("end)\n\n") | ||
|
||
|
||
mcmap = MCMap(sys.argv[1]) | ||
mtmap = MTMap(sys.argv[2]) | ||
|
||
nimap, ct = content_mcl2.read_content(["NETHER", "QUARTZ"]) | ||
mtmap.fromMCMap(mcmap, nimap, ct) | ||
mtmap.save() | ||
|
||
print("Conversion finished!\n") | ||
print("Please enjoy your new MineClone2 world!") | ||
|
Oops, something went wrong.