def insert_road(current_node_x, current_node_z, current_node_y, height_difference, level): # Will create a pillar of road material for node_y in range(current_node_y + height_difference, current_node_y + 1): utilityFunctions.setBlock(level, gravel, current_node_x, node_y, current_node_z)
def clearTerrain(level, box): for x in range(box.minx, box.maxx): # let's assume we won't build things taller than 50 blocks for y in range(box.miny, box.miny + 50): for z in range(box.minz, box.maxz): utilityFunctions.setBlock(level, (alphaMaterials.Air.ID, 0), x, y, z)
def makeRoof(level, box, options, height): # make sloped roof smallx = box.minx bigx = box.maxx - 1 addedHeight = 1 while smallx <= bigx: for z in range(box.minz, box.maxz): if z == box.minz or z == box.maxz - 1: utilityFunctions.setBlockToGround( level, (options["Roof Material"].ID, 0), smallx, box.miny + height + addedHeight, z, box.miny) utilityFunctions.setBlockToGround( level, (options["Roof Material"].ID, 0), bigx, box.miny + height + addedHeight, z, box.miny) else: utilityFunctions.setBlock(level, (options["Roof Material"].ID, 0), smallx, box.miny + height + addedHeight - 1, z) utilityFunctions.setBlock(level, (options["Roof Material"].ID, 0), bigx, box.miny + height + addedHeight - 1, z) smallx += 1 bigx -= 1 addedHeight += 1
def generateDispenser(level, box, y): x=box.minx z=box.minz uf.setBlock(level, (41,0),x,y,z)#Gold level.setBlockAt(x,y,z+3,76) #RedTorch level.setBlockDataAt(x, y, z+3, 4) level.setBlockAt(x+1,y, z+1, 41) level.setBlockAt(x+1,y,z+2, 55) #Redstone level.setBlockAt(x+1, y, z+3, 94) #Repeater level.setBlockDataAt(x+1, y, z+3, 11) level.setBlockAt(x+1,y,z+4,55) level.setBlockAt(x+2, y, z+3, 55) level.setBlockAt(x+2, y, z+4, 55) level.setBlockAt(x+3, y, z+4, 55) level.setBlockAt(x+4, y, z+4, 41) level.setBlockAt(x+1,y+1,z+1, 55) level.setBlockAt(x+1,y+1,z+2, 0) level.setBlockAt(x+4, y+1, z+4, 23) #Dispenser level.setBlockDataAt(x+4,y+1, z+4, 1) level.setBlockAt(x+1,y+2,z, 70) #Pressure plate
def place_floor(self): # puts the floor down # technically this should be in the translator, but I'm lazy for x in range(self.box.minx, self.box.maxx): for z in range(self.box.minz, self.box.maxz): utilityFunctions.setBlock(self.level, (5, 0), x, self.box.miny, z)
def __activate_one_repeater(level, box): # type: (MCLevel, TransformBox) -> None repeatr_pos = [] repeatr_id = Block['unpowered_repeater'].ID for x, y, z in box.positions: block_id = level.blockAt(x, y, z) if block_id == repeatr_id: repeatr_pos.append((x, y, z)) x, y, z = box.minx + 1, box.miny, box.maxz - 1 repeater = Block[repeatr_id, level.blockDataAt(x, y, z)] dir_str = str(repeater.Blockstate[1]['facing']) dir_com = Direction.from_string(dir_str) # activate a repeater and preparing its tile tick block = Block['Redstone Repeater (Powered, Delay 4, {})'.format( str(-dir_com))] WindmillGenerator.__repeater_tile_tick(level, x, y, z, True) setBlock(level, (block.ID, block.blockData), x, y, z) # activate the command block following the previous repeater x += 1 command_block_entity = level.getTileEntitiesInBox( TransformBox((x, y, z), (1, 1, 1)))[0] command_block_entity['powered'].value = True # power command block # prepare tile tick for the repeater following the command block x += 1 WindmillGenerator.__repeater_tile_tick(level, x, y, z, False)
def generate(self, level, origin): # type: (MCLevel, (int, int, int)) -> None # dimensions x0, y0, z0 = origin __network = zeros((self.width, self.length), dtype=int) # block states stony_palette = [4, 13, 1] stony_probs = [0.75, 0.20, 0.05] grassy_palette = [208] grassy_probs = [1] sandy_palette = [] sandy_probs = [] for road_block in self.road_blocks: width = self.__get_road_width(road_block) for x in range(max(0, road_block.x - width + 1), min(self.width, road_block.x + width - 1)): for z in range(max(0, road_block.z - width + 1), min(self.width, road_block.z + width - 1)): distance = abs(road_block.x - x) + abs( road_block.z - z) #Norme 1 prob = 1 - distance / (8 * width) #A calibrer if not bernouilli(prob): block = choice(grassy_palette) __network[x][z] = block x0, y0, z0 = self.__all_maps.box.origin for x in range(self.width): for z in range(self.length): if __network[x][z] > 0: y = max(63, self.__all_maps.height_map[x][z]) setBlock(level, (__network[x][z], 0), x0 + x, y, z0 + z)
def construct_vaulted_roof(level, coords, biome, height): minx, minz, miny, maxx, maxz = get_coords(coords) roof_block = BlockUtils.get_roof_block(biome) for i in range(-1, abs(maxx - minx) / 3): for x in range(minx, maxx): for z in range(minz + i, maxz - i): utilityFunctions.setBlock(level, roof_block, x, height + i, z)
def generateCeiling(level, floor, buildingHeightInfo, options): print "generating ceiling" for x in range(floor.minx, floor.maxx+1): for z in range(floor.minz, floor.maxz+1): utilityFunctions.setBlock(level, (options["Material"].ID, 0), x, buildingHeightInfo[2] + buildingHeightInfo[0], z) # scan all the blocks above me and make them air (all the way to maxy) for y in range(buildingHeightInfo[2] + buildingHeightInfo[0] + 1, 256): utilityFunctions.setBlock(level, (0, 0), x, y, z)
def place_door(level, coords, biome, door_coords): minx, minz, miny, maxx, maxz = get_coords(coords) door_block = BlockUtils.get_door_block(biome) # Place door utilityFunctions.setBlock(level, door_block, door_coords[0], miny + 1, door_coords[1]) utilityFunctions.setBlock(level, door_block, door_coords[0], miny + 2, door_coords[1])
def makePillar(level,highestTile,options): height = options["Height"] if (options["Use Custom Material"]==True): material = options["Material"].ID else: material = highestTile.material for step in range(height): utilityFunctions.setBlock(level, (material, 0), highestTile.x, highestTile.y+step+1, highestTile.z)
def build(level, xStart, zStart, baseHeight, blockRegister): for block in blockRegister: if block['type'] == None: utilityFunctions.setBlock(level, (block['id'], block['data']), xStart + block['x'], baseHeight + block['y'], zStart + block['z']) else: b = BlockDictionary.Block(block['type'], block['direction'], block['verticalAllignment']) blockIdentifier = BlockDictionary.getBlockIdentifier(b) utilityFunctions.setBlock(level, (blockIdentifier[0], blockIdentifier[1]), xStart + block['x'], baseHeight + block['y'], zStart + block['z'])
def build_roads(list_of_coordinates, level): list_of_used_coordinates = [] for roads in list_of_coordinates: for coordinates in roads: direction_lib = [5, 4, 3, 2] # 5 = East, 4 = West, 3 = South, 2 = North reverse_list = coordinates[::-1] start_node = reverse_list[0] # Get the start coordinate parent_node = coordinates[0] # To check for altitude change check_start_node( start_node, direction_lib, level ) # Need to know if start node is level with the house coordinate for current_node in coordinates: if current_node not in list_of_used_coordinates: # Will skip goal nodes which have been inserted direction_lib = [ 5, 4, 3, 2 ] # 5 = East, 4 = West, 3 = South, 2 = North parent_node_y = parent_node[2] current_node_x = current_node[0] current_node_z = current_node[1] current_node_y = current_node[2] height_difference = calculate_difference( parent_node_y, current_node_y) utilityFunctions.setBlock(level, gravel, current_node_x, current_node_y, current_node_z) list_of_used_coordinates.append(current_node) # If the height difference is equal or larger than 2, ladder it needed if abs(height_difference) >= 2: parent_node_x = parent_node[0] parent_node_z = parent_node[1] length_difference = calculate_difference( current_node_x, parent_node_x) width_difference = calculate_difference( current_node_z, parent_node_z) direction_node = current_node # Going downhill if height_difference < 0: direction_lib = [ 4, 5, 2, 3 ] # 4 = West, 5 = East, 2 = North, 3 = South direction_node = parent_node # Going uphill # Making sure there are blocks where the ladder is created insert_road(current_node_x, current_node_z, current_node_y, height_difference, level) height_difference = abs(height_difference) insert_ladder(length_difference, width_difference, height_difference, direction_node, direction_lib, level) parent_node = current_node del list_of_used_coordinates[:]
def paintComponents(level, tileMap, colorMap, material): for i in range(len(tileMap)): for j in range(len(tileMap[i])): if (tileMap[i][j].material != WATER): tile = tileMap[i][j] print "painting {} {} with ".format(i, j, material) utilityFunctions.setBlock(level, (material + colorMap[i][j] - 1, 0), tile.x, tile.y, tile.z)
def construct_pillars(level, coords, biome, height): minx, minz, miny, maxx, maxz = get_coords(coords) pillar_block = BlockUtils.get_beam_block(biome) for y in range(height, 0, -1): for x in [minx, maxx - 1]: for z in [minz, maxz - 1]: block = level.blockAt(x, y, z) if block in surface_blocks or block == 9: utilityFunctions.setBlock(level, pillar_block, x, y, z)
def water_in_well(level, length_of_building, width_of_building, box_height, building): for x in range(building.x + BUFFER + 1, building.x + length_of_building + BUFFER - 1): for z in range(building.z + BUFFER + 1, building.z + width_of_building + BUFFER - 1): utilityFunctions.setBlock(level, cobble, x, box_height, z) utilityFunctions.setBlockToGround(level, water, x, box_height + 2, z, box_height + 1)
def build_floor(level, length_of_building, width_of_building, height_of_building, box_height, building): for x in range(building.x + BUFFER, building.x + length_of_building + BUFFER): for z in range(building.z + BUFFER, building.z + width_of_building + BUFFER): utilityFunctions.setBlock(level, wood, x, box_height, z) utilityFunctions.setBlock(level, cobble, x, box_height + height_of_building, z)
def construct_floor_and_flat_roof(level, coords, biome, height): minx, minz, miny, maxx, maxz = get_coords(coords) roof_block = BlockUtils.get_roof_block(biome) floor_block = BlockUtils.get_floor_block(biome) # roof and floor for x in range(minx, maxx): for z in range(minz, maxz): utilityFunctions.setBlock(level, roof_block, x, height, z) utilityFunctions.setBlock(level, floor_block, x, miny, z)
def setBlock(level, id, x, y, z): utilityFunctions.setBlock(level, id, x, y, z) if id[0] == 0: # If placed an air-block if y == _heightMap[x][z]: for newY in xrange(y - 1, -1, -1): otherId = level.blockAt(x, newY, z) if isGround(otherId): _heightMap[x][z] = newY break else: # If placed a non-air block if y > _heightMap[x][z]: _heightMap[x][z] = y
def remove_blocks_in_box(level, coords): minx = coords[0][0] minz = coords[0][1] miny = coords[0][2] maxx = coords[1][0] maxz = coords[1][1] maxy = coords[1][2] # Sets every block in box to air for y in range(miny, maxy): for x in range(minx, maxx): for z in range(minz, maxz): utilityFunctions.setBlock(level, (0, 0), x, y, z)
def construct_walls(level, coords, biome, height): minx, minz, miny, maxx, maxz = get_coords(coords) wall_block = BlockUtils.get_wall_block(biome) # walls for y in range(height, miny, -1): for x in range(minx, maxx): for z in range(minz, maxz): # Skip columns since they should be a different block if (x == minx and z == minz) or (x == maxx-1 and z == minz) or \ (x == minx and z == maxz-1) or (x == maxx-1 and z == maxz-1): continue if x == maxx - 1 or z == maxz - 1 or x == minx or z == minz: utilityFunctions.setBlock(level, wall_block, x, y, z)
def construct_square_window(level, coords, biome, face=0): x = coords[0] y = coords[1] z = coords[2] window_block = BlockUtils.get_window_block(biome) if face == 0: for i in range(x, x + 2): for j in range(y, y - 2, -1): utilityFunctions.setBlock(level, window_block, i, j, z) elif face == 1: for i in range(z, z + 2): for j in range(y, y - 2, -1): utilityFunctions.setBlock(level, window_block, x, j, i)
def getHeight(level, x, z, house_plot=True): global maxy, miny, foliage for y in xrange(maxy, miny, -1): blockID = level.blockAt(x, y, z) if blockID not in ([0] + foliage): if not house_plot: utilityFunctions.setBlock(level, (0, 0), x, y + 1, z) return y elif blockID in foliage and house_plot: clearEnvironmentArea(level, [[x, y, z]]) # utilityFunctions.setBlock(level, (0, 0), x, y, z) return 0
def createPillars(level, floor, options): cornerBlockStarts = [] ycoords = [] # similarly to fences, we need to countdown on each of the four corners and find the block where the ground starts, then start building pillars above that height midpointFloorHeight = 0 for y in xrange(floor.maxy, floor.miny - 1, -1): # get this block tempBlock = level.blockAt(floor.minx, y, floor.minz) if tempBlock != 0: cornerBlockStarts.append((floor.minx, y + 1, floor.minz)) break for y in xrange(floor.maxy, floor.miny - 1, -1): # get this block tempBlock = level.blockAt(floor.minx, y, floor.maxz) if tempBlock != 0: cornerBlockStarts.append((floor.minx, y + 1, floor.maxz)) break for y in xrange(floor.maxy, floor.miny - 1, -1): # get this block tempBlock = level.blockAt(floor.maxx, y, floor.minz) if tempBlock != 0: cornerBlockStarts.append((floor.maxx, y + 1, floor.minz)) break for y in xrange(floor.maxy, floor.miny - 1, -1): # get this block tempBlock = level.blockAt(floor.maxx, y, floor.maxz) if tempBlock != 0: cornerBlockStarts.append((floor.maxx, y + 1, floor.maxz)) break # now we have all four corners. for each, pick a random y value between 5 and 45, and build up using stone ystartCoordMax = -10000 for cornerstone in cornerBlockStarts: midpointFloorHeight += cornerstone[1] if (cornerstone[1] > ystartCoordMax): ystartCoordMax = cornerstone[1] pillarheight = random.randint(5, 45) for y in range(0, pillarheight): utilityFunctions.setBlock(level, (options["Material"].ID, 0), cornerstone[0], cornerstone[1] + y, cornerstone[2]) if (y == pillarheight - 1): # add y to our y coords, which will be used to determine building height for the roof ycoords.append(y) allYs = 0 for ycoord in ycoords: allYs += ycoord yavg = allYs / 4 midpointFloorHeight = midpointFloorHeight / 4 # print("Average pillar height: ", yavg) return (yavg, ystartCoordMax, midpointFloorHeight)
def place(self, level, box, options): only_main_roads = True if only_main_roads: road = np.array( Image.open('story_viz/procedural_road/mycity.png').convert( 'L').resize((144, 192))) road = road == 0 for x_offset, row in enumerate(road): for z_offset, block in enumerate(row): if block == 1: utilityFunctions.setBlock(level, (1, 0), box.minx + x_offset, box.miny, box.minz + z_offset)
def buildRoads(level, box): for x in range(box.minx, box.maxx): utilityFunctions.setBlock(level, (1, 0), x, box.miny, box.maxz) utilityFunctions.setBlock(level, (1, 0), x, box.miny, box.minz) for z in range(box.minz, box.maxz): utilityFunctions.setBlock(level, (1, 0), box.maxx, box.miny, z) utilityFunctions.setBlock(level, (1, 0), box.minx, box.miny, z)
def modify_area(height_map, solution, level): use_average = False for building in solution: """use the average height to create the ground for the building to be build on. This might cause unreachable buildings in hill areas""" if use_average: target_height = find_average_height(building, height_map) else: target_height = find_most_common_height_around_the_building(height_map, building) reference_block = get_reference_block(level, building, target_height) for x in xrange(building.x, building.x + buildings[building.type_of_house]["xLength"]): for z in xrange(building.z, building.z + buildings[building.type_of_house]["zWidth"]): zero_difference = False while not zero_difference: current_difference = target_height - height_map[x, z][0] """ if there is no difference, set a block (used because the else statement does not put a block there when it gets to the correct floor) else if target_height is bigger than the height_map location else the target_height is smaller than the height_map location, clear everything down """ if current_difference == 0: utilityFunctions.setBlock(level, (reference_block, 0), x, height_map[x, z][0], z) zero_difference = True # Break elif current_difference > 0: if reference_block == aM.Grass.ID: utilityFunctions.setBlock(level, (aM.Dirt.ID, 0), x, height_map[x, z][0], z) else: utilityFunctions.setBlock(level, (reference_block, 0), x, height_map[x, z][0], z) height_map[x, z][0] += 1 else: for y in xrange(MAX_HEIGHT, target_height, -1): utilityFunctions.setBlock(level, (aM.Air.ID, 0), x, height_map[x, z][0], z) height_map[x, z][0] = target_height
def perform(level, box, options): z_len = box.maxz - box.minz x_len = box.maxx - box.minx surfaceLevel = [[0 for x in range(z_len)] for x in range(x_len)] biomes = [[0 for x in range(z_len)] for x in range(x_len)] for x in xrange(x_len): for z in xrange(z_len): world_x = x + box.minx world_z = z + box.minz surfaceLevel[x][z] = getSurfaceLevel(level, box, world_x, world_z) biomes[x][z] = level.getChunk( (world_x) // 16, (world_z) // 16).Biomes[(world_z) % 16, (world_x) % 16] utilityFunctions.setBlock(level, (biomes[x][z], 0), world_x, surfaceLevel[x][z] + 1, world_z)
def paste_nbt(level, box, nbt_file_name): _structure = StructureNBT(get_project_path() + '/structures/' + nbt_file_name) _width, _height, _length = _structure.Size x0, y0, z0 = box.minx, box.miny, box.minz # iterates over coordinates in the structure, copy to level for xs, ys, zs in product(xrange(_width), xrange(_height), xrange(_length)): block = _structure.Blocks[xs, ys, zs] # (id, data) tuple if ys == 14: print(xs, ys, zs, block) if block != Block['Structure Void'].ID: xd, yd, zd = x0 + xs, y0 + ys, z0 + zs # coordinates in the level: translation of the structure setBlock(level, block, xd, yd, zd)
def construct(self, level, coords, door_coords, surface): minx = coords[0][0] minz = coords[0][1] maxx = coords[1][0] maxz = coords[1][1] block = surface.surface_map[coords[0][0]][coords[0][1]] miny = block.height biome = block.biome_id hedge_block = BlockUtils.get_hedge_block(biome) new_coords = shrink_building_lot(coords, miny) if door_coords[0] > minx: door_x = door_coords[0] - 1 else: door_x = door_coords[0] + 1 if door_coords[1] > minz: door_z = door_coords[1] - 1 else: door_z = door_coords[1] + 1 new_door_coords = (door_x, door_z) building = BasicBuilding() building.construct(level, new_coords, new_door_coords, surface) # ring basic building in hedge minx = surface.to_real_x(minx) minz = surface.to_real_z(minz) maxx = surface.to_real_x(maxx) maxz = surface.to_real_z(maxz) for x in range(minx, maxx): for z in range(minz, maxz): if x == maxx - 1 or z == maxz - 1 or x == minx or z == minz: if x != surface.to_real_x( door_coords[0]) or z != surface.to_real_z( door_coords[1]): utilityFunctions.setBlock(level, hedge_block, x, miny + 1, z) else: # Remove hedges around door to ensure there is an entrance if level.blockAt(x + 1, miny + 1, z) == hedge_block[0]: utilityFunctions.setBlock(level, blocks['Air'], x + 1, miny + 1, z) if level.blockAt(x, miny + 1, z + 1) == hedge_block[0]: utilityFunctions.setBlock(level, blocks['Air'], x, miny + 1, z + 1) if level.blockAt(x - 1, miny + 1, z) == hedge_block[0]: utilityFunctions.setBlock(level, blocks['Air'], x - 1, miny + 1, z) if level.blockAt(x, miny + 1, z - 1) == hedge_block[0]: utilityFunctions.setBlock(level, blocks['Air'], x, miny + 1, z - 1)