Advertisement
QuantumWarpCode

MCEdit Skyscraper Generator

Jun 22nd, 2016
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 13.76 KB | None | 0 0
  1. # Made by @QuantumWarpCode.
  2. # Feel free to modify and use this filter however you wish.
  3. # If you do, please give credit to Elopus, Elopus001, or @QuantumWarpCode.
  4. # Effectively, treat this as a Creative Commons Attribution liscense.
  5.  
  6. # Procedural Skyscraper Generator
  7. # Version : 1
  8. # Last Updated: 6/15/2015
  9.  
  10. from pymclevel import alphaMaterials, MCSchematic, TileEntity
  11. import random
  12. from math import ceil, floor, sqrt
  13.  
  14. displayName = "Procedural Metropolis Generator - V1"
  15.  
  16. inputs = [
  17.     (
  18.         ("Setup", "title"),
  19.         ("Type", (
  20.             "City",
  21.             "Skyscraper",
  22.             "Outside"
  23.         )),
  24.         ("Ground Level", 17)
  25.     ),
  26.     (
  27.         ("Nature Blocks", "title"),
  28.         ("Air", alphaMaterials[0, 0]),
  29.         ("Grass", alphaMaterials[2, 0]),
  30.         ("Dirt", alphaMaterials[3, 1]),
  31.         ("Topsoil", alphaMaterials[3,0]),
  32.         ("Ground", alphaMaterials[1, 0]),
  33.         ("Bedrock", alphaMaterials[7, 0]),
  34.         ("Hedge", alphaMaterials[18, 7])
  35.     ),
  36.     (
  37.         ("Building Blocks", "title"),
  38.         ("Sidewalk", alphaMaterials[43, 0]),
  39.         ("Wall", alphaMaterials[98, 0]),
  40.         ("Floor", alphaMaterials[1, 6]),
  41.         ("Ceiling", alphaMaterials[5, 5]),
  42.         ("Glass", alphaMaterials[102, 0])
  43.     )
  44. ]
  45.  
  46. type = "City"
  47. xZero = 0
  48. yZero = 0
  49. zZero = 0
  50. xMax = 0
  51. yMax = 0
  52. zMax = 0
  53.  
  54. air = 0, 0
  55. grass = 2, 0
  56. dirt = 3, 1
  57. topsoil = 3, 0
  58. ground = 1, 0
  59. bedrock = 7, 0
  60. hedge = 18, 7
  61.  
  62. sidewalk = 43, 0
  63. wall = 98, 0
  64. flooring = 1, 6
  65. ceiling = 5, 5
  66. glass = 102, 0
  67.  
  68. def setBlock(x, y, z, block, schematic, derelict = False):
  69.     if derelict == False or random.randint(1,5) == 1:
  70.         output = ""
  71.         if schematic.blockAt(x, y, z) != 0:
  72.             output = output + "Overwriting " + str(schematic.blockAt(x, y, z)) + " by "
  73.         output = output + "Creating " + str(block) + " at " + str(x) + ", " + str(y) + ", " + str(z)
  74.         print output
  75.         schematic.setBlockAt(x, y, z, block.ID)
  76.         schematic.setBlockDataAt(x, y, z, block.blockData)
  77.  
  78. def setBlockFixed(x, y, z, id, data, schematic, derelict = False):
  79.     if derelict == False or random.randint(1,5) == 1:
  80.         output = ""
  81.         if schematic.blockAt(x, y, z) != 0:
  82.             output = output + "Overwriting " + str(schematic.blockAt(x, y, z)) + " by "
  83.         output = output + "Creating " + str(id) + " " + str(data) + " at " + str(x) + ", " + str(y) + ", " + str(z)
  84.         print output
  85.         schematic.setBlockAt(x, y, z, id)
  86.         schematic.setBlockDataAt(x, y, z, data)
  87.  
  88. def setBlockRelative(x, y, z, block, schematic):
  89.     global xZero, yZero, zZero
  90.     print("Creating ", block, " at ", x + xZero, " ", y + yZero, " ", z + zZero)
  91.     schematic.setBlockAt(x + xZero, y + yZero, z + zZero, block.ID)
  92.     schematic.setBlockDataAt(x + xZero, y + yZero, z + zZero, block.blockData)
  93.  
  94. def setRectangle(xStart, xEnd, y, zStart, zEnd, block, schematic):
  95.     for x in range(xStart, xEnd):
  96.         for z in range(zStart, zEnd):
  97.             setBlock(x, y, z, block, schematic)
  98.  
  99. def setFilledRectangle(xStart, xEnd, y, zStart, zEnd, block, block2, schematic):
  100.     for x in range(xStart, xEnd):
  101.         for z in range(zStart, zEnd):
  102.             if x == xStart or x == xEnd - 1 or z == zStart or z == zEnd - 1:
  103.                 setBlock(x, y, z, block, schematic)
  104.             else:
  105.                 setBlock(x, y, z, block2, schematic)
  106.  
  107. def setCornerHollowRectangle(xStart, xEnd, y, zStart, zEnd, block, block2, schematic):
  108.     for x in range(xStart, xEnd):
  109.         for z in range(zStart, zEnd):
  110.             if (x == xStart or x == xEnd - 1) and (z == zStart or z == zEnd - 1):
  111.                 setBlock(x, y, z, block, schematic)
  112.             elif x == xStart or x == xEnd - 1 or z == zStart or z == zEnd - 1:
  113.                 setBlock(x, y, z, block2, schematic)
  114.  
  115. def setHollowRectangle(xStart, xEnd, y, zStart, zEnd, block, schematic):
  116.     for x in range(xStart, xEnd):
  117.         for z in range(zStart, zEnd):
  118.             if x == xStart or x == xEnd - 1 or z == zStart or z == zEnd - 1:
  119.                 setBlock(x, y, z, block, schematic)
  120.  
  121. def setCube(xStart, xEnd, yStart, yEnd, zStart, zEnd, block, schematic):
  122.     for x in range(xStart, xEnd):
  123.         for y in range(yStart, yEnd):
  124.             for z in range(zStart, zEnd):
  125.                 setBlock(x, y, z, block, schematic)
  126.  
  127. def setGround(xStart, xEnd, yStart, yEnd, zStart, zEnd, groundLevel, schematic):
  128.     setRectangle(xStart, xEnd, yStart, zStart, zEnd, bedrock, schematic)
  129.     setCube(xStart, xEnd, yStart + 1, groundLevel - 5, zStart, zEnd, ground, schematic)
  130.     setCube(xStart, xEnd, groundLevel - 5, groundLevel, zStart, zEnd, topsoil, schematic)
  131.     setRectangle(xStart + 1, xEnd - 1, groundLevel, zStart + 1, zEnd - 1, grass, schematic)
  132.     setHollowRectangle(xStart, xEnd, groundLevel, zStart, zEnd, sidewalk, schematic)
  133.  
  134. def setSkyscraper(xStart, xEnd, yStart, yEnd, zStart, zEnd, groundLevel, schematic, style = 1):
  135.     global air, ground, grass, topsoil, bedrock, hedge, sidewalk, wall, ceiling, flooring, glass
  136.    
  137.     maxHeight = yEnd - groundLevel
  138.     groundHeight = groundLevel - yStart
  139.     maxFloors = ((maxHeight - 2) - ((maxHeight - 2) % 5)) / 5
  140.     maxBasements = ((groundHeight - 2) - ((groundHeight - 2) % 5)) / 5
  141.    
  142.     floors = random.randint(1, maxFloors)
  143.     basements = random.randint(0, maxBasements)
  144.     bottom = groundLevel - (basements * 5)
  145.     if xEnd - xStart > 16 and zEnd - zStart > 16:
  146.         lawnSize = random.randint(2, 6)
  147.     else:
  148.         lawnSize = random.randint(2, 4)
  149.    
  150.     if (xEnd - xStart) % 2 == 1:
  151.         xOdd = True
  152.     else:
  153.         xOdd = False
  154.     if (zEnd - zStart) % 2 == 1:
  155.         zOdd = True
  156.     else:
  157.         zOdd = False
  158.    
  159.     if style == 1:
  160.         if xOdd == True:
  161.             ladderSupportX = ((xEnd - xStart - 1) / 2) + xStart
  162.         else:
  163.             ladderSupportX = ((xEnd - xStart - 1) / 2) + xStart
  164.         if zOdd == True:
  165.             ladderSupportZ = ((zEnd - zStart - 1) / 2) + zStart
  166.         else:
  167.             ladderSupportZ = ((zEnd - zStart - 1) / 2) + zStart
  168.         if random.randint(1, 2) == 1:
  169.             ladderSupportX = int (ceil(ladderSupportX))
  170.         else:
  171.             ladderSupportX = int (floor(ladderSupportX))
  172.         if random.randint(1, 2) == 1:
  173.             ladderSupportZ = int (ceil(ladderSupportZ))
  174.         else:
  175.             ladderSupportZ = int (floor(ladderSupportZ))
  176.        
  177.         ladderR = random.randint(1, 4)
  178.         if ladderR == 1:
  179.             ladderX = ladderSupportX - 1
  180.             ladderZ = ladderSupportZ
  181.             ladderData = 4
  182.         elif ladderR == 2:
  183.             ladderX = ladderSupportX + 1
  184.             ladderZ = ladderSupportZ
  185.             ladderData = 5
  186.         elif ladderR == 3:
  187.             ladderX = ladderSupportX
  188.             ladderZ = ladderSupportZ - 1
  189.             ladderData = 2
  190.         else:
  191.             ladderX = ladderSupportX
  192.             ladderZ = ladderSupportZ + 1
  193.             ladderData = 3
  194.        
  195.         for y in range(bottom, groundLevel + (floors * 5)):
  196.             if y == bottom:
  197.                 setFilledRectangle(xStart + lawnSize, xEnd - lawnSize, y, zStart + lawnSize, zEnd - lawnSize, wall, flooring, schematic)
  198.             elif y == bottom + (floors * 5) - 1:
  199.                 setFilledRectangle(xStart + lawnSize, xEnd - lawnSize, y, zStart + lawnSize, zEnd - lawnSize, wall, flooring, schematic)
  200.                 setBlockFixed(ladderX, y, ladderZ, 65, ladderData, schematic)
  201.             elif (y - bottom) % 5 == 0:
  202.                 setFilledRectangle(xStart + lawnSize, xEnd - lawnSize, y, zStart + lawnSize, zEnd - lawnSize, wall, flooring, schematic)
  203.                 setBlock(ladderSupportX, y, ladderSupportZ, wall, schematic)
  204.                 setBlockFixed(ladderX, y, ladderZ, 65, ladderData, schematic)
  205.             elif (y - bottom) % 5 == 4:
  206.                 setFilledRectangle(xStart + lawnSize, xEnd - lawnSize, y, zStart + lawnSize, zEnd - lawnSize, wall, ceiling, schematic)
  207.                 setBlock(ladderSupportX, y, ladderSupportZ, wall, schematic)
  208.                 setBlockFixed(ladderX, y, ladderZ, 65, ladderData, schematic)
  209.             elif y < groundLevel:
  210.                 setFilledRectangle(xStart + lawnSize, xEnd - lawnSize, y, zStart + lawnSize, zEnd - lawnSize, wall, air, schematic)
  211.                 setBlock(ladderSupportX, y, ladderSupportZ, wall, schematic)
  212.                 setBlockFixed(ladderX, y, ladderZ, 65, ladderData, schematic)
  213.             else:
  214.                 setCornerHollowRectangle(xStart + lawnSize, xEnd - lawnSize, y, zStart + lawnSize, zEnd - lawnSize, wall, glass, schematic)
  215.                 setBlock(ladderSupportX, y, ladderSupportZ, wall, schematic)
  216.                 setBlockFixed(ladderX, y, ladderZ, 65, ladderData, schematic)
  217.         setHollowRectangle(xStart + lawnSize, xEnd - lawnSize, groundLevel + (floors * 5), zStart + lawnSize, zEnd - lawnSize, wall, schematic)
  218.        
  219.         if lawnSize >= 4:
  220.             if random.randint(1, 3) == 1:
  221.                 setHollowRectangle(xStart + 2, xEnd - 2, groundLevel + 1, zStart + 2, zEnd - 2, hedge, schematic)
  222.        
  223.         doors = random.randint(1, 15)
  224.         if doors  == 1 or doors == 5 or doors == 7 or doors == 9 or doors == 11 or doors == 12 or doors == 13 or doors == 15:
  225.             if xOdd == True:
  226.                 setRectangle(((xEnd - xStart - 1) / 2) + xStart - 1, ((xEnd - xStart - 1) / 2) + xStart + 2, groundLevel, zStart + 1, zStart + lawnSize, sidewalk, schematic)
  227.                 setRectangle(((xEnd - xStart - 1) / 2) + xStart - 1, ((xEnd - xStart - 1) / 2) + xStart + 2, groundLevel + 1, zStart + 1, zStart + lawnSize + 1, air, schematic)
  228.                 setRectangle(((xEnd - xStart - 1) / 2) + xStart - 1, ((xEnd - xStart - 1) / 2) + xStart + 2, groundLevel + 2, zStart + 1, zStart + lawnSize + 1, air, schematic)
  229.             else:
  230.                 setRectangle(((xEnd - xStart) / 2) + xStart - 1, ((xEnd - xStart) / 2) + xStart + 1, groundLevel, zStart + 1, zStart + lawnSize, sidewalk, schematic)
  231.                 setRectangle(((xEnd - xStart) / 2) + xStart - 1, ((xEnd - xStart) / 2) + xStart + 1, groundLevel + 1, zStart + 1, zStart + lawnSize + 1, air, schematic)
  232.                 setRectangle(((xEnd - xStart) / 2) + xStart - 1, ((xEnd - xStart) / 2) + xStart + 1, groundLevel + 2, zStart + 1, zStart + lawnSize + 1, air, schematic)
  233.         if doors == 2 or doors == 5 or doors == 8 or doors == 10 or doors == 11 or doors == 12 or doors == 14 or doors == 15:
  234.             if xOdd == True:
  235.                 setRectangle(((xEnd - xStart - 1) / 2) + xStart - 1, ((xEnd - xStart - 1) / 2) + xStart + 2, groundLevel, zEnd - lawnSize, zEnd - 1, sidewalk, schematic)
  236.                 setRectangle(((xEnd - xStart - 1) / 2) + xStart - 1, ((xEnd - xStart - 1) / 2) + xStart + 2, groundLevel + 1, zEnd - lawnSize - 1, zEnd - 1, air, schematic)
  237.                 setRectangle(((xEnd - xStart - 1) / 2) + xStart - 1, ((xEnd - xStart - 1) / 2) + xStart + 2, groundLevel + 2, zEnd - lawnSize - 1, zEnd - 1, air, schematic)
  238.             else:
  239.                 setRectangle(((xEnd - xStart) / 2) + xStart - 1, ((xEnd - xStart) / 2) + xStart + 1, groundLevel, zEnd - lawnSize, zEnd - 1, sidewalk, schematic)
  240.                 setRectangle(((xEnd - xStart) / 2) + xStart - 1, ((xEnd - xStart) / 2) + xStart + 1, groundLevel + 1, zEnd - lawnSize - 1, zEnd - 1, air, schematic)
  241.                 setRectangle(((xEnd - xStart) / 2) + xStart - 1, ((xEnd - xStart) / 2) + xStart + 1, groundLevel + 2, zEnd - lawnSize - 1, zEnd - 1, air, schematic)
  242.         if doors == 3 or doors == 6 or doors == 7 or doors == 10 or doors == 11 or doors == 13 or doors == 14 or doors == 15:
  243.             if zOdd == True:
  244.                 setRectangle(xStart + 1, xStart + lawnSize, groundLevel,((zEnd - zStart - 1) / 2) + zStart - 1, ((zEnd - zStart - 1) / 2) + zStart + 2, sidewalk, schematic)
  245.                 setRectangle(xStart + 1, xStart + lawnSize + 1, groundLevel + 1,((zEnd - zStart - 1) / 2) + zStart - 1, ((zEnd - zStart - 1) / 2) + zStart + 2, air, schematic)
  246.                 setRectangle(xStart + 1, xStart + lawnSize + 1, groundLevel + 2,((zEnd - zStart - 1) / 2) + zStart - 1, ((zEnd - zStart - 1) / 2) + zStart + 2, air, schematic)
  247.             else:
  248.                 setRectangle(xStart + 1, xStart + lawnSize, groundLevel,((zEnd - zStart) / 2) + zStart - 1, ((zEnd - zStart) / 2) + zStart + 1, sidewalk, schematic)
  249.                 setRectangle(xStart + 1, xStart + lawnSize + 1, groundLevel + 1,((zEnd - zStart) / 2) + zStart - 1, ((zEnd - zStart) / 2) + zStart + 1, air, schematic)
  250.                 setRectangle(xStart + 1, xStart + lawnSize + 1, groundLevel + 2,((zEnd - zStart) / 2) + zStart - 1, ((zEnd - zStart) / 2) + zStart + 1, air, schematic)
  251.         if doors == 4 or doors == 6 or doors == 8 or doors == 9 or doors == 12 or doors == 13 or doors == 14 or doors == 15:
  252.             if zOdd == True:
  253.                 setRectangle(xEnd - lawnSize, xEnd - 1, groundLevel,((zEnd - zStart - 1) / 2) + zStart - 1, ((zEnd - zStart - 1) / 2) + zStart + 2, sidewalk, schematic)
  254.                 setRectangle(xEnd - lawnSize - 1, xEnd - 1, groundLevel + 1,((zEnd - zStart - 1) / 2) + zStart - 1, ((zEnd - zStart - 1) / 2) + zStart + 2, air, schematic)
  255.                 setRectangle(xEnd - lawnSize - 1, xEnd - 1, groundLevel + 2,((zEnd - zStart - 1) / 2) + zStart - 1, ((zEnd - zStart - 1) / 2) + zStart + 2, air, schematic)
  256.             else:
  257.                 setRectangle(xEnd - lawnSize, xEnd - 1, groundLevel,((zEnd - zStart) / 2) + zStart - 1, ((zEnd - zStart) / 2) + zStart + 1, sidewalk, schematic)
  258.                 setRectangle(xEnd - lawnSize - 1, xEnd - 1, groundLevel + 1,((zEnd - zStart) / 2) + zStart - 1, ((zEnd - zStart) / 2) + zStart + 1, air, schematic)
  259.                 setRectangle(xEnd - lawnSize - 1, xEnd - 1, groundLevel + 2,((zEnd - zStart) / 2) + zStart - 1, ((zEnd - zStart) / 2) + zStart + 1, air, schematic)
  260.  
  261. def perform(level, box, options):
  262.     type = options["Type"]
  263.    
  264.     global xZero, yZero, zZero, xMax, yMax, zMax
  265.    
  266.     xZero = box.minx
  267.     yZero = box.miny
  268.     zZero = box.minz
  269.     xMax = box.maxx
  270.     yMax = box.maxy
  271.     zMax = box.maxz
  272.    
  273.     global air, bedrock, ground, grass, dirt, topsoil, hedge, sidewalk, wall, ceiling, flooring, glass
  274.    
  275.     air = options["Air"]
  276.     grass = options["Grass"]
  277.     dirt = options["Dirt"]
  278.     topsoil = options["Topsoil"]
  279.     ground = options["Ground"]
  280.     bedrock = options["Bedrock"]
  281.     hedge = options["Hedge"]
  282.    
  283.     sidewalk = options["Sidewalk"]
  284.     wall = options["Wall"]
  285.     ceiling = options["Ceiling"]
  286.     flooring = options["Floor"]
  287.     glass = options["Glass"]
  288.    
  289.     groundLevel = options["Ground Level"]
  290.    
  291.     if type == "City":
  292.         print("City")
  293.     elif type == "Skyscraper":
  294.         print("Skyscraper")
  295.         setGround(xZero, xMax, yZero, yMax, zZero, zMax, yZero + groundLevel - 1, level)
  296.         setSkyscraper(xZero, xMax, yZero, yMax, zZero, zMax, yZero + groundLevel - 1, level)
  297.     if type == "Outside" or type == "City":
  298.         for y in range(yZero, yZero + groundLevel):
  299.             if y == yZero:
  300.                 setHollowRectangle(xZero, xMax, y, zZero, zMax, bedrock, level)
  301.             elif y < yZero + groundLevel - 6:
  302.                 setHollowRectangle(xZero, xMax, y, zZero, zMax, ground, level)
  303.             elif y < yZero + groundLevel - 1:
  304.                 setHollowRectangle(xZero, xMax, y, zZero, zMax, topsoil, level)
  305.             else:
  306.                 setHollowRectangle(xZero, xMax, y, zZero, zMax, sidewalk, level)
  307.    
  308.     level.markDirtyBox(box)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement