pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

pastebin private pastebin - collaborative debugging tool What's a private pastebin?

Posted by frymaster on Thu 14th Apr 05:04
View followups from frymaster | download | new post

  1. #!/usr/bin/python
  2. import mclevel,sys,numpy,random
  3.  
  4. blockToChange="Redstone Ore"
  5. blockToChangeTo="Lapis Lazuli Ore"
  6. chanceToChange = 10     # One in (this) chance to change a block
  7.  
  8. alevel = mclevel.fromFile("/storage/games/minecraft/hmod/bin/NE-2011/level.dat")
  9. chunkPositions=alevel.allChunks
  10.  
  11. old=alevel.materials.materialNamed(blockToChange)
  12. new=alevel.materials.materialNamed(blockToChangeTo)
  13. chunkT=len(chunkPositions)
  14.  
  15. dirty=False
  16. numNewBlock=0
  17. chunkC=0
  18. def decide(blockOne):
  19.         global dirty
  20.         global numNewBlock
  21.         result = blockOne==old and random.randint(1,chanceToChange)==1
  22.         if result==True:
  23.                 dirty=True
  24.                 numNewBlock+=1
  25.         return result
  26.  
  27. decide_a=numpy.vectorize(decide)
  28. counter=0
  29. for x,z in chunkPositions:
  30.         chunkC+=1
  31.         chunk=alevel.getChunk(x,z)
  32.         foo=decide_a(chunk.Blocks)
  33.         if dirty==True:
  34.                 chunk.Blocks[foo] = new
  35.                 chunk.chunkChanged()
  36.                 dirty=False
  37.                 counter+=1
  38.         if counter>1000:
  39.                 alevel.saveInPlace()
  40.                 counter=0
  41.                 print "World Saved!",(chunkC * 100.0) /chunkT,"       ",numNewBlock, "redstone"
  42.  
  43. alevel.generateLights();
  44. alevel.saveInPlace()
  45. print "World Saved!",(chunkC * 100.0) /chunkT,"       ",numNewBlock, "blocks changed"
  46. sys.exit(0)

Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Use syntax highlighting

To highlight particular lines, prefix each line with @@


Remember my settings