Ejemplo n.º 1
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.º 2
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.º 3
0
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,
# 13: 450, 14: 2, 15: 65, 16: 124, 17: 3, 18: 21, 21: 2, 37: 1, 40: 2, 49: 10,