Advertisement
Kopasz7

Hanging blocks

Oct 30th, 2012
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. displayName = "Hanging blocks"
  2.  
  3. inputs = (
  4.     ("Replace", "blocktype"),
  5.     ("With", "blocktype"),
  6.     ("Frequency %", (50, 0, 100)),
  7.     ("Length %", (50, 0, 100)),
  8.     ("Check above", False),
  9. )
  10.  
  11. def perform(level, box, options):
  12.     mat1 = options["Replace"]
  13.     mat2 = options["With"]
  14.     frequency = options["Frequency %"]
  15.     length = options["Length %"]
  16.     mode = options["Check above"]
  17.     blockAbove = False
  18.     if mode:
  19.         first = True
  20.         for x in xrange(box.minx, box.maxx):
  21.             for z in xrange(box.minz, box.maxz):
  22.                 for y in reversed(xrange(box.miny, box.maxy)):
  23.                     if level.blockAt(x, y, z) == mat1.ID:
  24.                         if first:
  25.                             if randomGen() <= frequency and blockAbove:
  26.                                 level.setBlockAt(x, y, z, mat2.ID)
  27.                                 first = False
  28.                             else:
  29.                                 blockAbove = False
  30.                         else:
  31.                             if randomGen() <= length and blockAbove:
  32.                                 level.setBlockAt(x, y, z, mat2.ID)
  33.                             else:
  34.                                 blockAbove = False
  35.                     else:
  36.                         blockAbove = True
  37.                 blockAbove = False
  38.                 first = True
  39.         level.markDirtyBox(box)
  40.     else:
  41.         first = True
  42.         for x in xrange(box.minx, box.maxx):
  43.             for z in xrange(box.minz, box.maxz):
  44.                 for y in reversed(xrange(box.miny, box.maxy)):
  45.                     if level.blockAt(x, y, z) == mat1.ID:
  46.                         if first:
  47.                             if randomGen() <= frequency:
  48.                                 level.setBlockAt(x, y, z, mat2.ID)
  49.                                 first = False
  50.                             else:
  51.                                 break
  52.                         else:
  53.                             if randomGen() <= length:
  54.                                 level.setBlockAt(x, y, z, mat2.ID)
  55.                             else:
  56.                                 break
  57.                 first = True
  58.         level.markDirtyBox(box)
  59. def randomGen():
  60.     return int(random.random() * 100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement