def _dumpchests(self, command): """ dumpChests [ <filename> ] Saves the content and location of every chest in the world to a text file. With no filename, saves signs to <worldname>.chests Output is delimited by brackets and newlines. A set of coordinates in brackets begins a chest, followed by a line for each inventory slot. For example: [222, 51, 22] 2 String 3 String 3 Iron bar Coordinates are ordered the same as point inputs: [North/South, Down/Up, East/West] """ from items import items if len(command): filename = command[0] else: filename = self.level.displayName + ".chests" outFile = file(filename, "w") print "Dumping chests..." chestCount = 0 for i, cPos in enumerate(self.level.allChunks): try: chunk = self.level.getChunk(*cPos) except mclevelbase.ChunkMalformed: continue for tileEntity in chunk.TileEntities: if tileEntity["id"].value == "Chest": chestCount += 1 outFile.write(str(map(lambda x: tileEntity[x].value, "xyz")) + "\n") itemsTag = tileEntity["Items"] if len(itemsTag): for itemTag in itemsTag: try: id = itemTag["id"].value damage = itemTag["Damage"].value item = items.findItem(id, damage) itemname = item.name except KeyError: itemname = "Unknown Item {0}".format(itemTag) except Exception, e: itemname = repr(e) outFile.write("{0} {1}\n".format(itemTag["Count"].value, itemname)) else: outFile.write("Empty Chest\n") if i % 100 == 0: print "Chunk {0}...".format(i)
def _dumpchests(self, command): """ dumpChests [ <filename> ] Saves the content and location of every chest in the world to a text file. With no filename, saves signs to <worldname>.chests Output is delimited by brackets and newlines. A set of coordinates in brackets begins a chest, followed by a line for each inventory slot. For example: [222, 51, 22] 2 String 3 String 3 Iron bar Coordinates are ordered the same as point inputs: [North/South, Down/Up, East/West] """ from items import items if len(command): filename = command[0] else: filename = self.level.displayName + ".chests" outFile = file(filename, "w") print "Dumping chests..." chestCount = 0 for i, cPos in enumerate(self.level.allChunks): try: chunk = self.level.getChunk(*cPos) except mclevelbase.ChunkMalformed: continue for tileEntity in chunk.TileEntities: if tileEntity["id"].value == "Chest": chestCount += 1 outFile.write(str(map(lambda x: tileEntity[x].value, "xyz")) + "\n") itemsTag = tileEntity["Items"] if len(itemsTag): for itemTag in itemsTag: try: id = itemTag["id"].value damage = itemTag["Damage"].value item = items.findItem(id, damage) itemname = item.name except KeyError: itemname = "Unknown Item {0}".format(itemTag) except Exception, e: itemname = repr(e) outFile.write("{0} {1}\n".format(itemTag["Count"].value, itemname)) else: outFile.write("Empty Chest\n") if i % 100 == 0: print "Chunk {0}...".format(i)
def _dumpchests(self, command): ''' dumpChests [ <filename> ] Saves the content and location of every chest in the world to a text file. With no filename, saves signs to <worldname>.chests Output is delimited by brackets and newlines. A set of coordinates in brackets begins a chest, followed by a line for each inventory slot. For example: [222, 51, 22] 2 String 3 String 3 Iron bar Coordinates are ordered the same as point inputs: [North/South, Down/Up, East/West] ''' from items import items if len(command): filename = command[0] else: filename = self.level.displayName + '.chests' outFile = open(filename, 'w') print('Dumping chests...') chestCount = 0 for i, cPos in enumerate(self.level.allChunks): try: chunk = self.level.getChunk(*cPos) except mclevelbase.ChunkMalformed: continue for tileEntity in chunk.TileEntities: if tileEntity['id'].value == 'Chest': chestCount += 1 outFile.write(str([tileEntity[x].value for x in 'xyz']) + '\n') itemsTag = tileEntity['Items'] if len(itemsTag): for itemTag in itemsTag: try: id = itemTag['id'].value damage = itemTag['Damage'].value item = items.findItem(id, damage) itemname = item.name except KeyError: itemname = 'Unknown Item {0}'.format(itemTag) except Exception as e: itemname = repr(e) outFile.write('{0} {1}\n'.format(itemTag['Count'].value, itemname)) else: outFile.write('Empty Chest\n') if i % 100 == 0: print('Chunk {0}...'.format(i)) print('Dumped {0} chests to {1}'.format(chestCount, filename)) outFile.close()
def _dumpchests(self, command): ''' dumpChests [ <filename> ] Saves the content and location of every chest in the world to a text file. With no filename, saves signs to <worldname>.chests Output is delimited by brackets and newlines. A set of coordinates in brackets begins a chest, followed by a line for each inventory slot. For example: [222, 51, 22] 2 String 3 String 3 Iron bar Coordinates are ordered the same as point inputs: [North/South, Down/Up, East/West] ''' from items import items if len(command): filename = command[0] else: filename = self.level.displayName + '.chests' outFile = open(filename, 'w') print('Dumping chests...') chestCount = 0 for i, cPos in enumerate(self.level.allChunks): try: chunk = self.level.getChunk(*cPos) except mclevelbase.ChunkMalformed: continue for tileEntity in chunk.TileEntities: if tileEntity['id'].value == 'Chest': chestCount += 1 outFile.write( str([tileEntity[x].value for x in 'xyz']) + '\n') itemsTag = tileEntity['Items'] if len(itemsTag): for itemTag in itemsTag: try: id = itemTag['id'].value damage = itemTag['Damage'].value item = items.findItem(id, damage) itemname = item.name except KeyError: itemname = 'Unknown Item {0}'.format(itemTag) except Exception as e: itemname = repr(e) outFile.write('{0} {1}\n'.format( itemTag['Count'].value, itemname)) else: outFile.write('Empty Chest\n') if i % 100 == 0: print('Chunk {0}...'.format(i)) print('Dumped {0} chests to {1}'.format(chestCount, filename)) outFile.close()