Exemple #1
0
def generateRail(matrix, y, x, z, path_material, fence_material, rail_orientation, generateAround = True):
	# Generate the path
	matrix.setValue(y - 2, x, z, path_material)
	matrix.setValue(y - 1, x, z, path_material)
	matrix.setValue(y, x, z, path_material)
	if generateAround:
		(x_modifier, z_modifier) = (1, 0) # default
		if ((rail_orientation == toolbox.Orientation.VERTICAL - 1) or
			(rail_orientation == toolbox.Orientation.WEST - 1) or
			(rail_orientation == toolbox.Orientation.EAST - 1)):
			(x_modifier, z_modifier) = (1, 0)
		elif ((rail_orientation == toolbox.Orientation.HORIZONTAL - 1) or
			(rail_orientation == toolbox.Orientation.NORTH - 1) or
			(rail_orientation == toolbox.Orientation.SOUTH - 1)):
			(x_modifier, z_modifier) = (0, 1)
		matrix.setValue(y - 1, x - x_modifier, z - z_modifier, path_material)
		matrix.setValue(y, x - x_modifier, z - z_modifier, path_material)
		matrix.setValue(y + 1, x - x_modifier, z - z_modifier, fence_material)
		matrix.setValue(y - 1, x + x_modifier, z + z_modifier, path_material)
		matrix.setValue(y, x + x_modifier, z + z_modifier, path_material)
		matrix.setValue(y + 1, x + x_modifier, z + z_modifier, fence_material)
	# Generate the rail
	if isGoldenRail(rail_orientation):
		matrix.setValue(y + 1, x, z, toolbox.getBlockID("golden_rail", rail_orientation))
		if generateAround:
			matrix.setValue(y, x, z, toolbox.getBlockID("redstone_block"))
	else:
		matrix.setValue(y + 1, x, z, toolbox.getBlockID("rail", rail_orientation))
Exemple #2
0
def generateRails(matrix, wooden_materials_kit, height_map, rail_map, x_min,
                  x_max, z_min, z_max, highestPoint):
    for x in range(x_min, x_max + 1):
        for z in range(z_min, z_max + 1):
            if rail_map[x][z] >= 2:
                #logging.info("x:{} z:{} is {} with max rail length {}".format(x, z, rail_map[x][z], max_rail_length))
                ## check rail orientation using neighbouring rails
                binary_orientation_index = getRailOrientation(
                    height_map, rail_map, x, z, x_max, z_max, max_rail_length)

                ## set rail orientation
                rail_orientation = getOrientationFromBinaryIndex(
                    binary_orientation_index)

                ## generate the rail
                #logging.info("Generating a rail (index:{}) in x:{}, z:{}, y:{} with orientation:{}".format(rail_map[x][z], x, z, height_map[x][z], rail_orientation))
                matrix.setValue(height_map[x][z], x, z,
                                wooden_materials_kit["log"])

                ## regular rail
                if binary_orientation_index < 16:
                    matrix.setValue(
                        height_map[x][z] + 1, x, z,
                        toolbox.getBlockID("rail", rail_orientation))
                ## powered rail
                else:
                    matrix.setValue(
                        height_map[x][z] + 1, x, z,
                        toolbox.getBlockID("golden_rail", rail_orientation))
                    matrix.setEntity(height_map[x][z] - 1, x, z,
                                     toolbox.getBlockID("redstone_torch"),
                                     "redstone_torch")
Exemple #3
0
	def buildLight(matrix, h, x, z): #put the light at the position given
		logging.info("Generating light at point {}, {}, {}".format(h+1, x, z))
		try:
			matrix.setValue(h + 1, x, z, light_Pillar)
			matrix.setValue(h + 2, x, z, light_Pillar)
			matrix.setValue(h + 3, x, z, toolbox.getBlockID("redstone_lamp"))
			matrix.setEntity(h + 4, x, z, toolbox.getBlockID("daylight_detector_inverted", 15), "daylight_detector")
		except:
			logging.info("Error when generating light at position : {}, {}, {}".format(h+1, x, z))
Exemple #4
0
def generateSmileyPattern(matrix, wooden_materials_kit, h, x_min, x_max, z_min,
                          z_max):

    ## FENCES
    generateFences(matrix, wooden_materials_kit, h, x_min + 1, x_max - 1,
                   z_min + 1, z_max - 1)

    ## GROUND
    farmlandID = toolbox.getBlockID("farmland")
    carrotsID = toolbox.getBlockID("carrots")
    # fill field with dirt and carrots
    for x in range(x_min + 3, x_max - 2):
        for z in range(z_min + 3, z_max - 2):
            matrix.setValue(h, x, z, farmlandID)
            matrix.setValue(h + 1, x, z, CARROT_ID)

    ## SMILEY
    wheatID = toolbox.getBlockID("wheat")
    waterID = toolbox.getBlockID("water")

    # eyes
    def generateEye(x, z):
        matrix.setValue(h + 1, x, z, wheatID)
        matrix.setValue(h + 1, x, z + 1, wheatID)
        matrix.setValue(h + 1, x + 1, z, wheatID)
        matrix.setValue(h, x + 1, z + 1, waterID)
        matrix.setValue(h + 1, x + 1, z + 1, toolbox.getBlockID("air"))

    # left eye
    generateEye(x_min + 5, z_min + 5)
    # right eye
    generateEye(x_max - 6, z_min + 5)
    # mouth
    for x in range(x_min + 6, x_max - 5):
        matrix.setValue(h + 1, x, z_max - 4, wheatID)
    matrix.setValue(h + 1, x_min + 5, z_max - 5, wheatID)
    matrix.setValue(h + 1, x_max - 5, z_max - 5, wheatID)
    matrix.setValue(h + 1, x_min + 4, z_max - 6, wheatID)
    matrix.setValue(h + 1, x_max - 4, z_max - 6, wheatID)

    ## WATER
    for x in range(x_min + 2, x_max - 1):
        matrix.setValue(h, x, z_max - 2, waterID)
        matrix.setValue(h, x, z_min + 2, waterID)
    for z in range(z_min + 2, z_max - 1):
        matrix.setValue(h, x_max - 2, z, waterID)
        matrix.setValue(h, x_min + 2, z, waterID)
Exemple #5
0
def generatePath_StraightLine(matrix, x_p1, z_p1, x_p2, z_p2, height_map, pavement_Type):
	if pavement_Type == "Grass":
		pavement_Block = toolbox.getBlockID("grass_path")
		light_Pillar = toolbox.getBlockID("oak_fence")
	elif pavement_Type == "Stone":
		pavement_Block = toolbox.getBlockID("stone", 6)
		light_Pillar = toolbox.getBlockID("cobblestone_wall")

	for x in toolbox.twoway_range(x_p1, x_p2):
		h = height_map[x][z_p1]
		h = matrix.getMatrixY(h)
		matrix.setValue(h, x, z_p1, pavement_Block)

	for z in toolbox.twoway_range(z_p1, z_p2):
		h = height_map[x_p2][z]
		h = matrix.getMatrixY(h)
		matrix.setValue(h, x_p2, z, pavement_Block)
		matrix.setValue(h + 1, x_p2, z, toolbox.getBlockID("air"))
Exemple #6
0
def generatePillar(matrix, pillar_material, simple_height_map, train_line_height_map, x, z, direction):
	h = train_line_height_map[x][z] + HEIGHT_FROM_GROUND
	matrix.setValue(h - 4, x + 1, z, toolbox.getBlockID("torch", 1))
	matrix.setValue(h - 4, x - 1, z, toolbox.getBlockID("torch", 2))
	matrix.setValue(h - 4, x, z + 1, toolbox.getBlockID("torch", 3))
	matrix.setValue(h - 4, x, z - 1, toolbox.getBlockID("torch", 4))
	for y in range(simple_height_map[x][z] + 1, h - 2):
		matrix.setValue(y, x, z, pillar_material)
	if direction == 1:
		matrix.setValue(h + 2, x, z - 1, toolbox.getBlockID("torch", 5))
		matrix.setValue(h + 2, x, z + 1, toolbox.getBlockID("torch", 5))
	elif direction == 0:
		matrix.setValue(h + 2, x - 1, z, toolbox.getBlockID("torch", 5))
		matrix.setValue(h + 2, x + 1, z, toolbox.getBlockID("torch", 5))
Exemple #7
0
def generateStation(matrix, wooden_materials_kit, simple_height_map, train_line_height_map, x, z, direction):
	floor_material = wooden_materials_kit["planks"]
	fence_material = wooden_materials_kit["fence"]
	roof_material = wooden_materials_kit["slab"]
	air = toolbox.getBlockID("air", 0)

	initial_position = train_line_height_map[x][z] + HEIGHT_FROM_GROUND

	if direction == 1:
		# base
		matrix.setValue(initial_position + 1, x, z, toolbox.getBlockID("golden_rail", toolbox.Orientation.HORIZONTAL - 1))
		for y in range(simple_height_map[x][z - 1] + 1, initial_position + 1):
			matrix.setValue(y, x, z - 1, toolbox.getBlockID("ladder", 2))
		for y in range(simple_height_map[x][z + 1] + 1, initial_position + 1):
			matrix.setValue(y, x, z + 1, toolbox.getBlockID("ladder", 3))
		for i in range(-1, 2):
			matrix.setValue(initial_position + 1, x + i, z - 1, air)
			matrix.setValue(initial_position + 1, x + i, z + 1, air)
		for i in range(-2, 3):
			matrix.setValue(initial_position, x + i, z - 2, floor_material)
			matrix.setValue(initial_position + 1, x + i, z - 2, fence_material)
			matrix.setValue(initial_position, x + i, z + 2, floor_material)
			matrix.setValue(initial_position + 1, x + i, z + 2, fence_material)

	elif direction == 0:
		# base
		matrix.setValue(initial_position + 1, x, z, toolbox.getBlockID("golden_rail", toolbox.Orientation.VERTICAL - 1))
		for y in range(simple_height_map[x][z - 1] + 1, initial_position + 1):
			matrix.setValue(y, x - 1, z, toolbox.getBlockID("ladder", 4))
		for y in range(simple_height_map[x][z + 1] + 1, initial_position + 1):
			matrix.setValue(y, x + 1, z, toolbox.getBlockID("ladder", 5))
		for i in range(-1, 2):
			matrix.setValue(initial_position + 1, x - 1, z + i, air)
			matrix.setValue(initial_position + 1, x + 1, z + i, air)
		for i in range(-2, 3):
			matrix.setValue(initial_position, x - 2, z + i, floor_material)
			matrix.setValue(initial_position + 1, x - 2, z + i, fence_material)
			matrix.setValue(initial_position, x + 2, z + i, floor_material)
			matrix.setValue(initial_position + 1, x + 2, z + i, fence_material)

	# roof
	for i in range(0, 3):
		matrix.setValue(initial_position + 1 + i, x - 2, z - 2, fence_material)
		matrix.setValue(initial_position + 1 + i, x + 2, z - 2, fence_material)
		matrix.setValue(initial_position + 1 + i, x - 2, z + 2, fence_material)
		matrix.setValue(initial_position + 1 + i, x + 2, z + 2, fence_material)
	for i in range(-2, 3):
		for j in range(-2, 3):
			matrix.setValue(initial_position + 4, x + i, z + j, roof_material)
	for i in range(-1, 2):
		for j in range(-1, 2):
			matrix.setValue(initial_position + 4, x + i, z + j, floor_material)
Exemple #8
0
def generateBasicPattern(matrix,
                         wooden_materials_kit,
                         h,
                         x_min,
                         x_max,
                         z_min,
                         z_max,
                         plant=None):

    ## FENCES
    generateFences(matrix, wooden_materials_kit, h, x_min + 1, x_max - 1,
                   z_min + 1, z_max - 1)

    ## GROUND & CULTURES
    if plant == None:
        # select one random plant for this farm
        plants = [
            toolbox.getBlockID("wheat"),
            toolbox.getBlockID("carrots"),
            toolbox.getBlockID("potatoes")
        ]
        plant = plants[RNG.randint(0, PLANT_SPECIES_NUMBER - 1)]
    # fill field with dirt and the corresponding plant
    farmlandID = toolbox.getBlockID("farmland")
    for x in range(x_min + 3, x_max - 2):
        for z in range(z_min + 3, z_max - 2):
            matrix.setValue(h, x, z, farmlandID)
            matrix.setValue(h + 1, x, z, plant)

    ## WATER
    waterID = toolbox.getBlockID("water")
    for x in range(x_min + 2, x_max - 1):
        matrix.setValue(h, x, z_max - 2, waterID)
        matrix.setValue(h, x, z_min + 2, waterID)
    for z in range(z_min + 2, z_max - 1):
        matrix.setValue(h, x_max - 2, z, waterID)
        matrix.setValue(h, x_min + 2, z, waterID)
Exemple #9
0
def generateEntrance(matrix, wooden_materials_kit, orientation, h_min, door_x,
                     door_z, min_bound, max_bound):
    grass_pathID = toolbox.getBlockID("grass_path")
    if orientation % 2 == 0:
        for z in range(min_bound, max_bound):
            matrix.setValue(h_min, door_x, z, grass_pathID)
            matrix.setValue(h_min, door_x - 1, z, grass_pathID)
            matrix.setValue(h_min, door_x + 1, z, grass_pathID)
    else:
        for x in range(min_bound, max_bound):
            matrix.setValue(h_min, x, door_z, grass_pathID)
            matrix.setValue(h_min, x, door_z - 1, grass_pathID)
            matrix.setValue(h_min, x, door_z + 1, grass_pathID)
    matrix.setValue(h_min + 1, door_x, door_z,
                    (wooden_materials_kit["fence_gate"][0], orientation))
Exemple #10
0
def generateFountain(matrix, h_min, h_max, x_min, x_max, z_min, z_max):
	logger = logging.getLogger("fountain")
	logger.info("Preparation for Fountain generation")

	fountain_material = toolbox.getBlockID("double_stone_slab")

	x_center = (x_min + x_max) / 2
	z_center = (z_min + z_max) / 2
	if (h_min + FOUNTAIN_HEIGHT < h_max): h_max = h_min + FOUNTAIN_HEIGHT
	generateStructure(matrix, logger, fountain_material, h_min, h_max, x_center, z_center)

	f = toolbox.dotdict()
	f.type = "fountain"
	f.lotArea = toolbox.dotdict({"y_min": h_min, "y_max": h_max, "x_min": x_min, "x_max": x_max, "z_min": z_min, "z_max": z_max})
	f.buildArea = toolbox.dotdict({"y_min": h_min, "y_max": h_max, "x_min": x_center - 6, "x_max": x_center + 7, "z_min": z_center - 6, "z_max": z_center + 7})
	f.orientation = "S"
	f.entranceLot = (f.lotArea.x_min, f.lotArea.z_min)
	return f
Exemple #11
0
def generateFences(matrix, wooden_materials_kit, h, x_min, x_max, z_min,
                   z_max):
    oak_logID = wooden_materials_kit["log"]
    oak_fenceID = wooden_materials_kit["fence"]
    torchID = toolbox.getBlockID("torch", 5)
    for x in range(x_min, x_max + 1):
        matrix.setValue(h, x, z_max, oak_logID)
        matrix.setValue(h, x, z_min, oak_logID)
        matrix.setValue(h + 1, x, z_max, oak_fenceID)
        matrix.setValue(h + 1, x, z_min, oak_fenceID)
    for z in range(z_min, z_max + 1):
        matrix.setValue(h, x_max, z, oak_logID)
        matrix.setValue(h, x_min, z, oak_logID)
        matrix.setValue(h + 1, x_max, z, oak_fenceID)
        matrix.setValue(h + 1, x_min, z, oak_fenceID)
    matrix.setValue(h + 2, x_min, z_max, torchID)
    matrix.setValue(h + 2, x_min, z_min, torchID)
    matrix.setValue(h + 2, x_max, z_max, torchID)
    matrix.setValue(h + 2, x_max, z_min, torchID)
Exemple #12
0
def generateCorner(logger, matrix, simple_height_map, train_line_height_map, x, z, x_modifier, z_modifier, path_material, fence_material, pillar_material, rail_orientation):
	y = train_line_height_map[x][z] + HEIGHT_FROM_GROUND
	if (train_line_height_map[x][z] == train_line_height_map[x - x_modifier][z] - 1):
		if (train_line_height_map[x][z] != train_line_height_map[x][z - z_modifier] + 1):
			train_line_height_map[x][z] += 1
			y += 1
		else:
			generateSpecialCorner(logger, matrix, simple_height_map, train_line_height_map, y, x, z, x_modifier, z_modifier, path_material, fence_material, pillar_material, rail_orientation)
			return
	elif (train_line_height_map[x][z] == train_line_height_map[x][z - z_modifier] - 1):
		if (train_line_height_map[x][z] != train_line_height_map[x - x_modifier][z] + 1):
			train_line_height_map[x][z] += 1
			y += 1
		else:
			generateSpecialCorner(logger, matrix, simple_height_map, train_line_height_map, y, x, z, x_modifier, z_modifier, path_material, fence_material, pillar_material, rail_orientation)
			return
	generateRail(matrix, y, x, z, path_material, fence_material, rail_orientation, False)
	matrix.setValue(y, x + x_modifier, z, path_material)
	matrix.setValue(y + 1, x + x_modifier, z, fence_material)
	matrix.setValue(y, x, z + z_modifier, path_material)
	matrix.setValue(y + 1, x, z + z_modifier, fence_material)
	matrix.setValue(y, x + x_modifier, z + z_modifier, path_material)
	matrix.setValue(y + 1, x + x_modifier, z + z_modifier, fence_material)
	matrix.setValue(y + 2, x + x_modifier, z + z_modifier, toolbox.getBlockID("torch", 5))
Exemple #13
0
def generateSpecialCorner(logger, matrix, simple_height_map, train_line_height_map, y, x, z, x_modifier, z_modifier, path_material, fence_material, pillar_material, rail_orientation):
	logger.info("Generating special train line rail corner")
	rail_orientations = (toolbox.Orientation.NORTH_WEST - 1, toolbox.Orientation.SOUTH_EAST - 1, toolbox.Orientation.HORIZONTAL - 1, toolbox.Orientation.EAST - 1, toolbox.Orientation.SOUTH - 1, toolbox.Orientation.VERTICAL - 1) #default
	if rail_orientation == toolbox.Orientation.NORTH_EAST - 1:
		rail_orientations = (toolbox.Orientation.NORTH_WEST - 1, toolbox.Orientation.SOUTH_EAST - 1, toolbox.Orientation.HORIZONTAL - 1, toolbox.Orientation.EAST - 1, toolbox.Orientation.SOUTH - 1, toolbox.Orientation.VERTICAL - 1)
	elif rail_orientation == toolbox.Orientation.NORTH_WEST - 1:
		rail_orientations = (toolbox.Orientation.SOUTH_WEST - 1, toolbox.Orientation.NORTH_EAST - 1, toolbox.Orientation.VERTICAL - 1, toolbox.Orientation.NORTH - 1, toolbox.Orientation.EAST - 1, toolbox.Orientation.HORIZONTAL - 1)
	elif rail_orientation == toolbox.Orientation.SOUTH_WEST - 1:
		rail_orientations = (toolbox.Orientation.NORTH_WEST - 1, toolbox.Orientation.SOUTH_EAST - 1, toolbox.Orientation.HORIZONTAL - 1, toolbox.Orientation.EAST - 1, toolbox.Orientation.SOUTH - 1, toolbox.Orientation.VERTICAL - 1)
	elif rail_orientation == toolbox.Orientation.SOUTH_EAST - 1:
		rail_orientations = (toolbox.Orientation.SOUTH_WEST - 1, toolbox.Orientation.NORTH_EAST - 1, toolbox.Orientation.VERTICAL - 1, toolbox.Orientation.NORTH - 1, toolbox.Orientation.EAST - 1, toolbox.Orientation.HORIZONTAL - 1)

	generateRail(matrix, y + 1, x, z, path_material, fence_material, rail_orientations[1], False)
	generateRail(matrix, y + 1, x, z + z_modifier, path_material, fence_material, rail_orientations[2], False)
	generateRail(matrix, y + 1, x, z + 2 * z_modifier, path_material, fence_material, rail_orientations[0], False)
	generateRail(matrix, y, x + x_modifier, z + 2 * z_modifier, path_material, fence_material, rail_orientations[3], False)
	generateRail(matrix, y, x + 2 * x_modifier, z + 2 * z_modifier, path_material, fence_material, rail_orientation, False)
	generateRail(matrix, y - 1, x + 2 * x_modifier, z + z_modifier, path_material, fence_material, rail_orientations[4], False)
	generateRail(matrix, y - 1, x + 2 * x_modifier, z, path_material, fence_material, rail_orientations[1], False)
	generateRail(matrix, y - 1, x + x_modifier, z, path_material, fence_material, rail_orientations[5], False)
	generateRail(matrix, y - 1, x, z, path_material, fence_material, rail_orientations[0], False)
	matrix.setValue(y, x + x_modifier, z + z_modifier, toolbox.getBlockID("redstone_block"))
	matrix.setValue(y + 1, x + x_modifier, z + z_modifier, path_material)
	train_line_height_map[x][z] -= 1
Exemple #14
0
def generatePath(matrix, path, height_map, pavement_Type):
	air = toolbox.getBlockID("air")
	if pavement_Type == "Grass":
		pavement_Block = toolbox.getBlockID("grass_path")
		baseBlock = toolbox.getBlockID("dirt")
		light_Pillar = toolbox.getBlockID("oak_fence")
	elif pavement_Type == "Stone":
		pavement_Block = toolbox.getBlockID("stone", 6)
		baseBlock = toolbox.getBlockID("stone")
		light_Pillar = toolbox.getBlockID("cobblestone_wall")

	def fillUnderneath(matrix, y, x, z):
		if y < 0: return
		block = matrix.getValue(y, x, z)
		if type(block) == tuple: block = block[0]
		if block in air_like or block in water_like:
			matrix.setValue(y, x, z, baseBlock)
			fillUnderneath(matrix, y - 1, x, z)

	def fillAbove(matrix, y, x, z, up_to):
		if up_to < 0 or y >= matrix.height: return
		block = matrix.getValue(y, x, z)
		if type(block) == tuple: block = block[0]
		if block in air_like:
			matrix.setValue(y, x, z, air)
		fillAbove(matrix, y + 1, x, z, up_to-1)

	def getOrientation(x1, z1, x2, z2):
		if x1 < x2:   return "E"
		elif x1 > x2: return "W"
		elif z1 < z2: return "S"
		elif z1 > z2: return "N"
		else: return None

	def generateLight(matrix, block_section, path, height_map): #generate a light by using the center of mass if it is possible
		(x, z) = computeCenterOfMass(block_section)

		if height_map[x][z] != -1 and matrix.getValue(height_map[x][z] + 1, x, z) not in light_pillar_like+[65] and matrix.getValue(height_map[x][z] - 1, x, z) not in air_like: #validity of the center of mass
			if isNeighborLight(matrix,height_map, x, z) != True:
				buildLight(matrix, height_map[x][z], x, z)
		else:
			(x, z) = findPos(matrix, x, z, path, height_map)
			if (x, z) != (-1, -1):
				if isNeighborLight(matrix,height_map, x, z) != True:
					buildLight(matrix, height_map[x][z], x, z)
			else:
				return False

	def buildLight(matrix, h, x, z): #put the light at the position given
		logging.info("Generating light at point {}, {}, {}".format(h+1, x, z))
		try:
			matrix.setValue(h + 1, x, z, light_Pillar)
			matrix.setValue(h + 2, x, z, light_Pillar)
			matrix.setValue(h + 3, x, z, toolbox.getBlockID("redstone_lamp"))
			matrix.setEntity(h + 4, x, z, toolbox.getBlockID("daylight_detector_inverted", 15), "daylight_detector")
		except:
			logging.info("Error when generating light at position : {}, {}, {}".format(h+1, x, z))

	def computeCenterOfMass(block_section): #compute the center of gravity to have a general idea of where a light could be put
		x = 0
		z = 0
		for i in range(0, len(block_section)):
			x += block_section[i][0]
			z += block_section[i][1]
		x = int(round(x / len(block_section)))
		z = int(round(z / len(block_section)))
		return (x, z)

	def findPos(matrix, x, z, path, height_map): #try to find a position next to the one given that is suitable for building a light
		for neighbor_position in [(0, -1), (0, 1), (-1, 0), (1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]:
			new_position = (x + neighbor_position[0], z + neighbor_position[1])
			try:
				if height_map[new_position[0]][new_position[1]] != -1 and matrix.getValue(height_map[new_position[0]][new_position[1]]+1,new_position[0],new_position[1]) not in light_pillar_like+[65] and matrix.getValue(height_map[new_position[0]][new_position[1]]-1,new_position[0],new_position[1]) not in air_like:
					return new_position
			except:
				continue
		return (-1, -1)

	def isNeighborLight(matrix,height_map, x, z): #return True if a light is neighbor to the position x, y
		for neighbor_position in [(0, -1), (0, 1), (-1, 0), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]:
			new_position = (x + neighbor_position[0], z + neighbor_position[1])
			try:
				if matrix.getValue(height_map[new_position[0]][new_position[1]] + 1, new_position[0], new_position[1]) in light_pillar_like:
					return True
			except:
				continue

	for i in range(0, len(path) - 1):

		block = path[i]
		x = block[0]
		z = block[1]
		h = height_map[x][z]

		next_block = path[i + 1]
		next_h = height_map[next_block[0]][next_block[1]]

		if i != 0:
			previous_block = path[i - 1]
			previous_h = height_map[previous_block[0]][previous_block[1]]


		logging.info("Generating road at point ({}, {}, {})".format(h, x, z))
		(b, d) = toolbox.getBlockFullValue(matrix, h, x, z)
		if (b, d) != toolbox.getBlockID("stone", 6):
			matrix.setValue(h, x, z, pavement_Block)
			fillUnderneath(matrix, h - 1, x, z)
			fillAbove(matrix, h + 1, x, z, 5)
			# check if we are moving in the x axis (so to add a new pavement
			# on the z-1, z+1 block)
			if x != next_block[0]:

				# if that side block is walkable
				if z - 1 >= 0 and height_map[x][z - 1] != -1 and h-height_map[x][z - 1] in [0, 1]:
					matrix.setValue(h, x, z - 1, pavement_Block)
					height_map[x][z - 1] = h
					# try to fill with earth underneath if it's empty
					#logging.info("Filling underneath at height {}".format(h-1))
					fillUnderneath(matrix, h - 1, x, z - 1)
					# fill upwards with air to remove any obstacles
					fillAbove(matrix, h + 1, x, z - 1, 5)

				# if the opposite side block is walkable
				if z + 1 < matrix.depth and height_map[x][z + 1] != -1 and h-height_map[x][z + 1] in [0, 1]:
					matrix.setValue(h, x, z + 1, pavement_Block)
					height_map[x][z + 1] = h
					#logging.info("Filling underneath at height {}".format(h-1))
					fillUnderneath(matrix, h - 1, x, z + 1)
					fillAbove(matrix, h + 1, x, z + 1, 5)

			elif z != next_block[1]:
				# check if we are moving in the z axis (so add a new pavement
				# on the x-1 block) and if that side block is walkable
				if x-1 >= 0 and height_map[x - 1][z] != -1 and h - height_map[x - 1][z] in [0, 1]:
					matrix.setValue(h, x - 1, z, pavement_Block)
					height_map[x - 1][z] = h
					#logging.info("Filling underneath at height {}".format(h-1))
					fillUnderneath(matrix, h - 1, x - 1, z)
					fillAbove(matrix, h + 1, x - 1, z, 5)


				if x + 1 < matrix.width and height_map[x + 1][z] != -1 and h - height_map[x + 1][z] in [0, 1]:
					matrix.setValue(h, x + 1, z, pavement_Block)
					height_map[x + 1][z] = h
					#logging.info("Filling underneath at height {}".format(h-1))
					fillUnderneath(matrix, h - 1, x + 1, z)
					fillAbove(matrix, h + 1, x + 1, z, 5)

		else:
			logging.info("Stone path at point ({}, {}, {}) already existing, going forward".format(h, x, z))

	# another iteration over the path to generate ladders and lights
	# this is to guarantee that fillAbove or any other
	# manipulations of the environment around the path
	# will erase the ladder blocks or the lights
	block_section = path[0:20] # Block section of 20 blocks to find the right place to put lights
	isPut = generateLight(matrix, block_section, path, height_map)
	if isPut == False: #Failed to find a good position with the center of mass, build it next to or on the path
		try:
			(xl, zl) = findPos(matrix, path[10][0], path[10][1], path, height_map)
		except:
			#not enough block left in the path, so take the position of half of what remains
			(xl, zl) = findPos(matrix, path[int(((i-len(path)-1)/2))][0], path[int(((i-len(path)-1)/2))][1], path, height_map)
		if (xl, zl) != (-1, -1):
			if isNeighborLight(matrix,height_map, xl, zl) != True:
				buildLight(matrix, height_map[xl][zl], xl, zl)
		else:
			if isNeighborLight(matrix,height_map, path[10][0], path[10][1]) != True:
				buildLight(matrix, height_map[path[10][0]][path[10][1]], path[10][0], path[10][1])
	for i in range(0, len(path) - 1):

		block = path[i]
		x = block[0]
		z = block[1]
		h = height_map[x][z]

		next_block = path[i + 1]
		next_h = height_map[next_block[0]][next_block[1]]

		orientation = getOrientation(x, z, next_block[0], next_block[1])
		if abs(h - next_h) > 1:
			if h < next_h:
				if orientation == "N":   ladder_subID = 3
				elif orientation == "S": ladder_subID = 2
				elif orientation == "E": ladder_subID = 4
				elif orientation == "W": ladder_subID = 5
				for ladder_h in range(h + 1, next_h + 1):
					matrix.setValue(ladder_h, x, z, toolbox.getBlockID("ladder", ladder_subID))
					# make sure that the ladders in which the stairs are attached
					# are pathblock and not dirt, etc
					(b, d) = toolbox.getBlockFullValue(matrix, ladder_h, next_block[0], next_block[1])
					if (b, d) != toolbox.getBlockID("ladder", 6):
						matrix.setValue(ladder_h, next_block[0], next_block[1], (pavement_Block))
				block = matrix.getValue(next_h + 1, x, z)
				if type(block) == tuple: block = block[0]
				if block in air_like:
					matrix.setValue(next_h + 1, x, z, air)
				block = matrix.getValue(next_h + 2, x, z)
				if type(block) == tuple: block = block[0]
				if block in air_like:
					matrix.setValue(next_h + 2, x, z, air)

			elif h > next_h:
				if orientation == "N":   ladder_subID = 2
				elif orientation == "S": ladder_subID = 3
				elif orientation == "E": ladder_subID = 5
				elif orientation == "W": ladder_subID = 4
				for ladder_h in range(next_h+1, h+1):
					matrix.setValue(ladder_h, next_block[0], next_block[1], toolbox.getBlockID("ladder", ladder_subID))
					# make sure that the ladders in which the stairs are attached
					# are pathblock and not dirt, etc
					(b, d) = toolbox.getBlockFullValue(matrix, h, x, z)
					if (b, d) != toolbox.getBlockID("ladder", 6):
						matrix.setValue(ladder_h, x, z, (pavement_Block))
				block = matrix.getValue(h + 1, x, z)
				if type(block) == tuple: block = block[0]
				if block in air_like:
					matrix.setValue(h + 1, x, z, air)
				block = matrix.getValue(h + 2, x, z)
				if type(block) == tuple: block = block[0]
				if block in air_like:
					matrix.setValue(h + 2, x, z, air)

		#build next light and update the blocksection
		if type(block) == type(block_section[len(block_section) - 1]) and block == block_section[len(block_section) - 1]:
			isPut = generateLight(matrix, block_section, path, height_map)
			if isPut == False: #Failed to find a good position with the center of mass, build it next to or on the path
				try:
					(xl, zl) = findPos(matrix, path[i + 10][0], path[i + 10][1], path, height_map)
				except:
					#not enogh block left in the path, so take the position of half of what remains
					(xl, zl) = findPos(matrix, path[i + int(((i - len(path) - 1) / 2))][0], path[i + int(((i - len(path) - 1) / 2))][1], path, height_map)
				if (xl, zl) != (-1, -1):
					if isNeighborLight(matrix,height_map, xl, zl) != True:
						buildLight(matrix, height_map[xl][zl], xl, zl)
				else:
					if isNeighborLight(matrix,height_map, path[i + 10][0], path[i + 10][1]) != True:
						buildLight(matrix, height_map[path[i + 10][0]][path[i + 10][1]], path[i + 10][0], path[i + 10][1])
			try:
				block_section = path[i:i + 20]
			except:
				block_section = path[i:len(path)]
Exemple #15
0
def generateStructure(matrix, logger, material, h_min, h_max, x_center, z_center):
	water = toolbox.getBlockID("water")
	border = toolbox.getBlockID("lapis_block")

	h_first_floor = h_min + (h_max - h_min) / 3
	h_second_floor = h_min + (h_max - h_min) / 3 * 2

	# water
	matrix.setValue(h_max, x_center, z_center, water)
	for h in range(h_second_floor, h_max + 1):
		matrix.setValue(h, x_center - 1, z_center, water)
		matrix.setValue(h, x_center + 1, z_center, water)
		matrix.setValue(h, x_center, z_center - 1, water)
		matrix.setValue(h, x_center, z_center + 1, water)
	for h in range(h_first_floor, h_second_floor + 1):
		matrix.setValue(h, x_center - 2, z_center, water)
		matrix.setValue(h, x_center + 2, z_center, water)
		matrix.setValue(h, x_center, z_center - 2, water)
		matrix.setValue(h, x_center, z_center + 2, water)
	for h in range(h_min + 1, h_first_floor + 1):
		matrix.setValue(h, x_center - 3, z_center - 2, water)
		matrix.setValue(h, x_center - 3, z_center + 2, water)
		matrix.setValue(h, x_center + 3, z_center - 2, water)
		matrix.setValue(h, x_center + 3, z_center + 2, water)
		matrix.setValue(h, x_center - 2, z_center - 3, water)
		matrix.setValue(h, x_center + 2, z_center - 3, water)
		matrix.setValue(h, x_center - 2, z_center + 3, water)
		matrix.setValue(h, x_center + 2, z_center + 3, water)
	for i in range(-2, 3):
		for j in range(-2, 3):
			matrix.setValue(h_first_floor, x_center + i, z_center + j, water)

	for i in range(-5, 6):
		for j in range(-5, 6):
			matrix.setValue(h_min + 1, x_center + i, z_center + j, water)

	# central base
	logger.info("Fountain central base height : {}".format(h_max))
	for h in range(h_min, h_max):
		matrix.setValue(h, x_center, z_center, material)

	# basin
	for x in range(x_center - 6, x_center + 7):
		matrix.setValue(h_min + 1, x, z_center - 6, border)
		matrix.setValue(h_min + 1, x, z_center + 6, border)
	for z in range(z_center - 6, z_center + 7):
		matrix.setValue(h_min + 1, x_center - 6, z, border)
		matrix.setValue(h_min + 1, x_center + 6, z, border)
	for x in range(x_center - 4, x_center + 5):
		matrix.setValue(h_min, x, z_center - 4, border)
		matrix.setValue(h_min, x, z_center + 4, border)
	for z in range(z_center - 4, z_center + 5):
		matrix.setValue(h_min, x_center - 4, z, border)
		matrix.setValue(h_min, x_center + 4, z, border)
	for x in range(x_center - 8, x_center + 9):
		matrix.setValue(h_min, x, z_center - 8, border)
		matrix.setValue(h_min, x, z_center + 8, border)
	for z in range(z_center - 8, z_center + 9):
		matrix.setValue(h_min, x_center - 8, z, border)
		matrix.setValue(h_min, x_center + 8, z, border)

	# first floor
	logger.info("Fountain first floor height : {}".format(h_first_floor))
	for h in range(h_min, h_first_floor):
		for i in range(-2, 3):
			for j in range(-2, 3):
				matrix.setValue(h, x_center + i, z_center + j, material)
	def generateFirstFloorLine(x):
		matrix.setValue(h_first_floor, x, z_center - 3, border)
		matrix.setValue(h_first_floor, x, z_center - 1, border)
		matrix.setValue(h_first_floor, x, z_center, border)
		matrix.setValue(h_first_floor, x, z_center + 1, border)
		matrix.setValue(h_first_floor, x, z_center + 3, border)
	generateFirstFloorLine(x_center - 3)
	generateFirstFloorLine(x_center + 3)
	matrix.setValue(h_first_floor, x_center - 1, z_center - 3, border)
	matrix.setValue(h_first_floor, x_center, z_center - 3, border)
	matrix.setValue(h_first_floor, x_center + 1, z_center - 3, border)
	matrix.setValue(h_first_floor, x_center - 1, z_center + 3, border)
	matrix.setValue(h_first_floor, x_center, z_center + 3, border)
	matrix.setValue(h_first_floor, x_center + 1, z_center + 3, border)

	# second floor
	logger.info("Fountain second floor height : {}".format(h_second_floor))
	for h in range(h_first_floor, h_second_floor):
		for i in range(-1, 2):
			for j in range(-1, 2):
				matrix.setValue(h, x_center + i, z_center + j, material)
	matrix.setValue(h_second_floor, x_center - 1, z_center - 1, border)
	matrix.setValue(h_second_floor, x_center - 1, z_center + 1, border)
	matrix.setValue(h_second_floor, x_center + 1, z_center - 1, border)
	matrix.setValue(h_second_floor, x_center + 1, z_center + 1, border)
Exemple #16
0
def generateBridge(matrix, height_map, p1, p2,
                   bridge_Type):  #generate a bridge between p1 and p2
    logger = logging.getLogger("bridge")

    if bridge_Type == "Wood":
        bridge_Middle_Bottom = toolbox.getBlockID("wooden_slab", 5)
        bridge_Middle_Top = toolbox.getBlockID("wooden_slab", 13)
        bridge_Middle_Double = toolbox.getBlockID("double_wooden_slab", 5)
        bridge_Side_Bottom = toolbox.getBlockID("stone_slab", 2)
        bridge_Side_Top = toolbox.getBlockID("stone_slab", 10)
        bridge_Side_Double = toolbox.getBlockID("double_stone_slab", 10)
        bridge_Base = toolbox.getBlockID("grass_path")
        pillar_Base = toolbox.getBlockID("log")
        pillar = toolbox.getBlockID("oak_fence")

    elif bridge_Type == "Stone":
        bridge_Middle_Bottom = toolbox.getBlockID("stone_slab", 5)
        bridge_Middle_Top = toolbox.getBlockID("stone_slab", 13)
        bridge_Middle_Double = toolbox.getBlockID("double_wooden_slab", 5)
        bridge_Side_Bottom = toolbox.getBlockID("stone_slab")
        bridge_Side_Top = toolbox.getBlockID("stone_slab", 8)
        bridge_Side_Double = toolbox.getBlockID("double_wooden_slab")
        bridge_Base = toolbox.getBlockID("stone", 6)
        pillar_Base = toolbox.getBlockID("cobblestone")
        pillar = toolbox.getBlockID("cobblestone_wall")

    def getPathBridge(matrix, p1, p2):  #find a path to link p1 to p2
        path_bridge = []
        actual_point = p1
        path_bridge.append(actual_point)
        while actual_point != p2:
            if actual_point[0] < p2[0]:
                actual_point = (actual_point[0] + 1, actual_point[1])
                path_bridge.append(actual_point)
            if actual_point[0] > p2[0]:
                actual_point = (actual_point[0] - 1, actual_point[1])
                path_bridge.append(actual_point)
            if actual_point[1] < p2[1]:
                actual_point = (actual_point[0], actual_point[1] + 1)
                path_bridge.append(actual_point)
            if actual_point[1] > p2[1]:
                actual_point = (actual_point[0], actual_point[1] - 1)
                path_bridge.append(actual_point)
        return path_bridge

    def buildBridge(matrix, path_bridge, h_bridge, h_start, normal_bridge):
        #check if the bridge is more x or z axis
        if abs(path_bridge[0][0] -
               path_bridge[len(path_bridge) - 1][0]) >= abs(
                   path_bridge[0][1] - path_bridge[len(path_bridge) - 1][1]):
            x_val = 0
            z_val = 1
        else:
            x_val = 1
            z_val = 0

        #build cross in the middle of the bridge
        matrix.setValue(h_bridge, middlepoint[0], middlepoint[1],
                        bridge_Middle_Double)
        matrix.setValue(h_bridge, middlepoint[0] + x_val,
                        middlepoint[1] + z_val, bridge_Middle_Double)
        matrix.setValue(h_bridge, middlepoint[0] - x_val,
                        middlepoint[1] - z_val, bridge_Middle_Double)
        buildPillar(matrix, h_bridge - 1, middlepoint)

        #_______________________main path of the bridge______________________________
        is_half_block = True
        h_actual = h_start
        #start of the bridge
        matrix.setValue(h_actual, path_bridge[0][0], path_bridge[0][1],
                        bridge_Middle_Bottom)
        fillUnder(matrix, h_actual, path_bridge[0][0], path_bridge[0][1])
        matrix.setValue(h_actual, path_bridge[1][0], path_bridge[1][1],
                        bridge_Middle_Double)
        fillUnder(matrix, h_actual, path_bridge[1][0], path_bridge[1][1])

        for i in range(2, len(path_bridge) - 1):
            #the bridge goes up
            if h_actual != h_bridge:
                if is_half_block == True:  #check if we need to put a full block or 2 slabs
                    matrix.setValue(h_actual, path_bridge[i][0],
                                    path_bridge[i][1], bridge_Middle_Top)
                    matrix.setValue(h_actual + 1, path_bridge[i][0],
                                    path_bridge[i][1], bridge_Middle_Bottom)
                    h_actual += 1
                else:
                    matrix.setValue(h_actual, path_bridge[i][0],
                                    path_bridge[i][1], bridge_Middle_Double)
                is_half_block = not is_half_block

            #max height reached
            else:
                matrix.setValue(h_bridge, path_bridge[i][0], path_bridge[i][1],
                                bridge_Middle_Double)

        #_______________________extend the bridge on both sides______________________________
        is_half_block = True
        h_actual = h_start
        barrierPut = False
        #start of the bridge
        setIfCorrect(matrix, h_actual, path_bridge[0][0] - x_val,
                     path_bridge[0][1] - z_val, bridge_Side_Bottom)
        fillUnder(matrix, h_actual, path_bridge[0][0] - x_val,
                  path_bridge[0][1] - z_val)
        setIfCorrect(matrix, h_actual, path_bridge[0][0] + x_val,
                     path_bridge[0][1] + z_val, bridge_Side_Bottom)
        fillUnder(matrix, h_actual, path_bridge[0][0] + x_val,
                  path_bridge[0][1] + z_val)
        setIfCorrect(matrix, h_actual, path_bridge[1][0] - x_val,
                     path_bridge[1][1] - z_val, bridge_Side_Double)
        fillUnder(matrix, h_actual, path_bridge[1][0] - x_val,
                  path_bridge[1][1] - z_val)
        setIfCorrect(matrix, h_actual, path_bridge[1][0] + x_val,
                     path_bridge[1][1] + z_val, bridge_Side_Double)
        fillUnder(matrix, h_actual, path_bridge[1][0] + x_val,
                  path_bridge[1][1] + z_val)

        for i in range(2, len(path_bridge) - 1):
            #the bridge goes up
            if h_actual != h_bridge:
                if is_half_block == True:  #check if we need to put a full block or 2 slabs
                    setIfCorrect(matrix, h_actual + 1,
                                 path_bridge[i][0] - x_val,
                                 path_bridge[i][1] - z_val, bridge_Side_Bottom)
                    setIfCorrect(matrix, h_actual, path_bridge[i][0] - x_val,
                                 path_bridge[i][1] - z_val, bridge_Side_Top)
                    setIfCorrect(matrix, h_actual + 1,
                                 path_bridge[i][0] + x_val,
                                 path_bridge[i][1] + z_val, bridge_Side_Bottom)
                    setIfCorrect(matrix, h_actual, path_bridge[i][0] + x_val,
                                 path_bridge[i][1] + z_val, bridge_Side_Top)
                    h_actual += 1
                else:
                    setIfCorrect(matrix, h_actual, path_bridge[i][0] - x_val,
                                 path_bridge[i][1] - z_val, bridge_Side_Double)
                    setIfCorrect(matrix, h_actual, path_bridge[i][0] + x_val,
                                 path_bridge[i][1] + z_val, bridge_Side_Double)
                is_half_block = not is_half_block

            #max height reached
            else:
                setIfCorrect(matrix, h_bridge, path_bridge[i][0] - x_val,
                             path_bridge[i][1] - z_val, bridge_Side_Double)
                setIfCorrect(matrix, h_bridge, path_bridge[i][0] + x_val,
                             path_bridge[i][1] + z_val, bridge_Side_Double)
                #Build the barrier and light when the direction is fixed if the bridge is normal
                if normal_bridge == True and barrierPut == False and len(
                        path_bridge) - i >= 2:
                    if path_bridge[i -
                                   1][0] != path_bridge[i][0] != path_bridge[
                                       i + 1][0]:
                        buildBarrierX(matrix, h_bridge,
                                      path_bridge[i:len(path_bridge)])
                        barrierPut = True
                    if path_bridge[i -
                                   1][1] != path_bridge[i][1] != path_bridge[
                                       i + 1][1]:
                        buildBarrierZ(matrix, h_bridge,
                                      path_bridge[i:len(path_bridge)])
                        barrierPut = True

    def fillUnder(matrix, h, x,
                  z):  #put blocks under the position if there is air
        (b, d) = toolbox.getBlockFullValue(matrix, h, x, z)
        if (b, d) == bridge_Middle_Top:
            matrix.setValue(h, x, z, bridge_Middle_Double)
        elif (b, d) == bridge_Side_Top:
            matrix.setValue(h, x, z, bridge_Side_Double)
        h -= 1
        while matrix.getValue(h, x, z) in air_like + water_like:
            matrix.setValue(h, x, z, bridge_Side_Double)
            h -= 1

    def cleanAbove(matrix, h, x, z):  #erase block above the block selected
        h += 1
        while matrix.getValue(h, x, z) not in air_like:
            matrix.setValue(h, x, z, 0)
            h += 1

    def setIfCorrect(matrix, h, x, z,
                     i):  #put block only if the position given is correct
        (b, d) = toolbox.getBlockFullValue(matrix, h - 1, x, z)
        if matrix.getValue(h, x, z) in air_like and (b, d) not in [
                bridge_Side_Double, bridge_Side_Top, bridge_Side_Bottom,
                bridge_Middle_Double, bridge_Middle_Top, bridge_Middle_Bottom
        ]:
            matrix.setValue(h, x, z, i)

    def buildPillar(matrix, h,
                    p):  #build a pillar in the water as support to bridge
        while matrix.getValue(h, p[0], p[1]) in air_like:
            matrix.setValue(h, p[0], p[1], pillar)
            h -= 1
        while matrix.getValue(h, p[0], p[1]) in water_like:
            matrix.setValue(h, p[0], p[1], pillar_Base)
            h -= 1

    def buildBarrierX(matrix, h_bridge, path_bridge
                      ):  #build barrier on the bridge going through the X axis
        putLight(matrix, h_bridge, path_bridge[0][0], path_bridge[0][1] - 2)
        putLight(matrix, h_bridge, path_bridge[0][0], path_bridge[0][1] + 2)
        for i in range(1, len(path_bridge)):
            matrix.setValue(h_bridge + 1, path_bridge[i][0],
                            path_bridge[i][1] - 2, pillar)
            matrix.setValue(h_bridge + 1, path_bridge[i][0],
                            path_bridge[i][1] + 2, pillar)

    def buildBarrierZ(matrix, h_bridge, path_bridge
                      ):  #build barrier on the bridge going through the Z axis
        putLight(matrix, h_bridge, path_bridge[0][0] - 2, path_bridge[0][1])
        putLight(matrix, h_bridge, path_bridge[0][0] + 2, path_bridge[0][1])
        for i in range(1, len(path_bridge)):
            matrix.setValue(h_bridge + 1, path_bridge[i][0] - 2,
                            path_bridge[i][1], pillar)
            matrix.setValue(h_bridge + 1, path_bridge[i][0] + 2,
                            path_bridge[i][1], pillar)

    def putLight(matrix, h, x, z):  #build a light and a pillar under it
        matrix.setValue(h + 1, x, z, pillar)
        matrix.setValue(h + 2, x, z, pillar)
        matrix.setValue(h + 3, x, z, (123, 0))
        matrix.setEntity(h + 4, x, z, (178, 15), "daylight_detector")
        buildPillar(matrix, h, (x, z))

    def cleanFundation(matrix, p,
                       height_map):  #clean the endpoints of the bridge
        h = height_map[p[0]][p[1]]
        for neighbor_position in [(0, 0), (0, -1), (0, 1), (-1, 0), (1, 0),
                                  (1, 1), (-1, -1), (1, -1), (-1, 1)]:
            position_to_clean = (p[0] + neighbor_position[0],
                                 p[1] + neighbor_position[1])
            if matrix.getValue(h + 1, position_to_clean[0],
                               position_to_clean[1]) != 45:
                matrix.setValue(h, position_to_clean[0], position_to_clean[1],
                                bridge_Base)
                fillUnder(matrix, h, position_to_clean[0],
                          position_to_clean[1])
                cleanAbove(matrix, h, position_to_clean[0],
                           position_to_clean[1])
                height_map[position_to_clean[0]][position_to_clean[1]] = h

    def buildSmallBridge(matrix, path_bridge, h):
        if abs(path_bridge[0][0] -
               path_bridge[len(path_bridge) - 1][0]) >= abs(
                   path_bridge[0][1] - path_bridge[len(path_bridge) - 1][1]):
            x_val = 0
            z_val = 1
        else:
            x_val = 1
            z_val = 0

        for i in range(0, len(path_bridge)):
            x = path_bridge[i][0]
            z = path_bridge[i][1]
            matrix.setValue(h, x, z, bridge_Middle_Double)

        #build cross in the middle of the bridge
        matrix.setValue(h, middlepoint[0], middlepoint[1],
                        bridge_Middle_Double)
        matrix.setValue(h, middlepoint[0] + x_val, middlepoint[1] + z_val,
                        bridge_Middle_Double)
        matrix.setValue(h, middlepoint[0] - x_val, middlepoint[1] - z_val,
                        bridge_Middle_Double)
        buildPillar(matrix, h - 1, middlepoint)

        for i in range(0, len(path_bridge) - 1):
            setIfCorrect(matrix, h, path_bridge[i][0] - x_val,
                         path_bridge[i][1] - z_val, bridge_Side_Double)
            setIfCorrect(matrix, h, path_bridge[i][0] + x_val,
                         path_bridge[i][1] + z_val, bridge_Side_Double)

    logger.info("Trying to generate Bridge between {} and {}".format(p1, p2))
    #finding height
    h1 = height_map[p1[0]][p1[1]]
    h2 = height_map[p2[0]][p2[1]]
    h_bridge = max(h1, h2) + 2
    if min(h1, h2) == h1:
        min_point = p1
        max_point = p2
    else:
        min_point = p2
        max_point = p1

    #get the path for the 2 sides of the bridge
    logger.info("Calculating the path for the 2 sides of the Bridge")
    middlepoint = (int((p1[0] + p2[0]) / 2), (int((p1[1] + p2[1]) / 2)))
    path_bridge1 = getPathBridge(matrix, p1, middlepoint)  #first half
    path_bridge2 = getPathBridge(matrix, p2, middlepoint)  #second half

    if toolbox.getManhattanDistance(p1, p2) < 6:
        logger.info(
            "Bridge too small with length : {}, generating a small one".format(
                toolbox.getManhattanDistance(p1, p2)))
        buildSmallBridge(matrix, path_bridge1,
                         height_map[max_point[0]][max_point[1]])
        buildSmallBridge(matrix, path_bridge2,
                         height_map[max_point[0]][max_point[1]])

    else:
        #clean the fundations only if the bridge is not small
        cleanFundation(matrix, p1, height_map)
        cleanFundation(matrix, p2, height_map)

        #check if the normal bridge is buildable
        if height_map[min_point[0]][
                min_point[1]] + len(path_bridge1) * 0.5 >= h_bridge:
            logger.info(
                "Bridge size enough to go up on both sides with length : {}, generating a normal bridge"
                .format(toolbox.getManhattanDistance(p1, p2)))
            #build the bridge
            buildBridge(matrix, path_bridge1, h_bridge, h1 + 1,
                        True)  #first part of the bridge
            buildBridge(matrix, path_bridge2, h_bridge, h2 + 1,
                        True)  #second part
        else:  #bridge can't be built that way, going up only from one side
            logger.info(
                "Bridge too small to go up on both sides with length : {}, trying to go up only from the lowest point"
                .format(toolbox.getManhattanDistance(p1, p2)))
            path_bridge = getPathBridge(matrix, min_point,
                                        max_point)  #full bridge
            if height_map[min_point[0]][min_point[1]] + len(
                    path_bridge
            ) * 0.5 >= height_map[max_point[0]][max_point[
                    1]]:  #check if the difference of height is still too big
                logger.info("Bridge buildable from one side")
                buildBridge(matrix, path_bridge, max(h1, h2),
                            min(h1, h2) + 1, False)
            else:
                logger.error("Bridge not buildable, cancel generation")
                raise ValueError('Bridge not buildable')
Exemple #17
0
def clearAboveBlock(matrix, h_min, h_max, x, z):
	for y in range(h_min + HEIGHT_FROM_GROUND + 2, h_max):
		matrix.setValue(y, x, z, toolbox.getBlockID("air", 0))
Exemple #18
0
def spawnChest(matrix, wooden_materials_kit, h, x, z, socle="False"):
    ## generate oak log under chest
    if socle == True: matrix.setValue(h - 1, x, z, wooden_materials_kit["log"])
    ## generate the chest
    matrix.setEntity(h, x, z, toolbox.getBlockID("chest", 2), "chest")
Exemple #19
0
def generateHouse(matrix,
                  wood_material,
                  h_min,
                  h_max,
                  x_min,
                  x_max,
                  z_min,
                  z_max,
                  ceiling=None):
    logger = logging.getLogger("house")

    house = toolbox.dotdict()
    house.type = "house"
    house.lotArea = toolbox.dotdict({
        "y_min": h_min,
        "y_max": h_max,
        "x_min": x_min,
        "x_max": x_max,
        "z_min": z_min,
        "z_max": z_max
    })

    toolbox.cleanProperty(matrix, h_min + 1, h_max, x_min, x_max, z_min, z_max)

    (h_min, h_max, x_min, x_max, z_min,
     z_max) = getHouseAreaInsideLot(h_min, h_max, x_min, x_max, z_min, z_max)
    # calculate the top height of the walls, i.e. where the first
    # row of blocks of the pitched roof will be placed
    ceiling_bottom = h_max - int((h_max - h_min) * 0.5)
    house.buildArea = toolbox.dotdict({
        "y_min": h_min,
        "y_max": ceiling_bottom,
        "x_min": x_min,
        "x_max": x_max,
        "z_min": z_min,
        "z_max": z_max
    })

    logger.info("Generating House at area {}".format(house.lotArea))
    logger.info("Construction area {}".format(house.buildArea))

    ## Generates the house
    wooden_materials_kit = utility.wood_IDs[wood_material]

    wall = toolbox.getBlockID("double_stone_slab", RNG.randint(11, 15))
    floor = wall
    ceiling = wooden_materials_kit["planks"] if ceiling == None else ceiling
    door_ID = wooden_materials_kit["door"][0]
    window = toolbox.getBlockID("glass")
    fence = wooden_materials_kit["fence"]
    fence_gate_ID = wooden_materials_kit["fence_gate"][0]
    path = toolbox.getBlockID("stone", 6)

    # generate walls from x_min+1, x_max-1, etc to leave space for the roof
    generateWalls(matrix, house.buildArea.y_min, house.buildArea.y_max,
                  house.buildArea.x_min, house.buildArea.x_max,
                  house.buildArea.z_min, house.buildArea.z_max, wall)
    generateFloor(matrix, house.buildArea.y_min, house.buildArea.x_min,
                  house.buildArea.x_max, house.buildArea.z_min,
                  house.buildArea.z_max, floor)

    house.orientation = getOrientation(matrix, house.lotArea)
    window_y = house.buildArea.y_min + 3
    door_y = house.buildArea.y_min + 1

    if house.orientation == "N":
        door_orientation = (9, 1)
        door_x = RNG.randint(house.buildArea.x_min + 4,
                             house.buildArea.x_max - 4)
        door_z = house.buildArea.z_min
        generateDoor(matrix, door_y, door_x, door_z,
                     (door_ID, door_orientation[0]),
                     (door_ID, door_orientation[1]))
        house.entranceLot = (door_x, house.lotArea.z_min)
        # entrance path
        for z in range(house.lotArea.z_min, door_z):
            matrix.setValue(h_min, door_x, z, path)
            matrix.setValue(h_min, door_x - 1, z, path)
            matrix.setValue(h_min, door_x + 1, z, path)

    elif house.orientation == "S":
        door_orientation = (9, 3)
        door_x = RNG.randint(house.buildArea.x_min + 4,
                             house.buildArea.x_max - 4)
        door_z = house.buildArea.z_max
        generateDoor(matrix, door_y, door_x, door_z,
                     (door_ID, door_orientation[0]),
                     (door_ID, door_orientation[1]))
        house.entranceLot = (door_x, house.lotArea.z_max)
        # entrance path
        for z in range(door_z + 1, house.lotArea.z_max + 1):
            matrix.setValue(h_min, door_x, z, path)
            matrix.setValue(h_min, door_x - 1, z, path)
            matrix.setValue(h_min, door_x + 1, z, path)

    elif house.orientation == "W":
        door_orientation = (8, 0)
        door_x = house.buildArea.x_min
        door_z = RNG.randint(house.buildArea.z_min + 4,
                             house.buildArea.z_max - 4)
        generateDoor(matrix, door_y, door_x, door_z,
                     (door_ID, door_orientation[0]),
                     (door_ID, door_orientation[1]))
        house.entranceLot = (house.lotArea.x_min, door_z)
        # entrance path
        for x in range(house.lotArea.x_min, door_x):
            matrix.setValue(h_min, x, door_z, path)
            matrix.setValue(h_min, x, door_z - 1, path)
            matrix.setValue(h_min, x, door_z + 1, path)

    elif house.orientation == "E":
        door_orientation = (9, 2)
        door_x = house.buildArea.x_max
        door_z = RNG.randint(house.buildArea.z_min + 4,
                             house.buildArea.z_max - 4)
        generateDoor(matrix, door_y, door_x, door_z,
                     (door_ID, door_orientation[0]),
                     (door_ID, door_orientation[1]))
        house.entranceLot = (house.lotArea.x_max, door_z)
        # entrance path
        for x in range(door_x + 1, house.lotArea.x_max + 1):
            matrix.setValue(h_min, x, door_z, path)
            matrix.setValue(h_min, x, door_z - 1, path)
            matrix.setValue(h_min, x, door_z + 1, path)

    if house.orientation == "N" or house.orientation == "S":
        generateWindow_alongX(matrix, window, window_y, house.buildArea.x_min,
                              house.buildArea.z_min, house.buildArea.z_max)
        generateWindow_alongX(matrix, window, window_y, house.buildArea.x_max,
                              house.buildArea.z_min, house.buildArea.z_max)
        generateCeiling_x(matrix, ceiling_bottom, h_max, x_min - 1, x_max + 1,
                          z_min - 1, z_max + 1, ceiling, wall, 0)

    elif house.orientation == "E" or house.orientation == "W":
        generateWindow_alongZ(matrix, window, window_y, house.buildArea.z_min,
                              house.buildArea.x_min, house.buildArea.x_max)
        generateWindow_alongZ(matrix, window, window_y, house.buildArea.z_max,
                              house.buildArea.x_min, house.buildArea.x_max)
        generateCeiling_z(matrix, ceiling_bottom, h_max, x_min - 1, x_max + 1,
                          z_min - 1, z_max + 1, ceiling, wall, 0)

    generateInterior(matrix, h_min, ceiling_bottom, house.buildArea.x_min,
                     house.buildArea.x_max, house.buildArea.z_min,
                     house.buildArea.z_max, ceiling)
    generateGarden(logger, matrix, house, fence, fence_gate_ID)

    return house
Exemple #20
0
def cleanProperty(matrix, height_map, h_max, x_min, x_max, z_min, z_max):
    for x in range(x_min, x_max):
        for z in range(z_min, z_max):
            for y in range(height_map[x][z] + 1, h_max):
                matrix.setValue(y, x, z, toolbox.getBlockID("air"))
Exemple #21
0
 def generateEye(x, z):
     matrix.setValue(h + 1, x, z, wheatID)
     matrix.setValue(h + 1, x, z + 1, wheatID)
     matrix.setValue(h + 1, x + 1, z, wheatID)
     matrix.setValue(h, x + 1, z + 1, waterID)
     matrix.setValue(h + 1, x + 1, z + 1, toolbox.getBlockID("air"))