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:09 (modification of post by frymaster view diff)
diff | 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. alevel = mclevel.fromFile("/storage/games/minecraft/hmod/bin/NE-2011/level.dat")
  8.  
  9. chunkPositions=alevel.allChunks
  10. old=alevel.materials.materialNamed(blockToChange)
  11. new=alevel.materials.materialNamed(blockToChangeTo)
  12. chunkT=len(chunkPositions)
  13.  
  14. dirty=False
  15. numNewBlock=0
  16. chunkC=0
  17. def decide(blockOne):
  18.         global dirty
  19.         global numNewBlock
  20.         result = blockOne==old and random.randint(1,chanceToChange)==1
  21.         if result==True:
  22.                 dirty=True
  23.                 numNewBlock+=1
  24.         return result
  25.  
  26. decide_a=numpy.vectorize(decide)
  27. counter=0
  28. for x,z in chunkPositions:
  29.         chunkC+=1
  30.         chunk=alevel.getChunk(x,z)
  31.         foo=decide_a(chunk.Blocks)
  32.         if dirty==True:
  33.                 chunk.Blocks[foo] = new
  34.                 chunk.chunkChanged()
  35.                 dirty=False
  36.                 counter+=1
  37.         if counter>1000:
  38.                 alevel.generateLights();
  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