Issues in drawing order when generating non-square tiles

Godot Version

4.2

Question

Hi! I am trying to generate a map using Simplex Smooth noise and I get very random artifacts when generating trees.

Here’s a screenshot (red is for errors and blue to show that they do not happen all the time):

I am not exactly sure why this is happening since only some of the tiles are causing trouble.

I will provide a code snippet below if it helps:

func generate_trees():
	var small_distance = false
	for y in range(height):
		for x in range (width):
			if y >= 2:
				var noise_val = noise_base.get_noise_2d(x,y)
				var coords_tocheck = Vector2(x, y-2)
				var validity = false
				if !trees_busy_coords.has(coords_tocheck):
					var rng_spawn = randi_range(1,30)
					if rng_spawn > 3:
						pass
					else:
						if noise_val <= min_noise + one_percent_noise_diff*50:
							pass
						elif noise_val <= min_noise + one_percent_noise_diff*70:
							tilemap.set_cell(3,Vector2(x,y), source_id_base, tree_big_green_atlas_A)
							validity = true
						elif noise_val <= min_noise + one_percent_noise_diff*90:
							tilemap.set_cell(3,Vector2(x,y), source_id_base, tree_big_green_atlas_B)
							validity = true
						else:
							tilemap.set_cell(3,Vector2(x,y), source_id_base, tree_big_green_atlas_C)
							validity = true
						
						if validity == true:
							var free_tree_cells = 1
							for cell in free_tree_cells:
								no_grass_coords[Vector2(x,y)] = true
								
						var no_trees_area
						var rng
						if small_distance == false:
							rng = randi_range(3,6)
						else:
							rng = randi_range(4,6)
							
						if rng == 2:
							small_distance = true
							rng = randi_range(3,6)
						no_trees_area = rng
									
						for cell_x in range(-no_trees_area, no_trees_area):
							for cell_y in range(-2, 2):
								var new_coords = Vector2(x + cell_x, y + cell_y -2)
								trees_busy_coords[new_coords] = true

I’d appreciate any help or just a general direction to research.
Cheers!