All pastes #2088861 Raw Edit

Mine

public python v1 · immutable
#2088861 ·published 2011-10-10 20:11 UTC
rendered paste body
#! /usr/bin/env pythonimport osfrom logging import warn, error, info, debugfrom numpy import fromstringimport nbtfrom mclevelbase import *import mclevelfrom indev import *from infiniteworld import *from java import *from level import *from schematic import *import threadingimport timeclass modifierThread(threading.Thread):	def __init__(self, workerid):		threading.Thread.__init__(self);		self.chunkQueue = [];		self.alive = True		self.done = False		self.id=workerid	def run(self):		while self.alive:			while len(self.chunkQueue)>0:				chunk = self.chunkQueue.pop();				for x in range(0,16):					for z in range(0,16):						for y in range(50,128):							blockid = chunk.Blocks[x,z,y];							if changeBlocksHash[blockid]:								chunk.Blocks[x,z,y]=changeBlocks[int(random.random()*len(changeBlocks))];				chunk.chunkChanged();				#print "worker %s fu"			time.sleep(.01);			if not self.alive and len(self.chunkQueue)==0:				self.done = TruechangeBlocks = [1,2,3,4,5,7,12,13,14,15,16,17,18,19,20,21,22,23,24,25,29,30,33,35,41,42,43,44,45,46,47,48,49,52,53,54,55,56,57,58,60,61,63,67,73,74,79,80,81,82,83,84,85,86,87,88,89,90,91,95,97,98,101,102,103,107,108,109]changeBlocksHash = []for i in range(0,257):	changeBlocksHash.append(False)for i in changeBlocks:	changeBlocksHash[i]=Trueworld = mclevel.fromFile("/tmp/ramdisk/Waterfarm/");workers = [modifierThread(0), modifierThread(1), modifierThread(2), modifierThread(3), modifierThread(4), modifierThread(5), modifierThread(6), modifierThread(7)]for thread in workers:	thread.start();chunklist = list(world.allChunks);counttotal = len(chunklist);countprocessed = 0while countprocessed<counttotal-1:	for worker in workers:		if len(worker.chunkQueue)<5:			nowchunk = chunklist[countprocessed];			chunkobject = world.getChunk(nowchunk[0], nowchunk[1]);			worker.chunkQueue.append(chunkobject);			print "assigning chunk %s of %s to worker %s" % (countprocessed+1, counttotal, worker.id);			countprocessed+=1	time.sleep(.01);# out of chunks?for worker in workers:	worker.alive = False;# Wait for workers to finishprint "please wait while worker threads complete......."lastremaining = 0while True:	done = True	remaining = 0	for worker in workers:		remaining += len(worker.chunkQueue)		if not worker.done:			done = False	if done:		break	if remaining!=lastremaining:		print "%s chunks remaining" % remaining		lastremaining = remaining	time.sleep(.1);print "edit complete, generating lights"world.generateLights();print "saving map"world.saveInPlace();print "done"