Created
November 7, 2013 16:05
-
-
Save m0r13/7357103 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/env python | |
import cStringIO | |
import numpy | |
import shutil | |
import sys | |
from pymclevel import nbt, regionfile | |
if __name__ == "__main__": | |
if len(sys.argv) < 4: | |
print "Usage: ./merge_regions.py out.mca in.1.mca in.2.mca ... in.N.mca" | |
sys.exit(1) | |
shutil.copy(sys.argv[2], sys.argv[1]) | |
print "opening", sys.argv[1] | |
region1 = regionfile.MCRegionFile(sys.argv[1], (0, 0)) | |
chunks = [ None for i in xrange(1024) ] | |
for x in xrange(32): | |
for z in xrange(32): | |
if not region1.containsChunk(x, z): | |
continue | |
data = region1.readChunk(x, z) | |
chunks[x+z*32] = nbt._load_buffer(data) | |
sections = chunks[x+z*32]["Level"]["Sections"] | |
for section in sections: | |
# remove the highest section | |
if section["Y"].value == 15: | |
sections.remove(section) | |
break | |
#print chunks[x+z*32] | |
sections_diff = 0 | |
for filename in sys.argv[3:]: | |
print "adding", filename | |
region = regionfile.MCRegionFile(filename, (0, 0)) | |
sections_diff += 12 | |
for x in xrange(32): | |
for z in xrange(32): | |
if not region.containsChunk(x, z) or chunks[x+z*32] is None: | |
continue | |
chunk = chunks[x+z*32] | |
other_chunk = nbt._load_buffer(region.readChunk(x, z)) | |
for section in other_chunk["Level"]["Sections"]: | |
# remove the highest section, except of the last layer | |
if filename != sys.argv[-1] and section["Y"].value == 15: | |
continue | |
# remove the first three sections | |
if section["Y"].value < 3: | |
continue | |
section["Y"].value += sections_diff | |
chunk["Level"]["Sections"].append(section) | |
updated = 0 | |
for x in xrange(32): | |
for z in xrange(32): | |
if chunks[x+z*32] is None: | |
continue | |
updated += 1 | |
buf = cStringIO.StringIO() | |
chunks[x+z*32].save(buf, False) | |
region1.saveChunk(x, z, buf.getvalue()) | |
#print "updated:", updated | |
region1.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment