Advertisement
Kopasz7

Random replace

Oct 30th, 2012
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. from pymclevel import MCSchematic
  2. from pymclevel import TileEntity
  3. from pymclevel import TAG_Compound
  4. from pymclevel import TAG_Short
  5. from pymclevel import TAG_Byte
  6. from pymclevel import TAG_String
  7. import random
  8.  
  9. displayName = "Random Replace"
  10.  
  11. inputs = (
  12.     ("Replace", "blocktype"),
  13.     ("With", "blocktype"),
  14.     ("Chance", (50, 0, 100))
  15. )
  16.  
  17. def perform(level, box, options):
  18.     mat1 = options["Replace"]
  19.     mat2 = options["With"]
  20.     chance = options["Chance"]
  21.     for x in xrange(box.minx, box.maxx):
  22.         for y in xrange(box.miny, box.maxy):
  23.             for z in xrange(box.minz, box.maxz):
  24.                 if level.blockAt(x, y, z) == mat1.ID and level.blockDataAt(x, y, z) == mat1.blockData:
  25.                     if randomGen() <= chance:
  26.                         level.setBlockAt(x, y, z, mat2.ID)
  27.                         level.setBlockDataAt(x, y, z, mat2.blockData)
  28.     level.markDirtyBox(box)
  29. def randomGen():
  30.     return int(random.random() * 100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement