예제 #1
0
class Chunk:
    def __init__(self, world, coords, nbt):
        self.world = world
        self.coords = coords
        self.id = hash(self.coords)
        self.mineCube = ''
        self.blocks = {}
        self.oreStatistics = {}
        # nbt is supplied by loadChunk from World. None means Chunk invalid
        if nbt:
            self.isValid = True
            for section in nbt['Level']['Sections']:
                if section['Y'].value in [0, 1, 2, 3]:
                    self.blocks[section['Y'].value] = section['Blocks'].value
            # prepare statistics
            for block in self.blocks.values():
                for byte in block:
                    if byte in self.oreStatistics:
                        self.oreStatistics[byte] += 1
                    else:
                        self.oreStatistics[byte] = 1
        else:
            self.isValid = False

    def createCube(self):
        if self.isValid:
            self.mineCube = MineCube(self)

    def fetchMineral(self, mineralID):
        return self.mineCube.fetchMineral(mineralID)
예제 #2
0
 def createCube(self):
     if self.isValid:
         self.mineCube = MineCube(self)