I probably should have attached this with the original post sorry about that.
the main process here is to first, check if a tile is one that needs to be connected. then, in the connect_tile_to_adj function, it first checks where the tiles adjacent to it are and saves it as either a 1 for yes tile or 0 for no tile in an array (ordered left to right, top left corner is position 0 and bottom right is position 8), it also checks if the tile has any adjacent tiles in a cardinal direction to it, this is used to skip sections of the code where diagonal tiles would not affect the texture of the central tile.
finally, using the gathered info, it looks through the mess of if statements for the exact case found above, and sets the cell at coords to the correct texture.
func smooth_tiles(x, y): ## smooths all the tiles in the chunk and in a 1 tile border of the chunk at (x, y)
for i in range(-1, 17):
for j in range(-1, 17):
if map.get_cell_source_id(Vector2i(i+16*x, j+16*y)) == 4 or map.get_cell_source_id(Vector2i(i+16*x, j+16*y)) == 0:
connect_tile_to_adj(Vector2i(i+16*x, j+16*y))
func connect_tile_to_adj(coords : Vector2i): ## goes through every case of what a tile could look like and sets said tile to the correct texture
var tile_config = []
var crdnl = 0
var id = map.get_cell_source_id(coords)
for i in range(-1, 2):
for j in range(-1, 2):
#checks how many tiles are adjacent to the one being modified
if map.get_cell_source_id(Vector2i(coords.x+i, coords.y+j)) == 4 or map.get_cell_source_id(Vector2i(coords.x+i, coords.y+j)) == 0:
tile_config.append(1)
if i == 0 or j == 0:
crdnl += 1
else:
tile_config.append(0)
if map.get_cell_tile_data(coords) != null:
crdnl -= 1
if crdnl == 0: map.set_cell(coords, id, Vector2i(0, 3))
elif crdnl == 1:
if tile_config[1] == 1: map.set_cell(coords, id, Vector2i(3, 3))
elif tile_config[3] == 1: map.set_cell(coords, id, Vector2i(0, 2))
elif tile_config[5] == 1: map.set_cell(coords, id, Vector2i(0, 0))
elif tile_config[7] == 1: map.set_cell(coords, id, Vector2i(1, 3))
elif crdnl == 2:
if tile_config[1] == 1:
if tile_config[3] == 1:
if tile_config[0] == 1: map.set_cell(coords, id, Vector2i(11, 3))
else: map.set_cell(coords, id, Vector2i(3, 2))
elif tile_config[5] == 1:
if tile_config[2] == 1: map.set_cell(coords, id, Vector2i(11, 0))
else: map.set_cell(coords, id, Vector2i(3, 0))
elif tile_config[7] == 1: map.set_cell(coords, id, Vector2i(2, 3))
elif tile_config[3] == 1:
if tile_config[5] == 1: map.set_cell(coords, id, Vector2i(0, 1))
elif tile_config[7] == 1:
if tile_config[6] == 1: map.set_cell(coords, id, Vector2i(8, 3))
else: map.set_cell(coords, id, Vector2i(1, 2))
elif tile_config[5] == 1:
if tile_config[7] == 1:
if tile_config[8] == 1: map.set_cell(coords, id, Vector2i(8, 0))
else: map.set_cell(coords, id, Vector2i(1, 0))
elif crdnl == 3:
if tile_config[1] == 1:
if tile_config[3] == 1:
if tile_config[5] == 1:
if tile_config[0] == 1 and tile_config[2] == 1: map.set_cell(coords, id, Vector2i(11, 2))
elif tile_config[0] == 1: map.set_cell(coords, id, Vector2i(7, 2))
elif tile_config[2] == 1: map.set_cell(coords, id, Vector2i(7, 1))
else: map.set_cell(coords, id, Vector2i(3, 1))
elif tile_config[7] == 1:
if tile_config[0] == 1 and tile_config[6] == 1: map.set_cell(coords, id, Vector2i(9, 3))
elif tile_config[0] == 1: map.set_cell(coords, id, Vector2i(6, 3))
elif tile_config[6] == 1: map.set_cell(coords, id, Vector2i(5, 3))
else: map.set_cell(coords, id, Vector2i(2, 2))
elif tile_config[5] == 1:
if tile_config[7] == 1:
if tile_config[2] == 1 and tile_config[8] == 1: map.set_cell(coords, id, Vector2i(10, 0))
elif tile_config[2] == 1: map.set_cell(coords, id, Vector2i(6, 0))
elif tile_config[8] == 1: map.set_cell(coords, id, Vector2i(5, 0))
else: map.set_cell(coords, id, Vector2i(2, 0))
elif tile_config[3] == 1:
if tile_config[5] == 1:
if tile_config[7] == 1:
if tile_config[6] == 1 and tile_config[8] == 1: map.set_cell(coords, id, Vector2i(8, 1))
elif tile_config[6] == 1: map.set_cell(coords, id, Vector2i(4, 2))
elif tile_config[8] == 1: map.set_cell(coords, id, Vector2i(4, 1))
else: map.set_cell(coords, id, Vector2i(1, 1))
elif crdnl == 4:
if tile_config[0] == 1 and tile_config[2] == 1 and tile_config[6] == 1 and tile_config[8] == 1: map.set_cell(coords, id, Vector2i(9, 2))
elif tile_config[0] == 1:
if tile_config[2] == 1:
if tile_config[6] == 1: map.set_cell(coords, id, Vector2i(6, 2))
elif tile_config[8] == 1: map.set_cell(coords, id, Vector2i(6, 1))
else: map.set_cell(coords, id, Vector2i(11, 1))
elif tile_config[6] == 1:
if tile_config[8] == 1: map.set_cell(coords, id, Vector2i(5, 2))
else: map.set_cell(coords, id, Vector2i(10, 3))
elif tile_config[8] == 1: map.set_cell(coords, id, Vector2i(10, 2))
else: map.set_cell(coords, id, Vector2i(4, 0))
elif tile_config[2] == 1:
if tile_config[6] == 1:
if tile_config[8] == 1: map.set_cell(coords, id, Vector2i(5, 1))
else: map.set_cell(coords, id, Vector2i(9, 1))
elif tile_config[8] == 1: map.set_cell(coords, id, Vector2i(9, 0))
else: map.set_cell(coords, id, Vector2i(4, 3))
elif tile_config[6] == 1:
if tile_config[8] == 1: map.set_cell(coords, id, Vector2i(8, 2))
else: map.set_cell(coords, id, Vector2i(7, 0))
elif tile_config[8] == 1: map.set_cell(coords, id, Vector2i(7, 3))
else: map.set_cell(coords, id, Vector2i(2, 1))
else:map.set_cell(coords, 1, Vector2i(2, 0))