Advertisement
QuantumWarpCode

MCEdit Citygen Filter

Feb 12th, 2016
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.36 KB | None | 0 0
  1. # Made by @QuantumWarpCode.
  2. # Feel free to modify and use this filter however you wish. If you do,
  3. # please give credit to Elopus001.
  4.  
  5. from pymclevel import TAG_List
  6. from pymclevel import TAG_Byte
  7. from pymclevel import TAG_Int
  8. from pymclevel import TAG_Compound
  9. import random
  10.  
  11. displayName = "Generate a City"
  12.  
  13. xmod = 0
  14. ymod = 0
  15. zmod = 0
  16. levels = 0
  17.  
  18. def perform(level, box, options):
  19.     level.markDirtyBox(box)
  20.        
  21.     height = box.maxy - box.miny
  22.     width = box.maxx - box.minx
  23.     length  = box.maxz - box.minz
  24.    
  25.     global xmod
  26.     xmod = box.minx
  27.     global ymod
  28.     ymod = box.miny
  29.     global zmod
  30.     zmod = box.minz
  31.    
  32.     global levels
  33.     levelMod = (height - 2) % 4
  34.     levels = (height - 2 - levelMod) / 4
  35.    
  36.     createFilledOutline(1, width - 1, 1, length - 1, 0, 43, 0, 2, 0, level)
  37.     createOutline(0, width, 0, length, 0, 43, 0, level)
  38.     createGrid(0, width, 0, length, 0, 43, 0, level)
  39.     callBuild(0, width, 0, length, 0, level)
  40.  
  41. def setBlock(x, y, z, block, blockdata, level):
  42.     global xmod
  43.     global ymod
  44.     global zmod
  45.    
  46.     level.setBlockAt(x + xmod, y + ymod, z + zmod, block)
  47.     level.setBlockDataAt(x + xmod, y + ymod, z + zmod, blockdata)
  48.  
  49. def createFilledOutline(xstart, xend, zstart, zend, y, block, blockdata, block2, block2data, level):
  50.     for x in range(xstart, xend):
  51.         for z in range(zstart, zend):
  52.             xEdge = (x == xstart or x == xend - 1)
  53.             zEdge = (z == zstart or z == zend - 1)
  54.             if xEdge or zEdge:
  55.                 setBlock(x, y, z, block, blockdata, level)
  56.             else:
  57.                 setBlock(x, y, z, block2, block2data, level)
  58.  
  59. def createCornerOutline(xstart, xend, zstart, zend, y, block, blockdata, block2, block2data, level):
  60.     for x in range(xstart, xend):
  61.         for z in range(zstart, zend):
  62.             xEdge = (x == xstart or x == xend - 1)
  63.             zEdge = (z == zstart or z == zend - 1)
  64.             if xEdge and zEdge:
  65.                 setBlock(x, y, z, block2, block2data, level)
  66.             elif xEdge or zEdge:
  67.                 setBlock(x, y, z, block, blockdata, level)
  68.  
  69. def createOutline(xstart, xend, zstart, zend, y, block, blockdata, level):
  70.     for x in range(xstart, xend):
  71.         for z in range(zstart, zend):
  72.             xEdge = (x == xstart or x == xend - 1)
  73.             zEdge = (z == zstart or z == zend - 1)
  74.             if xEdge or zEdge:
  75.                 setBlock(x, y, z, block, blockdata, level)
  76.  
  77. def createGrid(xstart, xend, zstart, zend, y, block, blockdata, level):
  78.     for x in range(xstart, xend):
  79.         for z in range(zstart, zend):
  80.             xEdge = (x % 16 == 0 or (x - 1) % 16 == 0)
  81.             zEdge = (z % 16 == 0 or (z - 1) % 16 == 0)
  82.             if xEdge or zEdge:
  83.                 setBlock(x, y, z, block, blockdata, level)
  84.  
  85. def createSkyscraper(xstart, zstart, level):
  86.     global levels
  87.    
  88.     space = random.randint(2, 5)
  89.    
  90.     height = (random.randint(1, levels)) * 4
  91.    
  92.     for y in range (0, height + 1):
  93.         if y % 4 == 0:
  94.             createFilledOutline(xstart + space, xstart + 16 - space, zstart + space, zstart + 16 - space, y, 98, 0, 5, 5,level)
  95.         else:
  96.             createCornerOutline(xstart + space, xstart + 16 - space, zstart + space, zstart + 16 - space, y, 102, 0, 98, 0, level)
  97.    
  98.     createOutline(xstart + space, xstart + 16 - space, zstart + space, zstart + 16 - space, height + 1, 98, 0, level)
  99.                
  100. def callBuild(xstart, xend, zstart, zend, y, level):
  101.     for x in range(xstart, xend):
  102.         for z in range(zstart, zend):
  103.             xEdge = ((x - 1) % 16 == 0 and x != xend - 1)
  104.             zEdge = ((z - 1) % 16 == 0 and z != zend - 1)
  105.             if xEdge and zEdge:
  106.                 setBlock(x, y + 1, z, 1, 0, level)
  107.                 createSkyscraper(x, z, level)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement