diff --git a/init.lua b/init.lua index dc3fa98..89cc87e 100644 --- a/init.lua +++ b/init.lua @@ -366,16 +366,18 @@ function internal.clean_shape_def(def) end -- Get the most nearby cave biome -function internal.closest_cave_biome(heat, humidity) +function internal.closest_cave_biome(heat, humidity, pos) local biome = internal.default_biome() local d = internal.biome_def_distance(biome, heat, humidity) for _, def in pairs(noordstar_caves.registered_biomes) do - local new_d = internal.biome_def_distance(def, heat, humidity) - - if new_d <= d then - biome = def - d = new_d + if internal.is_valid_pos(pos, def.minp, def.maxp) then + local new_d = internal.biome_def_distance(def, heat, humidity) + + if new_d <= d then + biome = def + d = new_d + end end end @@ -383,16 +385,18 @@ function internal.closest_cave_biome(heat, humidity) end -- Get the most nearby cave shape -function internal.closest_cave_shape(cnct, vrtcl) +function internal.closest_cave_shape(cnct, vrtcl, y) local shape = internal.default_shape() local d = internal.shape_def_distance(shape, cnct, vrtcl) for key, def in pairs(noordstar_caves.registered_shapes) do - local new_d = internal.shape_def_distance(def, cnct, vrtcl) - - if new_d <= d then - shape = def - d = new_d + if def.y_min <= y and y <= def.y_max then + local new_d = internal.shape_def_distance(def, cnct, vrtcl) + + if new_d <= d then + shape = def + d = new_d + end end end @@ -516,7 +520,7 @@ function internal.flat_from_cave_bools(minp, maxp) local cnct = connectivity:get_index(i) local vrtcl = verticality:get_index(i) - local def = internal.closest_cave_shape(cnct, vrtcl) + local def = internal.closest_cave_shape(cnct, vrtcl, pos.y) return def.name end) @@ -735,7 +739,7 @@ function internal.generate_caves(data, minp, maxp) local heat = heat_points:get_index(i) local humidity = humidity_points:get_index(i) - local def = internal.closest_cave_biome(heat, humidity) + local def = internal.closest_cave_biome(heat, humidity, pos) if nt == internal.node_types.floor then place(def.node_floor)