Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Made by @QuantumWarpCode.
- # Feel free to modify and use this filter however you wish.
- # If you do, please give credit to Elopus, Elopus001, or @QuantumWarpCode.
- # Effectively, treat this as a Creative Commons Attribution liscense.
- # Procedural Skyscraper Generator
- # Version : 1
- # Last Updated: 6/15/2015
- from pymclevel import alphaMaterials, MCSchematic, TileEntity
- import random
- from math import ceil, floor, sqrt
- displayName = "Procedural Metropolis Generator - V1"
- inputs = [
- (
- ("Setup", "title"),
- ("Type", (
- "City",
- "Skyscraper",
- "Outside"
- )),
- ("Ground Level", 17)
- ),
- (
- ("Nature Blocks", "title"),
- ("Air", alphaMaterials[0, 0]),
- ("Grass", alphaMaterials[2, 0]),
- ("Dirt", alphaMaterials[3, 1]),
- ("Topsoil", alphaMaterials[3,0]),
- ("Ground", alphaMaterials[1, 0]),
- ("Bedrock", alphaMaterials[7, 0]),
- ("Hedge", alphaMaterials[18, 7])
- ),
- (
- ("Building Blocks", "title"),
- ("Sidewalk", alphaMaterials[43, 0]),
- ("Wall", alphaMaterials[98, 0]),
- ("Floor", alphaMaterials[1, 6]),
- ("Ceiling", alphaMaterials[5, 5]),
- ("Glass", alphaMaterials[102, 0])
- )
- ]
- type = "City"
- xZero = 0
- yZero = 0
- zZero = 0
- xMax = 0
- yMax = 0
- zMax = 0
- air = 0, 0
- grass = 2, 0
- dirt = 3, 1
- topsoil = 3, 0
- ground = 1, 0
- bedrock = 7, 0
- hedge = 18, 7
- sidewalk = 43, 0
- wall = 98, 0
- flooring = 1, 6
- ceiling = 5, 5
- glass = 102, 0
- def setBlock(x, y, z, block, schematic, derelict = False):
- if derelict == False or random.randint(1,5) == 1:
- output = ""
- if schematic.blockAt(x, y, z) != 0:
- output = output + "Overwriting " + str(schematic.blockAt(x, y, z)) + " by "
- output = output + "Creating " + str(block) + " at " + str(x) + ", " + str(y) + ", " + str(z)
- print output
- schematic.setBlockAt(x, y, z, block.ID)
- schematic.setBlockDataAt(x, y, z, block.blockData)
- def setBlockFixed(x, y, z, id, data, schematic, derelict = False):
- if derelict == False or random.randint(1,5) == 1:
- output = ""
- if schematic.blockAt(x, y, z) != 0:
- output = output + "Overwriting " + str(schematic.blockAt(x, y, z)) + " by "
- output = output + "Creating " + str(id) + " " + str(data) + " at " + str(x) + ", " + str(y) + ", " + str(z)
- print output
- schematic.setBlockAt(x, y, z, id)
- schematic.setBlockDataAt(x, y, z, data)
- def setBlockRelative(x, y, z, block, schematic):
- global xZero, yZero, zZero
- print("Creating ", block, " at ", x + xZero, " ", y + yZero, " ", z + zZero)
- schematic.setBlockAt(x + xZero, y + yZero, z + zZero, block.ID)
- schematic.setBlockDataAt(x + xZero, y + yZero, z + zZero, block.blockData)
- def setRectangle(xStart, xEnd, y, zStart, zEnd, block, schematic):
- for x in range(xStart, xEnd):
- for z in range(zStart, zEnd):
- setBlock(x, y, z, block, schematic)
- def setFilledRectangle(xStart, xEnd, y, zStart, zEnd, block, block2, schematic):
- for x in range(xStart, xEnd):
- for z in range(zStart, zEnd):
- if x == xStart or x == xEnd - 1 or z == zStart or z == zEnd - 1:
- setBlock(x, y, z, block, schematic)
- else:
- setBlock(x, y, z, block2, schematic)
- def setCornerHollowRectangle(xStart, xEnd, y, zStart, zEnd, block, block2, schematic):
- for x in range(xStart, xEnd):
- for z in range(zStart, zEnd):
- if (x == xStart or x == xEnd - 1) and (z == zStart or z == zEnd - 1):
- setBlock(x, y, z, block, schematic)
- elif x == xStart or x == xEnd - 1 or z == zStart or z == zEnd - 1:
- setBlock(x, y, z, block2, schematic)
- def setHollowRectangle(xStart, xEnd, y, zStart, zEnd, block, schematic):
- for x in range(xStart, xEnd):
- for z in range(zStart, zEnd):
- if x == xStart or x == xEnd - 1 or z == zStart or z == zEnd - 1:
- setBlock(x, y, z, block, schematic)
- def setCube(xStart, xEnd, yStart, yEnd, zStart, zEnd, block, schematic):
- for x in range(xStart, xEnd):
- for y in range(yStart, yEnd):
- for z in range(zStart, zEnd):
- setBlock(x, y, z, block, schematic)
- def setGround(xStart, xEnd, yStart, yEnd, zStart, zEnd, groundLevel, schematic):
- setRectangle(xStart, xEnd, yStart, zStart, zEnd, bedrock, schematic)
- setCube(xStart, xEnd, yStart + 1, groundLevel - 5, zStart, zEnd, ground, schematic)
- setCube(xStart, xEnd, groundLevel - 5, groundLevel, zStart, zEnd, topsoil, schematic)
- setRectangle(xStart + 1, xEnd - 1, groundLevel, zStart + 1, zEnd - 1, grass, schematic)
- setHollowRectangle(xStart, xEnd, groundLevel, zStart, zEnd, sidewalk, schematic)
- def setSkyscraper(xStart, xEnd, yStart, yEnd, zStart, zEnd, groundLevel, schematic, style = 1):
- global air, ground, grass, topsoil, bedrock, hedge, sidewalk, wall, ceiling, flooring, glass
- maxHeight = yEnd - groundLevel
- groundHeight = groundLevel - yStart
- maxFloors = ((maxHeight - 2) - ((maxHeight - 2) % 5)) / 5
- maxBasements = ((groundHeight - 2) - ((groundHeight - 2) % 5)) / 5
- floors = random.randint(1, maxFloors)
- basements = random.randint(0, maxBasements)
- bottom = groundLevel - (basements * 5)
- if xEnd - xStart > 16 and zEnd - zStart > 16:
- lawnSize = random.randint(2, 6)
- else:
- lawnSize = random.randint(2, 4)
- if (xEnd - xStart) % 2 == 1:
- xOdd = True
- else:
- xOdd = False
- if (zEnd - zStart) % 2 == 1:
- zOdd = True
- else:
- zOdd = False
- if style == 1:
- if xOdd == True:
- ladderSupportX = ((xEnd - xStart - 1) / 2) + xStart
- else:
- ladderSupportX = ((xEnd - xStart - 1) / 2) + xStart
- if zOdd == True:
- ladderSupportZ = ((zEnd - zStart - 1) / 2) + zStart
- else:
- ladderSupportZ = ((zEnd - zStart - 1) / 2) + zStart
- if random.randint(1, 2) == 1:
- ladderSupportX = int (ceil(ladderSupportX))
- else:
- ladderSupportX = int (floor(ladderSupportX))
- if random.randint(1, 2) == 1:
- ladderSupportZ = int (ceil(ladderSupportZ))
- else:
- ladderSupportZ = int (floor(ladderSupportZ))
- ladderR = random.randint(1, 4)
- if ladderR == 1:
- ladderX = ladderSupportX - 1
- ladderZ = ladderSupportZ
- ladderData = 4
- elif ladderR == 2:
- ladderX = ladderSupportX + 1
- ladderZ = ladderSupportZ
- ladderData = 5
- elif ladderR == 3:
- ladderX = ladderSupportX
- ladderZ = ladderSupportZ - 1
- ladderData = 2
- else:
- ladderX = ladderSupportX
- ladderZ = ladderSupportZ + 1
- ladderData = 3
- for y in range(bottom, groundLevel + (floors * 5)):
- if y == bottom:
- setFilledRectangle(xStart + lawnSize, xEnd - lawnSize, y, zStart + lawnSize, zEnd - lawnSize, wall, flooring, schematic)
- elif y == bottom + (floors * 5) - 1:
- setFilledRectangle(xStart + lawnSize, xEnd - lawnSize, y, zStart + lawnSize, zEnd - lawnSize, wall, flooring, schematic)
- setBlockFixed(ladderX, y, ladderZ, 65, ladderData, schematic)
- elif (y - bottom) % 5 == 0:
- setFilledRectangle(xStart + lawnSize, xEnd - lawnSize, y, zStart + lawnSize, zEnd - lawnSize, wall, flooring, schematic)
- setBlock(ladderSupportX, y, ladderSupportZ, wall, schematic)
- setBlockFixed(ladderX, y, ladderZ, 65, ladderData, schematic)
- elif (y - bottom) % 5 == 4:
- setFilledRectangle(xStart + lawnSize, xEnd - lawnSize, y, zStart + lawnSize, zEnd - lawnSize, wall, ceiling, schematic)
- setBlock(ladderSupportX, y, ladderSupportZ, wall, schematic)
- setBlockFixed(ladderX, y, ladderZ, 65, ladderData, schematic)
- elif y < groundLevel:
- setFilledRectangle(xStart + lawnSize, xEnd - lawnSize, y, zStart + lawnSize, zEnd - lawnSize, wall, air, schematic)
- setBlock(ladderSupportX, y, ladderSupportZ, wall, schematic)
- setBlockFixed(ladderX, y, ladderZ, 65, ladderData, schematic)
- else:
- setCornerHollowRectangle(xStart + lawnSize, xEnd - lawnSize, y, zStart + lawnSize, zEnd - lawnSize, wall, glass, schematic)
- setBlock(ladderSupportX, y, ladderSupportZ, wall, schematic)
- setBlockFixed(ladderX, y, ladderZ, 65, ladderData, schematic)
- setHollowRectangle(xStart + lawnSize, xEnd - lawnSize, groundLevel + (floors * 5), zStart + lawnSize, zEnd - lawnSize, wall, schematic)
- if lawnSize >= 4:
- if random.randint(1, 3) == 1:
- setHollowRectangle(xStart + 2, xEnd - 2, groundLevel + 1, zStart + 2, zEnd - 2, hedge, schematic)
- doors = random.randint(1, 15)
- if doors == 1 or doors == 5 or doors == 7 or doors == 9 or doors == 11 or doors == 12 or doors == 13 or doors == 15:
- if xOdd == True:
- setRectangle(((xEnd - xStart - 1) / 2) + xStart - 1, ((xEnd - xStart - 1) / 2) + xStart + 2, groundLevel, zStart + 1, zStart + lawnSize, sidewalk, schematic)
- setRectangle(((xEnd - xStart - 1) / 2) + xStart - 1, ((xEnd - xStart - 1) / 2) + xStart + 2, groundLevel + 1, zStart + 1, zStart + lawnSize + 1, air, schematic)
- setRectangle(((xEnd - xStart - 1) / 2) + xStart - 1, ((xEnd - xStart - 1) / 2) + xStart + 2, groundLevel + 2, zStart + 1, zStart + lawnSize + 1, air, schematic)
- else:
- setRectangle(((xEnd - xStart) / 2) + xStart - 1, ((xEnd - xStart) / 2) + xStart + 1, groundLevel, zStart + 1, zStart + lawnSize, sidewalk, schematic)
- setRectangle(((xEnd - xStart) / 2) + xStart - 1, ((xEnd - xStart) / 2) + xStart + 1, groundLevel + 1, zStart + 1, zStart + lawnSize + 1, air, schematic)
- setRectangle(((xEnd - xStart) / 2) + xStart - 1, ((xEnd - xStart) / 2) + xStart + 1, groundLevel + 2, zStart + 1, zStart + lawnSize + 1, air, schematic)
- if doors == 2 or doors == 5 or doors == 8 or doors == 10 or doors == 11 or doors == 12 or doors == 14 or doors == 15:
- if xOdd == True:
- setRectangle(((xEnd - xStart - 1) / 2) + xStart - 1, ((xEnd - xStart - 1) / 2) + xStart + 2, groundLevel, zEnd - lawnSize, zEnd - 1, sidewalk, schematic)
- setRectangle(((xEnd - xStart - 1) / 2) + xStart - 1, ((xEnd - xStart - 1) / 2) + xStart + 2, groundLevel + 1, zEnd - lawnSize - 1, zEnd - 1, air, schematic)
- setRectangle(((xEnd - xStart - 1) / 2) + xStart - 1, ((xEnd - xStart - 1) / 2) + xStart + 2, groundLevel + 2, zEnd - lawnSize - 1, zEnd - 1, air, schematic)
- else:
- setRectangle(((xEnd - xStart) / 2) + xStart - 1, ((xEnd - xStart) / 2) + xStart + 1, groundLevel, zEnd - lawnSize, zEnd - 1, sidewalk, schematic)
- setRectangle(((xEnd - xStart) / 2) + xStart - 1, ((xEnd - xStart) / 2) + xStart + 1, groundLevel + 1, zEnd - lawnSize - 1, zEnd - 1, air, schematic)
- setRectangle(((xEnd - xStart) / 2) + xStart - 1, ((xEnd - xStart) / 2) + xStart + 1, groundLevel + 2, zEnd - lawnSize - 1, zEnd - 1, air, schematic)
- if doors == 3 or doors == 6 or doors == 7 or doors == 10 or doors == 11 or doors == 13 or doors == 14 or doors == 15:
- if zOdd == True:
- setRectangle(xStart + 1, xStart + lawnSize, groundLevel,((zEnd - zStart - 1) / 2) + zStart - 1, ((zEnd - zStart - 1) / 2) + zStart + 2, sidewalk, schematic)
- setRectangle(xStart + 1, xStart + lawnSize + 1, groundLevel + 1,((zEnd - zStart - 1) / 2) + zStart - 1, ((zEnd - zStart - 1) / 2) + zStart + 2, air, schematic)
- setRectangle(xStart + 1, xStart + lawnSize + 1, groundLevel + 2,((zEnd - zStart - 1) / 2) + zStart - 1, ((zEnd - zStart - 1) / 2) + zStart + 2, air, schematic)
- else:
- setRectangle(xStart + 1, xStart + lawnSize, groundLevel,((zEnd - zStart) / 2) + zStart - 1, ((zEnd - zStart) / 2) + zStart + 1, sidewalk, schematic)
- setRectangle(xStart + 1, xStart + lawnSize + 1, groundLevel + 1,((zEnd - zStart) / 2) + zStart - 1, ((zEnd - zStart) / 2) + zStart + 1, air, schematic)
- setRectangle(xStart + 1, xStart + lawnSize + 1, groundLevel + 2,((zEnd - zStart) / 2) + zStart - 1, ((zEnd - zStart) / 2) + zStart + 1, air, schematic)
- if doors == 4 or doors == 6 or doors == 8 or doors == 9 or doors == 12 or doors == 13 or doors == 14 or doors == 15:
- if zOdd == True:
- setRectangle(xEnd - lawnSize, xEnd - 1, groundLevel,((zEnd - zStart - 1) / 2) + zStart - 1, ((zEnd - zStart - 1) / 2) + zStart + 2, sidewalk, schematic)
- setRectangle(xEnd - lawnSize - 1, xEnd - 1, groundLevel + 1,((zEnd - zStart - 1) / 2) + zStart - 1, ((zEnd - zStart - 1) / 2) + zStart + 2, air, schematic)
- setRectangle(xEnd - lawnSize - 1, xEnd - 1, groundLevel + 2,((zEnd - zStart - 1) / 2) + zStart - 1, ((zEnd - zStart - 1) / 2) + zStart + 2, air, schematic)
- else:
- setRectangle(xEnd - lawnSize, xEnd - 1, groundLevel,((zEnd - zStart) / 2) + zStart - 1, ((zEnd - zStart) / 2) + zStart + 1, sidewalk, schematic)
- setRectangle(xEnd - lawnSize - 1, xEnd - 1, groundLevel + 1,((zEnd - zStart) / 2) + zStart - 1, ((zEnd - zStart) / 2) + zStart + 1, air, schematic)
- setRectangle(xEnd - lawnSize - 1, xEnd - 1, groundLevel + 2,((zEnd - zStart) / 2) + zStart - 1, ((zEnd - zStart) / 2) + zStart + 1, air, schematic)
- def perform(level, box, options):
- type = options["Type"]
- global xZero, yZero, zZero, xMax, yMax, zMax
- xZero = box.minx
- yZero = box.miny
- zZero = box.minz
- xMax = box.maxx
- yMax = box.maxy
- zMax = box.maxz
- global air, bedrock, ground, grass, dirt, topsoil, hedge, sidewalk, wall, ceiling, flooring, glass
- air = options["Air"]
- grass = options["Grass"]
- dirt = options["Dirt"]
- topsoil = options["Topsoil"]
- ground = options["Ground"]
- bedrock = options["Bedrock"]
- hedge = options["Hedge"]
- sidewalk = options["Sidewalk"]
- wall = options["Wall"]
- ceiling = options["Ceiling"]
- flooring = options["Floor"]
- glass = options["Glass"]
- groundLevel = options["Ground Level"]
- if type == "City":
- print("City")
- elif type == "Skyscraper":
- print("Skyscraper")
- setGround(xZero, xMax, yZero, yMax, zZero, zMax, yZero + groundLevel - 1, level)
- setSkyscraper(xZero, xMax, yZero, yMax, zZero, zMax, yZero + groundLevel - 1, level)
- if type == "Outside" or type == "City":
- for y in range(yZero, yZero + groundLevel):
- if y == yZero:
- setHollowRectangle(xZero, xMax, y, zZero, zMax, bedrock, level)
- elif y < yZero + groundLevel - 6:
- setHollowRectangle(xZero, xMax, y, zZero, zMax, ground, level)
- elif y < yZero + groundLevel - 1:
- setHollowRectangle(xZero, xMax, y, zZero, zMax, topsoil, level)
- else:
- setHollowRectangle(xZero, xMax, y, zZero, zMax, sidewalk, level)
- level.markDirtyBox(box)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement