Advertisement
QuantumWarpCode

MCEdit Citygen Filter V1

Feb 12th, 2016
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.81 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. # Version : 1
  5.  
  6. from pymclevel import TAG_List
  7. from pymclevel import TAG_Byte
  8. from pymclevel import TAG_Int
  9. from pymclevel import TAG_Compound
  10. import random
  11.  
  12. displayName = "Generate a City"
  13.  
  14. inputs = (
  15.     ("Basements (These require 4 blocks of height each)", 3),
  16.     ("Minimum Height", 1),
  17. )
  18.  
  19. xmod = 0
  20. ymod = 0
  21. zmod = 0
  22. levels = 0
  23. basements = 0
  24.  
  25. def perform(level, box, options):
  26.     level.markDirtyBox(box)
  27.        
  28.     height = box.maxy - box.miny
  29.     width = box.maxx - box.minx
  30.     length  = box.maxz - box.minz
  31.    
  32.     global xmod
  33.     xmod = box.minx
  34.     global ymod
  35.     ymod = box.miny
  36.     global zmod
  37.     zmod = box.minz
  38.    
  39.     global basements
  40.     basements = options["Basements (These require 4 blocks of height each)"]
  41.     global minHeight
  42.     minHeight = options["Minimum Height"]
  43.    
  44.     global levels
  45.     levelMod = (height - (basements * 4) - 2) % 4
  46.     levels = ((height - (basements * 4)) - 2 - levelMod) / 4
  47.    
  48.     fillCube(0, width, 0, length,  0, basements * 4, 3, 0, level)
  49.     createFilledOutline(1, width - 1, 1, length - 1, 0 + (basements * 4), 43, 0, 2, 0, level)
  50.     createOutline(0, width, 0, length, 0 + (basements * 4), 43, 0, level)
  51.     createGrid(0, width, 0, length, 0 + (basements * 4), 43, 0, level)
  52.     callBuild(0, width, 0, length, 0 + (basements * 4), level)
  53.  
  54. def setBlock(x, y, z, block, blockdata, level):
  55.     global xmod
  56.     global ymod
  57.     global zmod
  58.     global basements
  59.    
  60.     level.setBlockAt(x + xmod, y + ymod, z + zmod, block)
  61.     level.setBlockDataAt(x + xmod, y + ymod, z + zmod, blockdata)
  62.  
  63. def fillRectangle(xstart, xend, zstart, zend, y, block, blockdata, level):
  64.     for x in range(xstart, xend):
  65.         for z in range(zstart, zend):
  66.             setBlock(x, y, z, block, blockdata, level)
  67.    
  68. def fillCube(xstart, xend, zstart, zend, ystart, yend, block, blockdata, level):
  69.     for x in range(xstart, xend):
  70.         for y in range(ystart, yend):
  71.             for z in range(zstart, zend):
  72.                 setBlock(x, y, z, block, blockdata, level)
  73.  
  74. def createFilledOutline(xstart, xend, zstart, zend, y, block, blockdata, block2, block2data, level):
  75.     for x in range(xstart, xend):
  76.         for z in range(zstart, zend):
  77.             xEdge = (x == xstart or x == xend - 1)
  78.             zEdge = (z == zstart or z == zend - 1)
  79.             if xEdge or zEdge:
  80.                 setBlock(x, y, z, block, blockdata, level)
  81.             else:
  82.                 setBlock(x, y, z, block2, block2data, level)
  83.  
  84. def createCornerOutline(xstart, xend, zstart, zend, y, block, blockdata, block2, block2data, level):
  85.     for x in range(xstart, xend):
  86.         for z in range(zstart, zend):
  87.             xEdge = (x == xstart or x == xend - 1)
  88.             zEdge = (z == zstart or z == zend - 1)
  89.             if xEdge and zEdge:
  90.                 setBlock(x, y, z, block2, block2data, level)
  91.             elif xEdge or zEdge:
  92.                 setBlock(x, y, z, block, blockdata, level)
  93.  
  94. def createOutline(xstart, xend, zstart, zend, y, block, blockdata, level):
  95.     for x in range(xstart, xend):
  96.         for z in range(zstart, zend):
  97.             xEdge = (x == xstart or x == xend - 1)
  98.             zEdge = (z == zstart or z == zend - 1)
  99.             if xEdge or zEdge:
  100.                 setBlock(x, y, z, block, blockdata, level)
  101.  
  102. def createGrid(xstart, xend, zstart, zend, y, block, blockdata, level):
  103.     for x in range(xstart, xend):
  104.         for z in range(zstart, zend):
  105.             xEdge = (x % 16 == 0 or (x - 1) % 16 == 0)
  106.             zEdge = (z % 16 == 0 or (z - 1) % 16 == 0)
  107.             if xEdge or zEdge:
  108.                 setBlock(x, y, z, block, blockdata, level)
  109.  
  110. def createSkyscraper(xstart, zstart, ystart, level):
  111.     global levels
  112.     global basements
  113.    
  114.     space = random.randint(2, 5)
  115.     global minHeight
  116.    
  117.     height = (random.randint(minHeight, levels)) * 4
  118.     bheight = random.randint(0, basements) * 4
  119.    
  120.     ladderPos = (random.randint(1, 4))
  121.     ladderRot = (random.randint(1, 2))
  122.    
  123.     if ladderPos == 1:
  124.         ladderTowerXPos = xstart + 7
  125.         ladderTowerZPos = zstart + 7
  126.         if ladderRot == 1:
  127.             ladderXPos = ladderTowerXPos + 1
  128.             ladderZPos = ladderTowerZPos
  129.             ladderData = 5
  130.         elif ladderRot == 2:
  131.             ladderXPos = ladderTowerXPos
  132.             ladderZPos = ladderTowerZPos + 1
  133.             ladderData = 3
  134.     elif ladderPos == 2:
  135.         ladderTowerXPos = xstart + 8
  136.         ladderTowerZPos = zstart + 7
  137.         if ladderRot == 1:
  138.             ladderXPos = ladderTowerXPos - 1
  139.             ladderZPos = ladderTowerZPos
  140.             ladderData = 4
  141.         elif ladderRot == 2:
  142.             ladderXPos = ladderTowerXPos
  143.             ladderZPos = ladderTowerZPos + 1
  144.             ladderData = 3
  145.     elif ladderPos == 3:
  146.         ladderTowerXPos = xstart + 7
  147.         ladderTowerZPos = zstart + 8
  148.         if ladderRot == 1:
  149.             ladderXPos = ladderTowerXPos + 1
  150.             ladderZPos = ladderTowerZPos
  151.             ladderData = 5
  152.         elif ladderRot == 2:
  153.             ladderXPos = ladderTowerXPos
  154.             ladderZPos = ladderTowerZPos - 1
  155.             ladderData = 2
  156.     elif ladderPos == 4:
  157.         ladderTowerXPos = xstart + 8
  158.         ladderTowerZPos = zstart + 8
  159.         if ladderRot == 1:
  160.             ladderXPos = ladderTowerXPos - 1
  161.             ladderZPos = ladderTowerZPos
  162.             ladderData = 4
  163.         elif ladderRot == 2:
  164.             ladderXPos = ladderTowerXPos
  165.             ladderZPos = ladderTowerZPos - 1
  166.             ladderData = 2
  167.    
  168.     for y in range (0, height + bheight + 1):
  169.         if y % 4 == 0:
  170.             createFilledOutline(xstart + space, xstart + 16 - space, zstart + space, zstart + 16 - space, y + ystart - bheight, 98, 0, 5, 5, level)
  171.             if y != height + bheight:
  172.                 setBlock(ladderTowerXPos, y + ystart - bheight, ladderTowerZPos, 98, 0, level)
  173.             if y != 0:
  174.                 setBlock(ladderXPos, y + ystart - bheight, ladderZPos, 65, ladderData, level)
  175.         else:
  176.             if y > bheight:
  177.                 createCornerOutline(xstart + space, xstart + 16 - space, zstart + space, zstart + 16 - space, y + ystart - bheight, 102, 0, 98, 0, level)
  178.                 setBlock(ladderTowerXPos, y + ystart - bheight, ladderTowerZPos, 98, 0, level)
  179.                 setBlock(ladderXPos, y + ystart - bheight, ladderZPos, 65, ladderData, level)
  180.             else:
  181.                 createFilledOutline(xstart + space, xstart + 16 - space, zstart + space, zstart + 16 - space, y + ystart - bheight, 98, 0, 0, 0, level)
  182.                 setBlock(ladderTowerXPos, y + ystart - bheight, ladderTowerZPos, 98, 0, level)
  183.                 setBlock(ladderXPos, y + ystart - bheight, ladderZPos, 65, ladderData, level)
  184.    
  185.     createOutline(xstart + space, xstart + 16 - space, zstart + space, zstart + 16 - space, height + ystart + 1, 98, 0, level)
  186.    
  187.     if space == 4:
  188.         hedge = random.randint(1, 3)
  189.         if hedge == 1:
  190.             createOutline(xstart + 2, xstart + 16 - 2, zstart + 2, zstart + 16 - 2, 1 + ystart, 18, 3, level)
  191.    
  192.     doors = (random.randint(1, 15))
  193.     #doors = 4
  194.     if doors  == 1 or doors == 5 or doors == 7 or doors == 9 or doors == 11 or doors == 12 or doors == 13 or doors == 15:
  195.         fillRectangle(xstart + 7, xstart + 9, zstart + 1, zstart + space, ystart, 43, 0, level)
  196.         fillRectangle(xstart + 7, xstart + 9, zstart + 1, zstart + space + 1, ystart + 1, 0, 0, level)
  197.         fillRectangle(xstart + 7, xstart + 9, zstart + 1, zstart + space + 1, ystart + 2, 0, 0, level)
  198.     if doors == 2 or doors == 5 or doors == 8 or doors == 10 or doors == 11 or doors == 12 or doors == 14 or doors == 15:
  199.         fillRectangle(xstart + 1, xstart + space, zstart + 7, zstart + 9, ystart, 43, 0, level)
  200.         fillRectangle(xstart + 1, xstart + space + 1, zstart + 7, zstart + 9, ystart + 1, 0, 0, level)
  201.         fillRectangle(xstart + 1, xstart + space + 1, zstart + 7, zstart + 9, ystart + 2, 0, 0, level)
  202.     if doors == 3 or doors == 6 or doors == 7 or doors == 10 or doors == 11 or doors == 13 or doors == 14 or doors == 15:
  203.         fillRectangle(xstart + 7, xstart + 9, zstart + 16 - space, zstart + 16 - 1, ystart, 43, 0, level)
  204.         fillRectangle(xstart + 7, xstart + 9, zstart + 16 - space - 1, zstart + 16 - 1, ystart + 1, 0, 0, level)
  205.         fillRectangle(xstart + 7, xstart + 9, zstart + 16 - space - 1, zstart + 16 - 1, ystart + 2, 0, 0, level)
  206.     if doors == 4 or doors == 6 or doors == 8 or doors == 9 or doors == 12 or doors == 13 or doors == 14 or doors == 15:
  207.         fillRectangle(xstart + 16 - space, xstart + 16 - 1, zstart + 7, zstart + 9, ystart, 43, 0, level)
  208.         fillRectangle(xstart + 16 - space - 1, xstart + 16 - 1, zstart + 7, zstart + 9, ystart + 1, 0, 0, level)
  209.         fillRectangle(xstart + 16 - space - 1, xstart + 16 - 1, zstart + 7, zstart + 9, ystart + 2, 0, 0, level)
  210.  
  211. def createDirtLot(xstart, zstart, ystart, level):
  212.     fillRectangle(xstart + 1, xstart + 16 - 1, zstart + 1, zstart + 16 - 1, ystart, 3, 1, level)
  213.  
  214. def createFlowerLot(xstart, zstart, ystart, level):
  215.     for x in range(xstart + 1, xstart + 16 - 1):
  216.         for z in range(zstart + 1, zstart + 16 - 1):
  217.             flower = random.randint(1, 5)
  218.             if flower == 5:
  219.                 setBlock(x, ystart + 1, z, 38, random.randint(0,8), level)
  220.    
  221. def callBuild(xstart, xend, zstart, zend, y, level):
  222.     for x in range(xstart, xend):
  223.         for z in range(zstart, zend):
  224.             xEdge = ((x - 1) % 16 == 0 and x != xend - 1)
  225.             zEdge = ((z - 1) % 16 == 0 and z != zend - 1)
  226.             if xEdge and zEdge:
  227.                 #setBlock(x, y + 1, z, 1, 0, level)
  228.                 type = random.randint(1,10)
  229.                 if type == 10:
  230.                     createDirtLot(x, z, y, level)
  231.                 elif type == 9:
  232.                     createFlowerLot(x, z, y, level)
  233.                 else:
  234.                     createSkyscraper(x, z, y, level)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement