forked from minetest-tools/mcimport
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mcimport.py
83 lines (71 loc) · 3.8 KB
/
mcimport.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/env python
import os
import stat
import sys
import logging
from block import *
import content
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 = minetest\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")
if not os.path.exists(sys.argv[2]+"/get-mods.sh"):
path = sys.argv[2]+"/get-mods.sh"
with open(path, "w") as md:
md.write("#!/bin/sh\n")
md.write("# run this script to automatically get all the required mods\n")
md.write("cd worldmods\n")
md.write("for mod in LNJ2/carpet minetest-mods/signs_lib minetest-mods/xdecor minetest-mods/plantlife_modpack Jeija/minetest-mod-mesecons pilzadam/nether minetest-mods/crops minetest-mods/quartz minetest-mods/biome_lib oOChainLynxOo/hardenedclay minetest-mods/lapis minetest-mods/flowerpot ShadowNinja/minetest_bedrock; do\n")
md.write(" echo \"Fetching: $mod\"\n")
md.write(" s=`basename $mod`\n")
md.write(" curl -q -L -o master.zip https://codeload.github.com/$mod/zip/master\n")
md.write(" unzip -qq master.zip\n")
md.write(" rm master.zip\n")
md.write(" mv $s-master $s\n")
md.write(" mv minetest_bedrock bedrock\n")
md.write("done\n")
md.write("for ex in plantlife_modpack/dryplants plantlife_modpack/along_shore plantlife_modpack/molehills plantlife_modpack/woodsoils plantlife_modpack/bushes plantlife_modpack/bushes_classic plantlife_modpack/youngtrees plantlife_modpack/3dmushrooms plantlife_modpack/cavestuff plantlife_modpack/poisonivy plantlife_modpack/trunks; do\n");
md.write(" echo \"Pruning: $ex\"\n")
md.write(" rm -rf $ex\n")
md.write("done\n")
st = os.stat(path)
os.chmod(path, st.st_mode | stat.S_IXUSR)
mcmap = MCMap(sys.argv[1])
mtmap = MTMap(sys.argv[2])
nimap, ct = content.read_content(["NETHER", "QUARTZ"])
mtmap.fromMCMap(mcmap, nimap, ct)
mtmap.save()
print("Conversion finished!\n")
print("Run \"sh get-mods.sh\" in the new world folder to automatically download all required mods.")