Skip to content

Instantly share code, notes, and snippets.

@Gargaj
Last active August 29, 2015 13:57
Show Gist options
  • Save Gargaj/9423096 to your computer and use it in GitHub Desktop.
Save Gargaj/9423096 to your computer and use it in GitHub Desktop.
Block statistics script for MCEdit
# block stats filter for mcedit
# by gargaj
#
# select area, apply filter, receive dialog with exact block stats.
# great for building in creative and then estimating resources for survival
inputs = ()
from albow.dialogs import Dialog
from albow import TableView, TableColumn, Button
from pymclevel.materials import alphaMaterials
class ResultDialog(Dialog):
def __init__(self, total, *a, **kw):
Dialog.__init__(self, *a, **kw)
tableview = TableView(columns=[TableColumn("Block",320),TableColumn("Count",40)])
from pymclevel import items
res = []
for (block,v) in total.iteritems():
if block != 0:
if len(v) <= 1:
res.append( [items.items.findItem(block).name, str(v.itervalues().next())] )
else:
res.append( [items.items.findItem(block).name,""] )
for (data,count) in v.iteritems():
res.append( [" - " + alphaMaterials[block, data].name, str(count)] )
tableview.num_rows = lambda: len(res)
tableview.row_data = lambda i: (res[i][0],res[i][1])
tableview.shrink_wrap()
self.add(tableview)
self.shrink_wrap()
but = Button("OK")
but.action = self.ok
but.top = tableview.bottom
but.centerx = self.centerx
but.align = "c"
but.height = 30
self.add(but)
self.shrink_wrap()
self.bottom += 30
def perform(level, box, options):
global GlobalLevel
GlobalLevel = level
total = {}
for x in xrange(box.minx, box.maxx):
for y in xrange(box.miny, box.maxy):
for z in xrange(box.minz, box.maxz):
block = level.blockAt(x,y,z)
data = level.blockDataAt(x,y,z)
if not block in total:
total[ block ] = {}
if not data in total[ block ]:
total[ block ][ data ] = 0
total[ block ][ data ] += 1
dialog = ResultDialog( total )
dialog.present()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment