Ejemplo n.º 1
0
 def process_world(self, world_folder, randomSpawners):
         try:
                 world = WorldFolder(world_folder)
         except:
                 return
         for region in world.iter_regions():
                 print(region.filename)
                 chunk_moved = False
                 for chunk in region.iter_chunks():
                         if(self.randomize_Spawners(chunk["Level"], randomSpawners)):
                                 x=chunk["Level"]["xPos"].value
                                 z=chunk["Level"]["zPos"].value
                                 if x < 0:
                                         while x < 0:
                                                 x += 32
                                 elif x > 31:
                                         while x > 31:
                                                 x -= 32
                                 if z < 0:
                                         while z < 0:
                                                 z += 32
                                 elif z > 31:
                                         while z > 31:
                                                 z -= 32
                                         
                                 print("Updating apawners in chunk: x: "+str(x)+" z: "+str(z))
                                 try:
                                         #print("HERP")
                                         if(region.write_chunk(x,z,chunk)):
                                                 chunk_moved = True
                                         #print("DERP")
                                 except ValueError as e:
                                         print("ERROR:  Failed to update chunk.")
                                         print(e)
Ejemplo n.º 2
0
Archivo: map.py Proyecto: macfreek/NBT
def main(world_folder, show=True):
    world = WorldFolder(world_folder)
    bb = world.get_boundingbox()
    world_map = Image.new('RGB', (16*bb.lenx(),16*bb.lenz()))
    t = world.chunk_count()
    try:
        i =0.0
        for chunk in world.iter_chunks():
            if i % 50 ==0:
                sys.stdout.write("Rendering image")
            elif i % 2 == 0:
                sys.stdout.write(".")
                sys.stdout.flush()
            elif i % 50 == 49:
                sys.stdout.write("%5.1f%%\n" % (100*i/t))
            i +=1
            chunkmap = get_map(chunk)
            x,z = chunk.get_coords()
            world_map.paste(chunkmap, (16*(x-bb.minx),16*(z-bb.minz)))
        print(" done\n")
        filename = os.path.basename(world_folder)+".png"
        world_map.save(filename,"PNG")
        print("Saved map as %s" % filename)
    except KeyboardInterrupt:
        print(" aborted\n")
        filename = os.path.basename(world_folder)+".partial.png"
        world_map.save(filename,"PNG")
        print("Saved map as %s" % filename)
        return 75 # EX_TEMPFAIL
    if show:
        world_map.show()
    return 0 # NOERR
Ejemplo n.º 3
0
Archivo: map.py Proyecto: ylehir/NBT
def main(world_folder, show=True):
    world = WorldFolder(world_folder)
    bb = world.get_boundingbox()
    world_map = Image.new('RGB', (16 * bb.lenx(), 16 * bb.lenz()))
    t = world.chunk_count()
    try:
        i = 0.0
        for chunk in world.iter_chunks():
            if i % 50 == 0:
                sys.stdout.write("Rendering image")
            elif i % 2 == 0:
                sys.stdout.write(".")
                sys.stdout.flush()
            elif i % 50 == 49:
                sys.stdout.write("%5.1f%%\n" % (100 * i / t))
            i += 1
            chunkmap = get_map(chunk)
            x, z = chunk.get_coords()
            world_map.paste(chunkmap, (16 * (x - bb.minx), 16 * (z - bb.minz)))
        print(" done\n")
        filename = os.path.basename(world_folder) + ".png"
        world_map.save(filename, "PNG")
        print("Saved map as %s" % filename)
    except KeyboardInterrupt:
        print(" aborted\n")
        filename = os.path.basename(world_folder) + ".partial.png"
        world_map.save(filename, "PNG")
        print("Saved map as %s" % filename)
        return 75  # EX_TEMPFAIL
    if show:
        world_map.show()
    return 0  # NOERR
Ejemplo n.º 4
0
def main(world_folder):
    world = WorldFolder(world_folder)

    try:
        for chunk in world.iter_nbt():
            print_results(entities_per_chunk(chunk["Level"]))

    except KeyboardInterrupt:
        return 75  # EX_TEMPFAIL
    return 0  # NOERR
Ejemplo n.º 5
0
def main(world_folder):
	world = WorldFolder(world_folder)
	
	try:
		for chunk in world.iter_nbt():
			print_results(entities_per_chunk(chunk["Level"]))

	except KeyboardInterrupt:
		return 75 # EX_TEMPFAIL
	return 0 # NOERR
Ejemplo n.º 6
0
    def __init__(self, level_name):
        self.level_name = level_name

        # Temporary fix for issue #6 until I have a better solution
        if not os.path.exists(level_name):
            return

        if not os.path.exists("%s/region" % level_name):
            return

        self.world = WorldFolder(level_name)
Ejemplo n.º 7
0
def main(world_folder):
    world = WorldFolder(world_folder)

    try:
        region = world.get_region(0, 0)
        process_region_file(region)
        print_results()

    except KeyboardInterrupt:
        print('Keyboard interrupt!')
        print_results()
        return 75  # EX_TEMPFAIL

    return 0  # EX_OK
Ejemplo n.º 8
0
def main(world_folder, start=None, stop=None):
    world = WorldFolder(world_folder)

    try:
        for region in world.iter_regions():
            process_region_file(region, start, stop)

    except KeyboardInterrupt:
        print('Keyboard interrupt!')
        print_results(block_counts)
        return 75 # EX_TEMPFAIL

    print_results()
    return 0 # EX_OK
Ejemplo n.º 9
0
def main(world_folder, start=None, stop=None):
    world = WorldFolder(world_folder)

    try:
        for region in world.iter_regions():
            process_region_file(region, start, stop)

    except KeyboardInterrupt:
        print('Keyboard interrupt!')
        print_results(block_counts)
        return 75  # EX_TEMPFAIL

    print_results()
    return 0  # EX_OK
Ejemplo n.º 10
0
def main(world_folder, options):
    world = WorldFolder(world_folder)

    if not isinstance(world, nbt.world.AnvilWorldFolder):
        print(world_folder + " is not an Anvil world")
        return 0

    level = NBTFile(os.path.join(world_folder, "level.dat"))
    version = Util.get_version(level)

    print("\nLoading level at " + world_folder)
    if version != "1.8" or options.force:
        if options.force:
            print("[Forcing level conversion attempt]")
        print("Level saved as Minecraft version " + version)
        try:
            total_nbt_edits = 0
            total_block_edits = 0
            for region in world.iter_regions():
                for chunk in region.iter_chunks():
                    chunk, nbt_edits = convert_chunk(chunk)
                    chunk, block_edits = convert_block(chunk)
                    total_nbt_edits += nbt_edits
                    total_block_edits += block_edits
                    if options.save and nbt_edits > 0 or block_edits > 0:
                        save_chunk(region, chunk)
            if total_nbt_edits > 0 or total_block_edits > 0:
                print("%d modifications made to the level nbt" %
                      (total_nbt_edits))
                print("%d modifications made to block section byte arrays" %
                      (total_block_edits))
                if options.save:
                    save_level(level, world_folder)
                else:
                    print("No modifications saved to level (using -n flag)")
            else:
                print("No level data was changed (nothing to modify)")
        except KeyboardInterrupt:
            return 75
    else:
        print("Level is already saved for Minecraft 1.8 (or older)")

    if options.disable_keep_inv and options.save:
        disable_keep_inv(level, world_folder)

    return 0
Ejemplo n.º 11
0
class MainWindow(QMainWindow):
    
    def __init__(self, parent = None):
        super(MainWindow, self).__init__(parent)
        self.app = QCoreApplication.instance()
        self.setWindowTitle('Overview Test')
        
        world_folder = 'D:\Distrib\Ostrova01'
        world_folder = os.path.normpath(world_folder)
        if (not os.path.exists(world_folder)):
            print "No Minecraft folder " + world_folder
            sys.exit(72) # EX_IOERR
        self.world = WorldFolder(world_folder)
        #self.chunk = self.world.get_chunk(-11, 22)
        self.chunk = self.world.get_nbt(-11, 22)

        #block_data_totals = [[0]*16 for i in range(256)] # up to 16 data numbers in 256 block IDs
        
        #puk = self.chunk.blocks.get_all_blocks_and_data()
        #for block_id, data_id in self.chunk.blocks.get_all_blocks_and_data():
        #    block_data_totals[block_id][data_id] += 1

        # get style metrics
        style = self.app.style()
        self.leftMargin = style.pixelMetric(QStyle.PM_LayoutLeftMargin)
        self.topMargin = style.pixelMetric(QStyle.PM_LayoutTopMargin)
        self.hsepara = style.pixelMetric(QStyle.PM_LayoutHorizontalSpacing)
        self.vsepara = style.pixelMetric(QStyle.PM_LayoutVerticalSpacing)
        self.fm = self.app.fontMetrics()

        # chunkData
        self.chunkData = {'X': -11,
                          'Y': 23,
                          14 : 6,   # Gold
                          15 : 152, # Iron
                          56 : 66,  # Diamond
                          73 : 555, # Redstone
                          49 : 0,   # Obsidian
                          21 : 2}   # Lazurit
        
        # render area
        self.rend = SliceRenderArea(self)
        self.setCentralWidget(self.rend)
        # debug text width!
        word = 'Redstone = 555'
        wi = self.fm.width(word)
        hi = self.fm.height()
        print 'Width of the word {0} is {1}'.format(word, wi)
        print 'Height of the word {0} is {1}'.format(word, hi)
        print 'Horizontal divider: ' + str(self.hsepara)
        print 'Vertical divider: ' + str(self.vsepara)
        print 'Left margin: ' + str(self.leftMargin)
        print 'Top margin: ' + str(self.topMargin)

    def sizeHint(self):
        return QSize(600, 600)
Ejemplo n.º 12
0
class World:
    def __init__(self, level_name):
        self.level_name = level_name

        # Temporary fix for issue #6 until I have a better solution
        if not os.path.exists(level_name):
            return

        if not os.path.exists("%s/region" % level_name):
            return

        self.world = WorldFolder(level_name)

    def __str__(self):
        return self.level_name

    @property
    def chunks(self):
        # Currently incompatible with Python 3.x and above
        if sys.version_info.major > 2:
            raise Exception("This method currently only works with Python 2.x.")

        for basic_chunk in self.world.iter_chunks():
            print(basic_chunk)
            x, z = basic_chunk.get_coords()

            yield Chunk(self.world, x, z)

    @property
    def bounding_box(self):
        return self.world.get_boundingbox()

    @property
    def players(self):
        return

    @property
    def seed(self):
        return

    @property
    def size(self):
        return 0
Ejemplo n.º 13
0
 def __init__(self):
     super(Presenter, self).__init__()
     # don't know for what is this
     try:
         self.zip_longest = itertools.zip_longest
     except AttributeError:
         self.zip_longest = itertools.izip_longest
     # clean path name, eliminate trailing slashes:
     world_folder = 'C:\Users\Yuretzz\AppData\Roaming\.minecraft\saves\Ostrova01'
     #world_folder = 'D:\Distrib\Ostrova01'
     levelDatPath = world_folder + '\level.dat'
     world_folder = os.path.normpath(world_folder)
     levelDatPath = os.path.normpath(levelDatPath)
     if (not os.path.exists(world_folder)):
         print "No Minecraft folder " + world_folder
         sys.exit(72) # EX_IOERR
     # calculate player spawn point chunk
     nbt = NBTFile(levelDatPath,'rb')
     rootTag = nbt.tags[0]
     spawnX = int(rootTag['SpawnX'].value)
     spawnZ = int(rootTag['SpawnZ'].value)
     self.spawnChunkX = divmod(spawnX, 16)[0]
     self.spawnChunkZ = divmod(spawnZ, 16)[0]
     self.showChunkX = self.spawnChunkX
     self.showChunkZ = self.spawnChunkZ
     self.elevation = 32
     # load world
     self.world = WorldFolder(world_folder)
     if not isinstance(self.world, AnvilWorldFolder):
         print("%s is not an Anvil world" % (world_folder))
         sys.exit(72) # EX_IOERR
     # load chunk and get first 4 sections from bottom
     self.mineCube = self.makeMineCube(self.spawnChunkX, self.spawnChunkZ)
     # mainWindow and start
     self.mainWindow = MainWindow(self)
     print 'Free widget status after MainWindow instance created:'
     print self.mainWindow.blank4.contentsRect()
     self.mainWindow.mainControl.txtChunkX.setText(str(self.spawnChunkX))
     self.mainWindow.mainControl.txtChunkZ.setText(str(self.spawnChunkZ))
     self.mainWindow.show()
Ejemplo n.º 14
0
                find[int(ele[0])].sort()
        except IndexError:
            print("Aborting, ID too large in line " + str(i) + " : " + line)
            sys.exit()
        except ValueError:
            print("Aborting, bad value in line " + str(i) + " : " + line)
            sys.exit()
        line = inputfile.readline().strip("\n\r")
        i += 1
    inputfile.close()
    #print(find)

    #return

    counter = 0
    world = WorldFolder(world_folder)

    print("Counting chunks")
    numchunks = 0
    for chunk in world.iter_nbt():
        numchunks += 1
        sys.stdout.write('%d chunks\r' % (numchunks))
        sys.stdout.flush()
    #numchunks = 689
    print("")
    chunknum = 0
    try:
        for chunk in world.iter_nbt():
            chunknum += 1
            sys.stdout.write('%d / %d chunks searched\r' %
                             (chunknum, numchunks))
Ejemplo n.º 15
0
import os
import nbt
from nbt.chunk import *
from nbt.world import WorldFolder
from nbt.nbt import NBTFile

world_folder = os.path.normpath("/home/campbell/.minecraft/saves/glass2/")
world = WorldFolder(world_folder)
#print(nbtt.pretty_tree())
print(
    world.get_region(0, 0).get_nbt(0, 0)['Level']['Sections'][1].pretty_tree())
#print(world.get_region(0,0).get_chunks())
for i, state in enumerate(
        world.get_region(0,
                         0).get_nbt(1,
                                    0)['Level']['Sections'][1]['BlockStates']):
    print(state, i)
Ejemplo n.º 16
0
				find[int(ele[0])].sort()
		except IndexError:
			print("Aborting, ID too large in line "+str(i)+" : "+line)
			sys.exit()
		except ValueError:
			print("Aborting, bad value in line "+str(i)+" : "+line)
			sys.exit()
		line = inputfile.readline().strip("\n\r")
		i += 1
	inputfile.close()
	#print(find)

	#return

	counter = 0
	world = WorldFolder(world_folder)
	
	print("Counting chunks")
	numchunks = 0
	for chunk in world.iter_nbt():
		numchunks += 1
		sys.stdout.write('%d chunks\r' % (numchunks))
		sys.stdout.flush()
	#numchunks = 689
	print("")
	chunknum = 0
	try:
		for chunk in world.iter_nbt():
			chunknum += 1
			sys.stdout.write('%d / %d chunks searched\r' % (chunknum, numchunks))
			sys.stdout.flush()
Ejemplo n.º 17
0
class Presenter(QObject):
    
    def __init__(self):
        super(Presenter, self).__init__()
        # don't know for what is this
        try:
            self.zip_longest = itertools.zip_longest
        except AttributeError:
            self.zip_longest = itertools.izip_longest
        # clean path name, eliminate trailing slashes:
        world_folder = 'C:\Users\Yuretzz\AppData\Roaming\.minecraft\saves\Ostrova01'
        #world_folder = 'D:\Distrib\Ostrova01'
        levelDatPath = world_folder + '\level.dat'
        world_folder = os.path.normpath(world_folder)
        levelDatPath = os.path.normpath(levelDatPath)
        if (not os.path.exists(world_folder)):
            print "No Minecraft folder " + world_folder
            sys.exit(72) # EX_IOERR
        # calculate player spawn point chunk
        nbt = NBTFile(levelDatPath,'rb')
        rootTag = nbt.tags[0]
        spawnX = int(rootTag['SpawnX'].value)
        spawnZ = int(rootTag['SpawnZ'].value)
        self.spawnChunkX = divmod(spawnX, 16)[0]
        self.spawnChunkZ = divmod(spawnZ, 16)[0]
        self.showChunkX = self.spawnChunkX
        self.showChunkZ = self.spawnChunkZ
        self.elevation = 32
        # load world
        self.world = WorldFolder(world_folder)
        if not isinstance(self.world, AnvilWorldFolder):
            print("%s is not an Anvil world" % (world_folder))
            sys.exit(72) # EX_IOERR
        # load chunk and get first 4 sections from bottom
        self.mineCube = self.makeMineCube(self.spawnChunkX, self.spawnChunkZ)
        # mainWindow and start
        self.mainWindow = MainWindow(self)
        print 'Free widget status after MainWindow instance created:'
        print self.mainWindow.blank4.contentsRect()
        self.mainWindow.mainControl.txtChunkX.setText(str(self.spawnChunkX))
        self.mainWindow.mainControl.txtChunkZ.setText(str(self.spawnChunkZ))
        self.mainWindow.show()
    
    def grouper(self, iterable, n, fillvalue=None):
        "Collect data into fixed-length chunks or blocks"
        # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx"
        # Taken from itertools recipe.
        args = [iter(iterable)] * n
        return self.zip_longest(*args, fillvalue=fillvalue)

    def makeMineCube(self, chX, chZ):
        self.chunk = self.world.get_nbt(chX, chZ) # may raise InconceivedChunk
        self.sections = []
        for section in self.chunk['Level']['Sections']:
            if section['Y'].value in [0, 1, 2, 3]:
                self.sections.append(section)
        # prepare Minecraft Cube 3D array
        mineCube = []
        for section in self.sections:
            sectionCube = []
            blocks = section['Blocks'].value
            for yoffset in range(16):
                slice_ = list(blocks[yoffset*256:(yoffset+1)*256])
                igreks = []
                for row in self.grouper(slice_, 16):
                    #print (" ".join(("%2d" % blo) for blo in row))
                    igreks.append([blo for blo in row])
                sectionCube.append(igreks)
            mineCube += sectionCube
        return mineCube

    def changeCube(self, coords):
        self.mineCube = self.makeMineCube(coords[0], coords[1])
        self.showChunkX = coords[0]
        self.showChunkZ = coords[1]

    def getSlice(self, elevation):
        return self.mineCube[elevation]
Ejemplo n.º 18
0
import sys
import os
from nbt.world import WorldFolder, AnvilWorldFolder
import itertools
from nbt.nbt import NBTFile

#world_folder = 'C:\Users\Yuretzz\AppData\Roaming\.minecraft\saves\Ostrova01'
world_folder = 'D:\Distrib\Ostrova01'

world_folder = os.path.normpath(world_folder)

if (not os.path.exists(world_folder)):
    print "No Minecraft folder " + world_folder
    sys.exit(72) # EX_IOERR

world = WorldFolder(world_folder)
chunk = world.get_nbt(-12, 25)
stata = {}

for section in chunk['Level']['Sections']:
    if section['Y'].value in [0, 1, 2, 3]:
        blocks = section['Blocks'].value
        for byte in blocks:
            if byte in stata:
                stata[byte] += 1
            else:
                stata[byte] = 1

print stata

#{0: 3779, 1: 8848, 2: 189, 3: 1282, 4: 101, 7: 781, 9: 79, 11: 610, 12: 17,