def placeHeightBlocks(level, surface, x, z): height = surface.surfaceMap[x][z].height i = (height - 60) / 7 if i < 0: i = 0 elif i >= length: i = length - 1 setBlock(level, surface, x, 250, z, d[i])
def paintStraightPaths(level, surface, paths, blockType): straightPaths = [] for path in paths: length = len(path) p1 = path[0] p2 = path[length - 1] straightPaths.append(getStraightPath(p1.x, p1.z, p2.x, p2.z)) for path in straightPaths: for point in path: setBlock(level, surface, point.x, 250, point.z, blockType)
def buildOuterPathTile(level, surface, point, height): if not isWithinBorder(surface, point.x - surface.xStart, point.z - surface.zStart): return False surface.surfaceMap[point.x - surface.xStart][point.z - surface.zStart].isOccupied = True if level.blockAt(point.x, height, point.z) == 43: return False if level.blockAt(point.x, height, point.z) == 0: i = 0 while level.blockAt(point.x, height - i, point.z) == 0: if level.blockAt(point.x, height - 1 - i, point.z) == 43: return False i += 1 if level.blockAt(point.x, height + 1, point.z) == 4: setBlock(level, None, point.x, height + 1, point.z, 44, 3) if level.blockAt(point.x, height - 1, point.z) == 4: setBlock(level, None, point.x, height, point.z, 44, 3) else: setBlock(level, None, point.x, height, point.z, 4, 0) clearAboveTile(level, point, height) i = 1 while level.blockAt(point.x, height - i, point.z) == 0: setBlock(level, None, point.x, height - i, point.z, 98, 0) i += 1 return True
def buildFoundation(level, blueprint): if not blueprint.base: return xStart = blueprint.base.xStart zStart = blueprint.base.zStart xEnd = blueprint.base.xStart + blueprint.base.xLength - 1 zEnd = blueprint.base.zStart + blueprint.base.zLength - 1 for x in range(xStart, xEnd + 1): for z in range(zStart, zEnd + 1): i = 1 while not isSurfaceBlock(level, x, blueprint.baseHeight - i, z): blockId = 1 if i == 1: blockId = 98 if (x == xStart or x == xEnd) and (z == zStart or z == zEnd): blockId = 98 setBlock(level, None, x, blueprint.baseHeight - i, z, blockId) i += 1
def buildField(level, surface, prop): y = prop.height + 1 for x in range(prop.xStart + 1, prop.xEnd - 1): for z in range(prop.zStart + 1, prop.zEnd - 1): setBlock(level, surface, x, y, z, 60) setBlock(level, surface, x, y + 1, z, 59, 7) setBlock(level, surface, prop.xStart + prop.xLength / 2, y, prop.zStart + prop.zLength / 2, 9) setBlock(level, surface, prop.xStart + prop.xLength / 2, y + 1, prop.zStart + prop.zLength / 2, 0)
def perform(level, box, options): surface = Surface(box.minx, box.minz, box.maxx, box.maxz) calculateHeightMapAdv(level, surface) calculateSteepnessMap(surface) calculateWaterPlacement(level, surface) sections = calculateSections(surface, 1, 15) for section in sections: calculateSectionMid(surface, section) for x in range(surface.xLength): for z in range(surface.zLength): layer = surface.surfaceMap[x][z].layer # block = layerBlocks[min([layer + 1, len(layerBlocks) - 1])] block = layerBlocks[(layer + 1) % len(layerBlocks)] if surface.surfaceMap[x][z].isWater or surface.surfaceMap[x][ z].sectionId == -1: block = (35, 15) setBlock(level, surface, x, 249, z, 2, 0) setBlock(level, surface, x, 250, z, block)
def paintSections(level, surface, smallLandSections, mediumLandSections, bigLandSections, waterSections): for x in range(surface.xLength): for z in range(surface.zLength): setBlock(level, surface, x, 250, z, 35, 15) for s in smallLandSections: for p in s.points: setBlock(level, surface, p.x, 250, p.z, 35, 5) for s in mediumLandSections: for p in s.points: setBlock(level, surface, p.x, 250, p.z, 2) for s in bigLandSections: for p in s.points: setBlock(level, surface, p.x, 250, p.z, 35, 13) for s in waterSections: for p in s.points: setBlock(level, surface, p.x, 250, p.z, 35, 11)
def build(level, blueprint): for block in blueprint.blockRegister: x = blueprint.point.x z = blueprint.point.z b = None if block.get('type'): b = BlockDictionary.Block(block['type'], block['direction'], block['verticalAllignment']) else: b = BlockDictionary.getBlock(block['id'], block['data']) if not b: setBlock(level, None, x + int(block['x']), blueprint.baseHeight + int(block['y']), z + int(block['z']), block['id'], block['data']) else: blockIdentifier = BlockDictionary.getBlockIdentifier(b) setBlock(level, None, x + int(block['x']), blueprint.baseHeight + int(block['y']), z + int(block['z']), blockIdentifier[0], blockIdentifier[1]) if blueprint.buildFoundation: buildFoundation(level, blueprint)
def buildPathway(level, surface, xStart, zStart, xEnd, zEnd): path = getPath(surface, xStart, zStart, xEnd, zEnd) for p in path: height = surface.surfaceMap[p.x][p.z].height setBlock(level, surface, p.x, height + 1, p.z, 0) setBlock(level, surface, p.x, height + 2, p.z, 0) if not surface.surfaceMap[p.x][p.z].isOccupied: setBlock(level, surface, p.x, height, p.z, 4)
def paintPathPoints(level, surface, habitatSections): for section in habitatSections: for x in [section.xMid - 1, section.xMid, section.xMid + 1]: for z in [section.zMid - 1, section.zMid, section.zMid + 1]: setBlock(level, surface, x, 251, z, 2) setBlock(level, surface, x, 252, z, 38) for p in section.pathConnectionPoints: for x in [p.x - 1, p.x, p.x + 1]: for z in [p.z - 1, p.z, p.z + 1]: setBlock(level, surface, x, 251, z, 35, 1)
def buildSides(level, surface, prop): # Corners y = prop.height + 1 for p in [(prop.xStart, prop.zStart), (prop.xStart, prop.zEnd - 1), (prop.xEnd - 1, prop.zStart), (prop.xEnd - 1, prop.zEnd - 1)]: setBlock(level, surface, p[0], y, p[1], materials["wood"]["default"]) setBlock(level, surface, p[0], y + 1, p[1], materials["wood"]["default"]) setBlock(level, surface, p[0], y + 2, p[1], materials["torch"]["default"]) buildNorthSide(level, surface, prop) buildEastSide(level, surface, prop) buildSouthSide(level, surface, prop) buildWestSide(level, surface, prop)
def buildWindows(level, surface, prop): if prop.doorDirection != "NORTH": x = prop.xStart + 3 i = 0 while x < prop.xEnd - 3: if i % 2 == 0: setBlock(level, surface, x, prop.height + 3, prop.zStart + 1, materials["glass_pane"]["default"]) x += 1 i += 1 if prop.doorDirection != "EAST": z = prop.zStart + 3 i = 0 while z < prop.zEnd - 3: if i % 2 == 0: setBlock(level, surface, prop.xEnd - 2, prop.height + 3, z, materials["glass_pane"]["default"]) z += 1 i += 1 if prop.doorDirection != "SOUTH": x = prop.xStart + 3 i = 0 while x < prop.xEnd - 3: if i % 2 == 0: setBlock(level, surface, x, prop.height + 3, prop.zEnd - 2, materials["glass_pane"]["default"]) x += 1 i += 1 if prop.doorDirection != "WEST": z = prop.zStart + 3 i = 0 while z < prop.zEnd - 3: if i % 2 == 0: setBlock(level, surface, prop.xStart + 1, prop.height + 3, z, materials["glass_pane"]["default"]) z += 1 i += 1
def placeBiomeBlocks(level, surface, x, z): biomeId = surface.surfaceMap[x][z].biomeId blockType = d.get(biomeId, (35, 15)) setBlock(level, surface, x, 250, z, blockType)
def buildEastSide(level, surface, prop): y = prop.height + 1 if prop.doorDirection == "EAST": setBlock(level, surface, prop.xEnd - 1, y, prop.zStart + 1, materials["wood_planks"]["default"]) setBlock(level, surface, prop.xEnd - 1, y + 1, prop.zStart + 1, materials["fence"]["default"]) setBlock(level, surface, prop.xEnd - 1, y, prop.zEnd - 2, materials["wood_planks"]["default"]) setBlock(level, surface, prop.xEnd - 1, y + 1, prop.zEnd - 2, materials["fence"]["default"]) for z in range(prop.zStart + 2, prop.zEnd - 2): if isSurfaceBlock(level, prop.xEnd + surface.xStart, y, z + surface.zStart): setBlock(level, surface, prop.xEnd - 1, y, z, materials["wood_planks"]["default"]) else: setBlock( level, surface, prop.xEnd - 1, y, z, materials["wood_planks"]["directions"]["west"]["bottom"]) else: for z in range(prop.zStart + 1, prop.zEnd - 1): setBlock(level, surface, prop.xEnd - 1, y, z, materials["wood_planks"]["default"]) setBlock(level, surface, prop.xEnd - 1, y + 1, z, materials["fence"]["default"])
def buildNorthSide(level, surface, prop): y = prop.height + 1 if prop.doorDirection == "NORTH": setBlock(level, surface, prop.xStart + 1, y, prop.zStart, materials["wood_planks"]["default"]) setBlock(level, surface, prop.xStart + 1, y + 1, prop.zStart, materials["fence"]["default"]) setBlock(level, surface, prop.xEnd - 2, y, prop.zStart, materials["wood_planks"]["default"]) setBlock(level, surface, prop.xEnd - 2, y + 1, prop.zStart, materials["fence"]["default"]) for x in range(prop.xStart + 2, prop.xEnd - 2): if isSurfaceBlock(level, x + surface.xStart, y, prop.zStart - 1 + surface.zStart): setBlock(level, surface, x, y, prop.zStart, materials["wood_planks"]["default"]) else: setBlock( level, surface, x, y, prop.zStart, materials["wood_planks"]["directions"]["south"]["bottom"]) else: for x in range(prop.xStart + 1, prop.xEnd - 1): setBlock(level, surface, x, y, prop.zStart, materials["wood_planks"]["default"]) setBlock(level, surface, x, y + 1, prop.zStart, materials["fence"]["default"])
def clearFarmProperty(level, surface, prop): for x in range(prop.xStart, prop.xEnd): for z in range(prop.zStart, prop.zEnd): for y in range(prop.height + 2, prop.height + 4): removeTree(level, x + surface.xStart, y, z + surface.zStart) setBlock(level, surface, x, y, z, 0)
def paintPaths(level, surface, paths, blockType): for path in paths: for point in path: setBlock(level, surface, point.x, 250, point.z, blockType)
def test(level, surface): length = len(d) for i in range(length): setBlock(level, surface, i, 80, 0, d[i])
def clearAboveTile(level, point, height): for i in range(1, 4): removeTree(level, point.x, height + i, point.z) setBlock(level, None, point.x, height + i, point.z, 0, 0)
def paintFarmProperties(level, surface, farmProperties): for prop in farmProperties: for x in range(prop.xStart, prop.xEnd): for z in range(prop.zStart, prop.zEnd): setBlock(level, surface, x, 250, z, 41)
def paintHouseProperties(level, surface, houseProperties): for prop in houseProperties: for x in range(prop.xStart, prop.xEnd): for z in range(prop.zStart, prop.zEnd): setBlock(level, surface, x, 250, z, 5)
def paintTowerProperties(level, surface, towerSections): for section in towerSections: for x in range(section.xMid - 3, section.xMid + 4): for z in range(section.zMid - 3, section.zMid + 4): setBlock(level, surface, x, 252, z, 35, 10)
def placeSteepnessBlocks(level, surface, x, z): steepness = surface.surfaceMap[x][z].steepness blockType = d.get(steepness, (35, 15)) setBlock(level, surface, x, 250, z, blockType)
def buildWalls(level, surface, prop): # North and south walls for x in range(prop.xStart + 2, prop.xEnd - 2): for y in range(prop.height + 2, prop.height + 5): setBlock(level, surface, x, y, prop.zStart + 1, materials["wood_planks"]["default"]) setBlock(level, surface, x, y, prop.zEnd - 2, materials["wood_planks"]["default"]) # East and west walls for z in range(prop.zStart + 2, prop.zEnd - 2): for y in range(prop.height + 2, prop.height + 5): setBlock(level, surface, prop.xStart + 1, y, z, materials["wood_planks"]["default"]) setBlock(level, surface, prop.xEnd - 2, y, z, materials["wood_planks"]["default"]) # Corners for y in range(prop.height + 2, prop.height + 5): setBlock(level, surface, prop.xStart + 1, y, prop.zStart + 1, materials["wood"]["default"]) setBlock(level, surface, prop.xStart + 1, y, prop.zEnd - 2, materials["wood"]["default"]) setBlock(level, surface, prop.xEnd - 2, y, prop.zStart + 1, materials["wood"]["default"]) setBlock(level, surface, prop.xEnd - 2, y, prop.zEnd - 2, materials["wood"]["default"])
def placeStreetLight(level, surface, point, height): buildablePoint = buildOuterPathTile(level, surface, point, height) if buildablePoint: # Tries to place a tile and if successful place a street light. setBlock(level, None, point.x, height + 1, point.z, 139, 0) setBlock(level, None, point.x, height + 2, point.z, 50, 5)
def buildRoofEW(level, surface, prop): y = prop.height + 5 for z in range(prop.zStart + 2, prop.zEnd - 2): setBlock(level, surface, prop.xStart + 1, y, z, materials["wood"]["directions"]["north"]["top"]) setBlock(level, surface, prop.xEnd - 2, y, z, materials["wood"]["directions"]["north"]["top"]) for x in range(prop.xStart, prop.xEnd): setBlock(level, surface, x, y, prop.zStart, materials["wood_planks"]["directions"]["south"]["bottom"]) setBlock(level, surface, x, y + 1, prop.zStart + 1, materials["wood_planks"]["directions"]["south"]["bottom"]) setBlock(level, surface, x, y, prop.zStart + 1, materials["wood"]["directions"]["east"]["top"]) setBlock(level, surface, x, y, prop.zEnd - 1, materials["wood_planks"]["directions"]["north"]["bottom"]) setBlock(level, surface, x, y + 1, prop.zEnd - 2, materials["wood_planks"]["directions"]["north"]["bottom"]) setBlock(level, surface, x, y, prop.zEnd - 2, materials["wood"]["directions"]["east"]["top"]) for z in range(prop.zStart + 2, prop.zEnd - 2): setBlock(level, surface, x, y + 1, z, materials["wood_planks"]["default"])
def buildDoor(level, surface, prop): if prop.doorDirection == "NORTH": x = prop.xStart + prop.xLength / 2 # Stair if isSurfaceBlock(level, x + surface.xStart, prop.height + 1, prop.zStart - 1 + surface.zStart): setBlock(level, surface, x, prop.height + 1, prop.zStart, materials["stone"]["default"]) else: setBlock(level, surface, x, prop.height + 1, prop.zStart, materials["stone"]["directions"]["south"]["bottom"]) # Door setBlock(level, surface, x, prop.height + 2, prop.zStart + 1, materials["door"]["directions"]["south"]["bottom"]) setBlock(level, surface, x, prop.height + 3, prop.zStart + 1, materials["door"]["directions"]["south"]["top"]) # Torch setBlock(level, surface, x + 1, prop.height + 3, prop.zStart + 2, materials["torch"]["directions"]["south"]["top"]) setBlock(level, surface, x - 1, prop.height + 3, prop.zStart + 2, materials["torch"]["directions"]["south"]["top"]) elif prop.doorDirection == "EAST": z = prop.zStart + prop.zLength / 2 # Stair if isSurfaceBlock(level, prop.xEnd + surface.xStart, prop.height + 1, z + surface.zStart): setBlock(level, surface, prop.xEnd - 1, prop.height + 1, z, materials["stone"]["default"]) else: setBlock(level, surface, prop.xEnd - 1, prop.height + 1, z, materials["stone"]["directions"]["west"]["bottom"]) # Door setBlock(level, surface, prop.xEnd - 2, prop.height + 2, z, materials["door"]["directions"]["west"]["bottom"]) setBlock(level, surface, prop.xEnd - 2, prop.height + 3, z, materials["door"]["directions"]["west"]["top"]) # Torch setBlock(level, surface, prop.xEnd - 3, prop.height + 3, z + 1, materials["torch"]["directions"]["west"]["top"]) setBlock(level, surface, prop.xEnd - 3, prop.height + 3, z - 1, materials["torch"]["directions"]["west"]["top"]) elif prop.doorDirection == "SOUTH": x = prop.xStart + prop.xLength / 2 # Stair if isSurfaceBlock(level, x + surface.xStart, prop.height + 1, prop.zEnd + surface.zStart): setBlock(level, surface, x, prop.height + 1, prop.zEnd - 1, materials["stone"]["default"]) else: setBlock(level, surface, x, prop.height + 1, prop.zEnd - 1, materials["stone"]["directions"]["north"]["bottom"]) # Door setBlock(level, surface, x, prop.height + 2, prop.zEnd - 2, materials["door"]["directions"]["north"]["bottom"]) setBlock(level, surface, x, prop.height + 3, prop.zEnd - 2, materials["door"]["directions"]["north"]["top"]) # Torch setBlock(level, surface, x + 1, prop.height + 3, prop.zEnd - 3, materials["torch"]["directions"]["north"]["top"]) setBlock(level, surface, x - 1, prop.height + 3, prop.zEnd - 3, materials["torch"]["directions"]["north"]["top"]) elif prop.doorDirection == "WEST": z = prop.zStart + prop.zLength / 2 # Stair if isSurfaceBlock(level, prop.xStart - 1 + surface.xStart, prop.height + 1, z + surface.zStart): setBlock(level, surface, prop.xStart, prop.height + 1, z, materials["stone"]["default"]) else: setBlock(level, surface, prop.xStart, prop.height + 1, z, materials["stone"]["directions"]["east"]["bottom"]) # Door setBlock(level, surface, prop.xStart + 1, prop.height + 2, z, materials["door"]["directions"]["east"]["bottom"]) setBlock(level, surface, prop.xStart + 1, prop.height + 3, z, materials["door"]["directions"]["east"]["top"]) # Torch setBlock(level, surface, prop.xStart + 2, prop.height + 3, z + 1, materials["torch"]["directions"]["east"]["top"]) setBlock(level, surface, prop.xStart + 2, prop.height + 3, z - 1, materials["torch"]["directions"]["east"]["top"])
def buildFloor(level, surface, prop): for x in range(prop.xStart + 1, prop.xEnd - 1): for z in range(prop.zStart + 1, prop.zEnd - 1): setBlock(level, surface, x, prop.height + 1, z, materials["stone"]["default"])
def buildAnimalPen(level, surface, prop): # Grass y = prop.height + 1 for x in range(prop.xStart + 1, prop.xEnd - 1): for z in range(prop.zStart + 1, prop.zEnd - 1): setBlock(level, surface, x, y, z, 2) # Fence for x in range(prop.xStart, prop.xEnd): setBlock(level, surface, x, y, prop.zStart, 4) setBlock(level, surface, x, y + 1, prop.zStart, materials["fence"]["default"]) setBlock(level, surface, x, y, prop.zEnd - 1, 4) setBlock(level, surface, x, y + 1, prop.zEnd - 1, materials["fence"]["default"]) for z in range(prop.zStart + 1, prop.zEnd - 1): setBlock(level, surface, prop.xStart, y, z, 4) setBlock(level, surface, prop.xStart, y + 1, z, materials["fence"]["default"]) setBlock(level, surface, prop.xEnd - 1, y, z, 4) setBlock(level, surface, prop.xEnd - 1, y + 1, z, materials["fence"]["default"]) # Torches setBlock(level, surface, prop.xStart, y + 2, prop.zStart, 50, 5) setBlock(level, surface, prop.xStart, y + 2, prop.zEnd - 1, 50, 5) setBlock(level, surface, prop.xEnd - 1, y + 2, prop.zStart, 50, 5) setBlock(level, surface, prop.xEnd - 1, y + 2, prop.zEnd - 1, 50, 5) # Gate if prop.doorDirection == "NORTH": x = prop.xStart + prop.xLength / 2 setBlock(level, surface, x, y + 1, prop.zStart, 107, 0) if isSurfaceBlock(level, x + surface.xStart, y, prop.zStart - 1 + surface.zStart): setBlock(level, surface, x, y, prop.zStart, 4) else: setBlock(level, surface, x, y, prop.zStart, 67, 2) if prop.doorDirection == "EAST": z = prop.zStart + prop.zLength / 2 setBlock(level, surface, prop.xEnd - 1, y + 1, z, 107, 1) if isSurfaceBlock(level, prop.xEnd + surface.xStart, y, z + surface.zStart): setBlock(level, surface, prop.xEnd - 1, y, z, 4) else: setBlock(level, surface, prop.xEnd - 1, y, z, 67, 1) if prop.doorDirection == "SOUTH": x = prop.xStart + prop.xLength / 2 setBlock(level, surface, x, y + 1, prop.zEnd - 1, 107, 2) if isSurfaceBlock(level, x + surface.xStart, y, prop.zEnd + surface.zStart): setBlock(level, surface, x, y, prop.zEnd - 1, 4) else: setBlock(level, surface, x, y, prop.zEnd - 1, 67, 3) if prop.doorDirection == "WEST": z = prop.zStart + prop.zLength / 2 setBlock(level, surface, prop.xStart, y + 1, z, 107, 3) if isSurfaceBlock(level, prop.xStart - 1 + surface.xStart, y, z + surface.zStart): setBlock(level, surface, prop.xStart, y, z, 4) else: setBlock(level, surface, prop.xStart, y, z, 67, 0) # Animals amount = (prop.xLength * prop.zLength) / 12 kind = None a = random.randint(0, 12) if a < 1: kind = "HORSE" elif a < 4: kind = "CHICKEN" elif a < 7: kind = "PIG" elif a < 10: kind = "COW" else: kind = "SHEEP" points = [] for _ in range(amount): points.append(getRandomPoint(surface, prop, points)) if kind == "HORSE": for p in points: placeHorse(level, p.x + surface.xStart, y + 1, p.z + surface.zStart) elif kind == "CHICKEN": for p in points: placeChicken(level, p.x + surface.xStart, y + 1, p.z + surface.zStart) elif kind == "PIG": for p in points: placePig(level, p.x + surface.xStart, y + 1, p.z + surface.zStart) elif kind == "COW": for p in points: placeCow(level, p.x + surface.xStart, y + 1, p.z + surface.zStart) elif kind == "SHEEP": for p in points: placeSheep(level, p.x + surface.xStart, y + 1, p.z + surface.zStart)
def buildCenterPathTile(level, surface, point, height): surface.surfaceMap[point.x - surface.xStart][point.z - surface.zStart].isOccupied = True setBlock(level, None, point.x, height, point.z, 43, 0) clearAboveTile(level, point, height)