mirror of
https://gitlab.com/gaelysam/mapgen_rivers.git
synced 2025-02-21 14:30:32 +01:00
Added caves (hardcoded for now)
This commit is contained in:
parent
b406bebb7b
commit
77b05f044a
59
mapgen.lua
59
mapgen.lua
@ -28,12 +28,13 @@ local floor, min = math.floor, math.min
|
||||
|
||||
local data = {}
|
||||
|
||||
local noise_x_obj, noise_z_obj, noise_distort_obj, noise_heat_obj, noise_heat_blend_obj
|
||||
local noise_x_obj, noise_z_obj, noise_distort_obj, noise_heat_obj, noise_heat_blend_obj, noise_cave_obj
|
||||
local noise_x_map = {}
|
||||
local noise_z_map = {}
|
||||
local noise_distort_map = {}
|
||||
local noise_heat_map = {}
|
||||
local noise_heat_blend_map = {}
|
||||
local noise_cave = {}
|
||||
local mapsize
|
||||
local init = false
|
||||
|
||||
@ -41,6 +42,18 @@ local sumtime = 0
|
||||
local sumtime2 = 0
|
||||
local ngen = 0
|
||||
|
||||
local use_caves = true
|
||||
local np_cave = {
|
||||
offset = 0,
|
||||
scale = 8,
|
||||
spread = {x=256, y=128, z=256},
|
||||
seed = -9152,
|
||||
octaves = 4,
|
||||
persist = 0.65,
|
||||
lacunarity = 2,
|
||||
flags = "absvalue",
|
||||
}
|
||||
|
||||
function mapgen_rivers.make_chunk(minp, maxp, seed)
|
||||
minetest.log("info", ("[mapgen_rivers] Generating from %s to %s"):format(minetest.pos_to_string(minp), minetest.pos_to_string(maxp)))
|
||||
|
||||
@ -65,6 +78,9 @@ function mapgen_rivers.make_chunk(minp, maxp, seed)
|
||||
noise_heat_obj = minetest.get_perlin_map(mapgen_rivers.noise_params.heat, chulens)
|
||||
noise_heat_blend_obj = minetest.get_perlin_map(mapgen_rivers.noise_params.heat_blend, chulens)
|
||||
end
|
||||
if use_caves then
|
||||
noise_cave_obj = minetest.get_perlin_map(np_cave, mapsize)
|
||||
end
|
||||
init = true
|
||||
end
|
||||
|
||||
@ -79,7 +95,9 @@ function mapgen_rivers.make_chunk(minp, maxp, seed)
|
||||
noise_heat_obj:get_2d_map_flat(minp2d, noise_heat_map)
|
||||
noise_heat_blend_obj:get_2d_map_flat(minp2d, noise_heat_blend_map)
|
||||
end
|
||||
|
||||
if use_caves then
|
||||
noise_cave_obj:get_3d_map_flat(minp, noise_cave)
|
||||
end
|
||||
local terrain_map, lake_map, incr, i_origin
|
||||
|
||||
if use_distort then
|
||||
@ -146,6 +164,7 @@ function mapgen_rivers.make_chunk(minp, maxp, seed)
|
||||
local c_stone = minetest.get_content_id("mapgen_stone")
|
||||
local c_water = minetest.get_content_id("mapgen_water_source")
|
||||
local c_rwater = minetest.get_content_id("mapgen_river_water_source")
|
||||
local c_air = minetest.get_content_id("air")
|
||||
|
||||
local c_dirt, c_lawn, c_dirtsnow, c_snow, c_sand, c_ice
|
||||
if use_biomes then
|
||||
@ -178,7 +197,7 @@ function mapgen_rivers.make_chunk(minp, maxp, seed)
|
||||
if use_biomes then
|
||||
temperature = noise_heat_map[i2d]+noise_heat_blend_map[i2d]
|
||||
end
|
||||
local terrain, lake
|
||||
local terrain, lake, caveness
|
||||
if not use_distort then
|
||||
terrain = terrain_map[i2d]
|
||||
lake = lake_map[i2d]
|
||||
@ -200,6 +219,10 @@ function mapgen_rivers.make_chunk(minp, maxp, seed)
|
||||
lake = min(lake_map[i0], lake_map[i1], lake_map[i2], lake_map[i3])
|
||||
end
|
||||
|
||||
if use_caves then
|
||||
noise_cave[nid] = noise_cave[nid] < math.min(math.max(terrain - y, 0), 100) ^ 0.5 / 10
|
||||
end
|
||||
|
||||
if y <= maxp.y then
|
||||
|
||||
local is_lake = lake > terrain
|
||||
@ -249,10 +272,32 @@ function mapgen_rivers.make_chunk(minp, maxp, seed)
|
||||
end
|
||||
|
||||
if use_biomegen_mod then
|
||||
biomegen.generate_all(data, a, vm, minp, maxp, seed)
|
||||
else
|
||||
vm:set_data(data)
|
||||
minetest.generate_ores(vm, minp, maxp)
|
||||
biomegen.generate_biomes(data, a, minp, maxp)
|
||||
end
|
||||
if use_caves then
|
||||
local i = 1
|
||||
for z=minp.z, maxp.z do
|
||||
for y=minp.y, maxp.y do
|
||||
local vi = a:index(minp.x, y, z)
|
||||
for x=minp.x, maxp.x do
|
||||
if noise_cave[i] then
|
||||
data[vi] = c_air
|
||||
end
|
||||
i = i + 1
|
||||
vi = vi + 1
|
||||
end
|
||||
end
|
||||
i = i + chulens.x -- Skip etra row
|
||||
end
|
||||
end
|
||||
vm:set_data(data)
|
||||
if use_biomegen_mod then
|
||||
biomegen.place_all_decos(data, a, vm, minp, maxp, seed)
|
||||
end
|
||||
minetest.generate_ores(vm, minp, maxp)
|
||||
if use_biomegen_mod then
|
||||
vm:get_data(data)
|
||||
biomegen.dust_top_nodes(data, a, vm, minp, maxp)
|
||||
end
|
||||
|
||||
vm:set_lighting({day = 0, night = 0})
|
||||
|
Loading…
x
Reference in New Issue
Block a user