Advertisement
Kopasz7

Random Replace - Faster

Jun 16th, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 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 2"
  10.  
  11. inputs = (
  12.     ("Replace", "blocktype"),
  13.     ("With", "blocktype"),
  14.     ("Step", (2, 0, 500)),
  15.     ("Any subtype", False)
  16. )
  17.  
  18. def perform(level, box, options):
  19.     mat1 = options["Replace"]
  20.     mat2 = options["With"]
  21.     step = options["Step"]
  22.     subtype = options["Any subtype"]
  23.     y = box.miny
  24.     for x in xrange(box.minx, box.maxx):
  25.         for z in xrange(box.minz, box.maxz):
  26.             while y <= box.maxy:
  27.                 y = y + int(randomGen() * step) + 1
  28.                 if level.blockAt(x, y, z) == mat1.ID and (level.blockDataAt(x, y, z) == mat1.blockData or subtype):
  29.                     level.setBlockAt(x, y, z, mat2.ID)
  30.                     level.setBlockDataAt(x, y, z, mat2.blockData)
  31.             y = box.miny
  32.     level.markDirtyBox(box)
  33. def randomGen():
  34.     return random.random()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement