From 49b9392dd9d1571034a59cc4a094c2fce36fe0f1 Mon Sep 17 00:00:00 2001 From: David Vierra Date: Sun, 13 Mar 2011 16:46:09 -1000 Subject: [PATCH] updated analyze to count blocks with alternate blockData --- mce.py | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/mce.py b/mce.py index 29288e8..5aa81ce 100755 --- a/mce.py +++ b/mce.py @@ -430,24 +430,45 @@ class mce(object): Also updates the level's 'SizeOnDisk' field, correcting its size in the world select menu. """ - blockCounts = zeros( (256,), 'uint64') + blockCounts = zeros( (4096,), 'uint64') sizeOnDisk = 0; print "Analyzing {0} chunks...".format(self.level.chunkCount) + #for input to bincount, create an array of uint16s by + #shifting the data left and adding the blocks + for i, cPos in enumerate(self.level.allChunks, 1): ch = self.level.getChunk(*cPos); - counts = bincount(ch.Blocks.ravel()) + btypes = numpy.array(ch.Data.ravel(), dtype='uint16') + btypes <<= 8 + btypes += ch.Blocks.ravel() + counts = bincount(btypes) + blockCounts[:counts.shape[0]] += counts sizeOnDisk += ch.compressedSize(); ch.unload(); if i % 100 == 0: - print "Chunk {0}...".format( i ) + logging.info( "Chunk {0}...".format( i ) ) + + for blockID in range(256): + block = self.level.materials.blockWithID(blockID, 0) + if block.hasAlternate: + for data in range(16): + i = (data << 8) + blockID + if blockCounts[i]: + idstring = "({id}:{data})".format(id=blockID, data=data) + + print "{idstring:9} {name:30}: {count:<10}".format( + idstring=idstring, name=self.level.materials.blockWithID(blockID, data).name, count=blockCounts[i]); + + else: + count = int(sum( blockCounts[(d<<8)+blockID] for d in range(16) )) + if count: + idstring = "({id})".format(id=blockID) + print "{idstring:9} {name:30}: {count:<10}".format( + idstring=idstring, name=self.level.materials.blockWithID(blockID, 0).name, count=count); - for i in range(256): - if blockCounts[i]: - print "{0:30}: {1:10}".format(self.level.materials.names[i], blockCounts[i]); - print "Size on disk: {0:.3}MB".format(sizeOnDisk / 1048576.0) self.level.SizeOnDisk = sizeOnDisk self.needsSave = True