Compare commits

...

10 Commits

10 changed files with 239 additions and 523 deletions

28
dependencies.lua Normal file
View File

@ -0,0 +1,28 @@
subterrane.dependencies = {}
local default_modpath = minetest.get_modpath("default")
local mcl_core_modpath = minetest.get_modpath("mcl_core")
assert(default_modpath or mcl_core_modpath, "[subterrane] This mod requires either minetest_game (default) or Mineclone2 (mcl_core) to be installed")
if default_modpath then
subterrane.dependencies.stone = "default:stone"
subterrane.dependencies.clay = "default:clay"
subterrane.dependencies.desert_stone = "default:desert_stone"
subterrane.dependencies.sandstone = "default:sandstone"
subterrane.dependencies.water = "default:water_source"
subterrane.dependencies.obsidian = "default:obsidian"
elseif mcl_core_modpath then
subterrane.dependencies.stone = "mcl_core:stone"
subterrane.dependencies.clay = "mcl_core:clay"
subterrane.dependencies.desert_stone = "mcl_core:redsandstone"
subterrane.dependencies.sandstone = "mcl_core:sandstone"
subterrane.dependencies.water = "mcl_core:water_source"
subterrane.dependencies.obsidian = "mcl_core:obsidian"
end
minetest.after(0, function() subterrane.dependencies = nil end) -- ensure these are only used during initialization, to avoid polluting the global namespace with irrelevancies

View File

@ -1,3 +0,0 @@
default
intllib?
mapgen_helper

View File

@ -1 +0,0 @@
A mod that creates vast underground caverns and allows biomes to be defined for them

View File

@ -43,7 +43,7 @@ local stal_on_place = function(itemstack, placer, pointed_thing)
-- add the node and remove 1 item from the itemstack
minetest.add_node(pt.above, {name = itemstack:get_name(), param2 = new_param2})
if not minetest.settings:get_bool("creative_mode", false) then
if not minetest.is_creative_enabled(placer:get_player_name()) then
itemstack:take_item()
end
return itemstack
@ -153,8 +153,8 @@ end
-- Builds very large stalactites and stalagmites
--giant stalagmite spawner
function subterrane.big_stalagmite(vi, area, data, min_height, max_height, base_material, root_material, shaft_material)
local pos = area:position(vi)
function subterrane.big_stalagmite(vi_spawn, area, data, min_height, max_height, base_material, root_material, shaft_material)
local pos = area:position(vi_spawn)
local x = pos.x
local y = pos.y
local z = pos.z
@ -188,8 +188,8 @@ function subterrane.big_stalagmite(vi, area, data, min_height, max_height, base_
end
--giant stalactite spawner
function subterrane.big_stalactite(vi, area, data, min_height, max_height, base_material, root_material, shaft_material)
local pos = area:position(vi)
function subterrane.big_stalactite(vi_spawn, area, data, min_height, max_height, base_material, root_material, shaft_material)
local pos = area:position(vi_spawn)
local x = pos.x
local y = pos.y
local z = pos.z
@ -227,15 +227,15 @@ end
--function to create giant 'shrooms. Cap radius works well from about 2-6
--if ignore_bounds is true this function will place the mushroom even if it overlaps the edge of the voxel area.
function subterrane.giant_mushroom(vi, area, data, stem_material, cap_material, gill_material, stem_height, cap_radius, ignore_bounds)
function subterrane.giant_mushroom(vi_spawn, area, data, stem_material, cap_material, gill_material, stem_height, cap_radius, ignore_bounds)
if not ignore_bounds and
not (area:containsi(vi - cap_radius - area.zstride*cap_radius) and
area:containsi(vi + cap_radius + stem_height*area.ystride + area.zstride*cap_radius)) then
not (area:containsi(vi_spawn - cap_radius - area.zstride*cap_radius) and
area:containsi(vi_spawn + cap_radius + stem_height*area.ystride + area.zstride*cap_radius)) then
return false -- mushroom overlaps the bounds of the voxel area, abort.
end
local pos = area:position(vi)
local pos = area:position(vi_spawn)
local x = pos.x
local y = pos.y
local z = pos.z
@ -267,7 +267,7 @@ function subterrane.giant_mushroom(vi, area, data, stem_material, cap_material,
for j = -2, stem_height do -- going down to -2 to ensure the stem is flush with the ground
local vi = area:index(x, y+j, z)
if j >= 0 or area:containsi(vi) then -- since -2 puts us below the bounds we've already tested, add a contains check here.
data[vi] = stem_material
if mapgen_helper.buildable_to(data[vi]) or data[vi] == gill_material then data[vi] = stem_material end
if cap_radius > 3 then
local ai = area:index(x, y+j, z+1)
if mapgen_helper.buildable_to(data[ai]) or data[ai] == gill_material then data[ai] = stem_material end

View File

@ -4,15 +4,20 @@
-- Depends default
-- License: code MIT
local c_stone = minetest.get_content_id("default:stone")
local c_clay = minetest.get_content_id("default:clay")
local c_desert_stone = minetest.get_content_id("default:desert_stone")
local c_sandstone = minetest.get_content_id("default:sandstone")
subterrane = {} --create a container for functions and constants
local modpath = minetest.get_modpath(minetest.get_current_modname())
dofile(modpath.."/dependencies.lua")
local c_stone = minetest.get_content_id(subterrane.dependencies.stone)
local c_clay = minetest.get_content_id(subterrane.dependencies.clay)
local c_desert_stone = minetest.get_content_id(subterrane.dependencies.desert_stone)
local c_sandstone = minetest.get_content_id(subterrane.dependencies.sandstone)
local c_air = minetest.get_content_id("air")
local c_water = minetest.get_content_id("default:water_source")
local c_obsidian = minetest.get_content_id("default:obsidian")
local c_obsidian = minetest.get_content_id(subterrane.dependencies.obsidian)
local c_cavern_air = c_air
local c_warren_air = c_air
@ -28,17 +33,12 @@ local c_lava_set -- will be populated with a set of nodes that count as lava
-- Performance instrumentation
local t_start = os.clock()
subterrane = {} --create a container for functions and constants
subterrane.registered_layers = {}
--grab a shorthand for the filepath of the mod
local modpath = minetest.get_modpath(minetest.get_current_modname())
--load companion lua files
dofile(modpath.."/defaults.lua")
dofile(modpath.."/features.lua") -- some generic cave features useful for a variety of mapgens
dofile(modpath.."/player_spawn.lua") -- Function for spawning a player in a giant cavern
dofile(modpath.."/test_pos.lua") -- Function other mapgens can use to test if a position is inside a cavern
dofile(modpath.."/legacy.lua") -- contains old node definitions and functions, will be removed at some point in the future.
local disable_mapgen_caverns = function()
@ -87,8 +87,8 @@ disable_mapgen_caverns()
local grid_size = mapgen_helper.block_size * 4
subterrane.get_column_points = function(minp, maxp, column_def)
local grids = mapgen_helper.get_nearest_regions(minp, grid_size)
subterrane.get_column_points = function(minp_param, maxp_param, column_def)
local grids = mapgen_helper.get_nearest_regions(minp_param, grid_size)
local points = {}
for _, grid in ipairs(grids) do
--The y value of the returned point will be the radius of the column
@ -276,8 +276,6 @@ subterrane.register_layer = function(cave_layer_def)
end
if error_out then return end
local cave_name = cave_layer_def.name
subterrane.set_defaults(cave_layer_def)
local YMIN = cave_layer_def.y_min
@ -287,20 +285,25 @@ subterrane.register_layer = function(cave_layer_def)
cave_layer_def.name = tostring(YMIN) .. " to " .. tostring(YMAX)
end
table.insert(subterrane.registered_layers, cave_layer_def)
local cave_name = cave_layer_def.name
if subterrane.registered_layers[cave_name] ~= nil then
minetest.log("warning", "[subterrane] cave layer def " .. tostring(cave_name) .. " has already been registered. Overriding with new definition.")
end
subterrane.registered_layers[cave_name] = cave_layer_def
local block_size = mapgen_helper.block_size
if (YMAX+32+1)%block_size ~= 0 then
local boundary = YMAX -(YMAX+32+1)%block_size
minetest.log("warning", "[subterrane] The y_max setting "..tostring(YMAX)..
" for cavern layer " .. cave_layer_def.name .. " is not aligned with map chunk boundaries. Consider "..
" for cavern layer " .. cave_name .. " is not aligned with map chunk boundaries. Consider "..
tostring(boundary) .. " or " .. tostring(boundary+block_size) .. " for maximum mapgen efficiency.")
end
if (YMIN+32)%block_size ~= 0 then
local boundary = YMIN - (YMIN+32)%block_size
minetest.log("warning", "[subterrane] The y_min setting "..tostring(YMIN)..
" for cavern layer " .. cave_layer_def.name .. " is not aligned with map chunk boundaries. Consider "..
" for cavern layer " .. cave_name .. " is not aligned with map chunk boundaries. Consider "..
tostring(boundary) .. " or " .. tostring(boundary+block_size) .. " for maximum mapgen efficiency.")
end
@ -384,7 +387,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
local nvals_warrens
local previous_y = emin.y
local previous_node_state = outside_region
local previous_node_state
local this_node_state = outside_region
local column_points = nil
@ -402,7 +405,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
for vi, x, y, z in area:iterp_yxz(emin, emax) do
-- We're "over-generating" when carving out the empty space of the cave volume so that decorations
-- can slop over the boundaries of the mapblock without being cut off.
-- We only want to add vi to the various decoration node lists if we're actually whithin the mapblock.
-- We only want to add vi to the various decoration node lists if we're actually within the mapblock.
local is_within_current_mapblock = mapgen_helper.is_pos_within_box({x=x, y=y, z=z}, minp, maxp)
if y < previous_y then
@ -452,7 +455,9 @@ minetest.register_on_generated(function(minp, maxp, seed)
end
if column_value > 0 and cave_value - column_value * column_weight < cave_local_threshold then
if is_ground_content(data[vi]) then
-- only add column nodes if we're within the current mapblock because
-- otherwise we're adding column nodes that the decoration loop won't know about
if is_ground_content(data[vi]) and is_within_current_mapblock then
data[vi] = c_column -- add a column node
end
this_node_state = inside_column

View File

@ -17,11 +17,16 @@ subterrane.register_stalagmite_nodes("subterrane:dry_stal", {
sounds = default.node_sound_stone_defaults(),
})
local flowstone_drops
if minetest.get_modpath("default") then
flowstone_drops = 'default:cobble'
end
minetest.register_node("subterrane:dry_flowstone", {
description = S("Dry Flowstone"),
tiles = {"default_stone.png^[brighten"},
groups = {cracky = 3, stone = 1},
drop = 'default:cobble',
drop = flowstone_drops,
sounds = default.node_sound_stone_defaults(),
})
@ -40,7 +45,7 @@ minetest.register_node("subterrane:wet_flowstone", {
description = S("Wet Flowstone"),
tiles = {"default_stone.png^[brighten^subterrane_dripstone_streaks.png"},
groups = {cracky = 3, stone = 1, subterrane_wet_dripstone = 1},
drop = 'default:cobble',
drop = flowstone_drops,
sounds = default.node_sound_stone_defaults(),
})
@ -61,380 +66,9 @@ end
function subterrane:giant_shroom(vi, area, data, stem_material, cap_material, gill_material, stem_height, cap_radius, ignore_bounds)
subterrane.giant_mushroom(vi, area, data, stem_material, cap_material, gill_material, stem_height, cap_radius, ignore_bounds)
end
-------------------------------------------------------------------------------------
-- Original cave registration code.
local c_lava = minetest.get_content_id("default:lava_source")
local c_obsidian = minetest.get_content_id("default:obsidian")
local c_stone = minetest.get_content_id("default:stone")
local c_air = minetest.get_content_id("air")
subterrane.default_perlin_cave = {
offset = 0,
scale = 1,
spread = {x=256, y=256, z=256},
seed = -400000000089,
octaves = 3,
persist = 0.67
}
subterrane.default_perlin_wave = {
offset = 0,
scale = 1,
spread = {x=512, y=256, z=512}, -- squashed 2:1
seed = 59033,
octaves = 6,
persist = 0.63
}
-- cave_layer_def
--{
-- minimum_depth = -- required, the highest elevation this cave layer will be generated in.
-- maximum_depth = -- required, the lowest elevation this cave layer will be generated in.
-- cave_threshold = -- optional, Cave threshold. Defaults to 0.5. 1 = small rare caves, 0.5 = 1/3rd ground volume, 0 = 1/2 ground volume
-- boundary_blend_range = -- optional, range near ymin and ymax over which caves diminish to nothing. Defaults to 128.
-- perlin_cave = -- optional, a 3D perlin noise definition table to define the shape of the caves
-- perlin_wave = -- optional, a 3D perlin noise definition table that's averaged with the cave noise to add more horizontal surfaces (squash its spread on the y axis relative to perlin_cave to accomplish this)
-- columns = -- optional, a column_def table for producing truly enormous dripstone formations
--}
-- column_def
--{
-- max_column_radius = -- Maximum radius for individual columns, defaults to 10
-- min_column_radius = -- Minimum radius for individual columns, defaults to 2 (going lower can increase the likelihood of "intermittent" columns with floating sections)
-- node = -- node name to build columns out of. Defaults to default:stone
-- weight = -- a floating point value (usually in the range of 0.5-1) to modify how strongly the column is affected by the surrounding cave. Lower values create a more variable, tapered stalactite/stalagmite combination whereas a value of 1 produces a roughly cylindrical column. Defaults to 0.5
-- maximum_count = -- The maximum number of columns placed in any given column region (each region being a square 4 times the length and width of a map chunk). Defaults to 100
-- minimum_count = -- The minimum number of columns placed in a column region. The actual number placed will be randomly selected between this range. Defaults to 25.
--}
--extra biome properties used by subterrane
--{
-- _subterrane_ceiling_decor = -- function for putting stuff on the ceiling of the big caverns
-- _subterrane_floor_decor = -- function for putting stuff on the floor of the big caverns
-- _subterrane_fill_node = -- node to fill the cavern with (defaults to air)
-- _subterrane_column_node = -- override the node the giant columns in this biome are made from
-- _subterrane_cave_floor_decor = -- function for putting stuff on the floors of other preexisting open space
-- _subterrane_cave_ceiling_decor = -- function for putting stuff on the ceiling of other preexisting open space
-- _subterrane_mitigate_lava = -- try to patch the walls of big caverns with obsidian plugs when lava intersects. Not perfect, but helpful.
-- _subterrane_override_sea_level = -- Y coordinate where an underground sea level begins. Biomes' y coordinate cutoffs are unreliable underground, this forces subterrane to take this sea level cutoff into account.
-- _subterrane_override_under_sea_biome = -- When below the override_sea_level, the biome with this name will be looked up and substituted.
-- _subterrane_column_node = -- overrides the node type of a cavern layer's column_def, if there are columns here.
--}
local default_column = {
max_column_radius = 10,
min_column_radius = 2,
node = c_stone,
weight = 0.25,
maximum_count = 100,
minimum_count = 25,
}
function subterrane:register_cave_layer(cave_layer_def)
table.insert(subterrane.registered_layers, cave_layer_def)
local YMIN = cave_layer_def.maximum_depth
local YMAX = cave_layer_def.minimum_depth
local BLEND = math.min(cave_layer_def.boundary_blend_range or 128, (YMAX-YMIN)/2)
local TCAVE = cave_layer_def.cave_threshold or 0.5
local np_cave = cave_layer_def.perlin_cave or subterrane.default_perlin_cave
local np_wave = cave_layer_def.perlin_wave or subterrane.default_perlin_wave
local yblmin = YMIN + BLEND * 1.5
local yblmax = YMAX - BLEND * 1.5
local column_def = cave_layer_def.columns
local c_column
if column_def then
column_def.max_column_radius = column_def.max_column_radius or default_column.max_column_radius
column_def.min_column_radius = column_def.min_column_radius or default_column.min_column_radius
c_column = column_def.node or default_column.node
column_def.weight = column_def.weight or default_column.weight
column_def.maximum_count = column_def.maximum_count or default_column.maximum_count
column_def.minimum_count = column_def.minimum_count or default_column.minimum_count
end
-- On generated function
minetest.register_on_generated(function(minp, maxp, seed)
--if out of range of cave definition limits, abort
if minp.y > YMAX or maxp.y < YMIN then
return
end
local t_start = os.clock()
local y_max = maxp.y
local y_min = minp.y
minetest.log("info", "[subterrane] chunk minp " .. minetest.pos_to_string(minp)) --tell people you are generating a chunk
local vm, data, data_param2, area = mapgen_helper.mapgen_vm_data_param2()
local layer_range_name = tostring(YMIN).." to "..tostring(YMAX)
local nvals_cave, cave_area = mapgen_helper.perlin3d("cave "..layer_range_name, minp, maxp, np_cave) --cave noise for structure
local nvals_wave = mapgen_helper.perlin3d("wave "..layer_range_name, minp, maxp, np_wave) --wavy structure of cavern ceilings and floors
local cave_iterator = cave_area:iterp(minp, maxp)
local biomemap = minetest.get_mapgen_object("biomemap")
local column_points = nil
local column_weight = nil
if column_def then
column_points = subterrane.get_column_points(minp, maxp, column_def)
column_weight = column_def.weight
end
for vi, x, y, z in area:iterp_xyz(minp, maxp) do
local index_3d = cave_iterator()
local index_2d = mapgen_helper.index2d(minp, maxp, x, z)
local tcave --declare variable
--determine the overall cave threshold
if y < yblmin then
tcave = TCAVE + ((yblmin - y) / BLEND) ^ 2
elseif y > yblmax then
tcave = TCAVE + ((y - yblmax) / BLEND) ^ 2
else
tcave = TCAVE
end
local biome
if biomemap then
biome = mapgen_helper.get_biome_def(biomemap[index_2d])
end
if biome and biome._subterrane_override_sea_level and y <= biome._subterrane_override_sea_level then
local override_name = biome._subterrane_override_under_sea_biome
if override_name then
biome = minetest.registered_biomes[override_name]
else
biome = nil
end
end
local fill_node = c_air
local column_node = c_column
if biome then
if biome._subterrane_fill_node then
fill_node = biome._subterrane_fill_node
end
if biome._subterrane_column_node then
column_node = biome._subterrane_column_node
end
end
local cave_value = (nvals_cave[index_3d] + nvals_wave[index_3d])/2
if cave_value > tcave then --if node falls within cave threshold
local column_value = 0
if column_def then
column_value = subterrane.get_point_heat({x=x, y=y, z=z}, column_points)
end
if column_value > 0 and cave_value - column_value * column_weight < tcave then
data[vi] = column_node -- add a column
else
data[vi] = fill_node --hollow it out to make the cave
end
elseif biome and biome._subterrane_cave_fill_node and data[vi] == c_air then
data[vi] = biome._subterrane_cave_fill_node
end
if biome and biome._subterrane_mitigate_lava and cave_value > tcave - 0.1 then -- Eliminate nearby lava to keep it from spilling in
if data[vi] == c_lava then
data[vi] = c_obsidian
end
end
end
cave_iterator = cave_area:iterp(minp, maxp) -- reset this iterator
for vi, x, y, z in area:iterp_xyz(minp, maxp) do
local index_3d = cave_iterator()
local index_2d = mapgen_helper.index2d(minp, maxp, x, z)
local ai = vi + area.ystride
local bi = vi - area.ystride
local tcave --same as above
if y < yblmin then
tcave = TCAVE + ((yblmin - y) / BLEND) ^ 2
elseif y > yblmax then
tcave = TCAVE + ((y - yblmax) / BLEND) ^ 2
else
tcave = TCAVE
end
local biome
if biomemap then
biome = mapgen_helper.get_biome_def(biomemap[index_2d])
end
local fill_node = c_air
local cave_fill_node = c_air
if biome and biome._subterrane_override_sea_level and y <= biome._subterrane_override_sea_level then
local override_name = biome._subterrane_override_under_sea_biome
if override_name then
biome = minetest.registered_biomes[override_name]
else
biome = nil
end
end
if biome then
local cave_value = (nvals_cave[index_3d] + nvals_wave[index_3d])/2
-- only check nodes near the edges of caverns
if cave_value > tcave - 0.05 and cave_value < tcave + 0.05 then
if biome._subterrane_fill_node then
fill_node = biome._subterrane_fill_node
end
--ceiling
if biome._subterrane_ceiling_decor
and data[ai] ~= fill_node
and data[vi] == fill_node
and y < y_max
then --ceiling
biome._subterrane_ceiling_decor(area, data, ai, vi, bi, data_param2)
end
--floor
if biome._subterrane_floor_decor
and data[bi] ~= fill_node
and data[vi] == fill_node
and y > y_min
then --floor
biome._subterrane_floor_decor(area, data, ai, vi, bi, data_param2)
end
elseif cave_value <= tcave then --if node falls outside cave threshold
-- decorate other "native" caves and tunnels
if biome._subterrane_cave_fill_node then
cave_fill_node = biome._subterrane_cave_fill_node
if data[vi] == c_air then
data[vi] = cave_fill_node
end
end
if biome._subterrane_cave_ceiling_decor
and data[ai] ~= cave_fill_node
and data[vi] == cave_fill_node
and y < y_max
then --ceiling
biome._subterrane_cave_ceiling_decor(area, data, ai, vi, bi, data_param2)
end
if biome._subterrane_cave_floor_decor
and data[bi] ~= cave_fill_node
and data[vi] == cave_fill_node
and y > y_min
then --ground
biome._subterrane_cave_floor_decor(area, data, ai, vi, bi, data_param2)
end
end
end
end
--send data back to voxelmanip
vm:set_data(data)
vm:set_param2_data(data_param2)
--calc lighting
vm:set_lighting({day = 0, night = 0})
vm:calc_lighting()
--write it to world
vm:write_to_map()
local chunk_generation_time = math.ceil((os.clock() - t_start) * 1000) --grab how long it took
if chunk_generation_time < 1000 then
minetest.log("info", "[subterrane] "..chunk_generation_time.." ms") --tell people how long
else
minetest.log("warning", "[subterrane] took "..chunk_generation_time.." ms to generate map block "
.. minetest.pos_to_string(minp) .. minetest.pos_to_string(maxp))
end
end)
end
function subterrane:register_cave_decor(minimum_depth, maximum_depth)
-- On generated function
minetest.register_on_generated(function(minp, maxp, seed)
--if out of range of cave definition limits, abort
if minp.y > minimum_depth or maxp.y < maximum_depth then
return
end
--easy reference to commonly used values
local t_start = os.clock()
local y_max = maxp.y
local y_min = minp.y
minetest.log("info", "[subterrane] chunk minp " .. minetest.pos_to_string(minp)) --tell people you are generating a chunk
local vm, data, data_param2, area = mapgen_helper.mapgen_vm_data_param2()
local biomemap = minetest.get_mapgen_object("biomemap")
for vi, x, y, z in area:iterp_xyz(minp, maxp) do
--decoration loop, places nodes on floor and ceiling
local index_2d = mapgen_helper.index2d(minp, maxp, x, z)
local ai = vi + area.ystride
local bi = vi - area.ystride
local biome
if biomemap then
biome = mapgen_helper.get_biome_def(biomemap[index_2d])
end
local cave_fill_node = c_air
if biome then
-- decorate "native" caves and tunnels
if biome._subterrane_cave_fill_node then
cave_fill_node = biome._subterrane_cave_fill_node
if data[vi] == c_air then
data[vi] = cave_fill_node
end
end
if biome._subterrane_cave_ceiling_decor
and data[ai] ~= cave_fill_node
and data[vi] == cave_fill_node
and y < y_max
then --ceiling
biome._subterrane_cave_ceiling_decor(area, data, ai, vi, bi, data_param2)
end
--ground
if biome._subterrane_cave_floor_decor
and data[bi] ~= cave_fill_node
and data[vi] == cave_fill_node
and y > y_min
then --ground
biome._subterrane_cave_floor_decor(area, data, ai, vi, bi, data_param2)
end
end
end
--send data back to voxelmanip
vm:set_data(data)
vm:set_param2_data(data_param2)
--calc lighting
vm:set_lighting({day = 0, night = 0})
vm:calc_lighting()
--write it to world
vm:write_to_map()
local chunk_generation_time = math.ceil((os.clock() - t_start) * 1000) --grab how long it took
if chunk_generation_time < 1000 then
minetest.log("info", "[subterrane] "..chunk_generation_time.." ms") --tell people how long
else
minetest.log("warning", "[subterrane] took "..chunk_generation_time.." ms to generate a map block")
end
end)
end
--FUNCTIONS--
local grid_size = mapgen_helper.block_size * 4
function subterrane:vertically_consistent_randomp(pos)
local next_seed = math.floor(math.random() * 2^31)
math.randomseed(minetest.hash_node_position({x=pos.x, y=0, z=pos.z}))
@ -448,26 +82,6 @@ function subterrane:vertically_consistent_random(vi, area)
return subterrane:vertically_consistent_randomp(pos)
end
subterrane.get_column_points = function(minp, maxp, column_def)
local grids = mapgen_helper.get_nearest_regions(minp, grid_size)
local points = {}
for _, grid in ipairs(grids) do
--The y value of the returned point will be the radius of the column
local minp = {x=grid.x, y = column_def.min_column_radius*100, z=grid.z}
local maxp = {x=grid.x+grid_size-1, y=column_def.max_column_radius*100, z=grid.z+grid_size-1}
for _, point in ipairs(mapgen_helper.get_random_points(minp, maxp, column_def.minimum_count, column_def.maximum_count)) do
point.y = point.y / 100
if point.x > minp.x - point.y
and point.x < maxp.x + point.y
and point.z > minp.z - point.y
and point.z < maxp.z + point.y then
table.insert(points, point)
end
end
end
return points
end
subterrane.get_point_heat = function(pos, points)
local heat = 0
for _, point in ipairs(points) do

13
locale/subterrane.it.tr Normal file
View File

@ -0,0 +1,13 @@
# textdomain: subterrane
### legacy.lua ###
#WARNING: AUTOTRANSLATED BY GOOGLE TRANSLATE
Dry Dripstone=Pietra gocciolante secca
#WARNING: AUTOTRANSLATED BY GOOGLE TRANSLATE
Dry Flowstone=Flowstone secco
#WARNING: AUTOTRANSLATED BY GOOGLE TRANSLATE
Wet Dripstone=Dripstone bagnato
#WARNING: AUTOTRANSLATED BY GOOGLE TRANSLATE
Wet Flowstone=Flowstone bagnato

View File

@ -1,3 +1,4 @@
name = subterrane
description = A mapgen helper mod that facilitates the creation of vast underground caverns
depends = default, mapgen_helper
optional_depends = default, mcl_core
depends = mapgen_helper

View File

@ -4,39 +4,12 @@ local snap_to_minp = function(ydepth)
return ydepth - (ydepth+32) % sidelen -- put ydepth at the minp.y of mapblocks
end
function subterrane:register_cave_spawn(cave_layer_def, start_depth)
minetest.register_on_newplayer(function(player)
local ydepth = snap_to_minp(start_depth or cave_layer_def.y_max)
local spawned = false
while spawned ~= true do
spawned = spawnplayer(cave_layer_def, player, ydepth)
ydepth = ydepth - sidelen
if ydepth < cave_layer_def.y_min then
ydepth = snap_to_minp(cave_layer_def.y_max)
end
end
end)
minetest.register_on_respawnplayer(function(player)
local ydepth = snap_to_minp(start_depth or cave_layer_def.y_max)
local spawned = false
while spawned ~= true do
spawned = spawnplayer(cave_layer_def, player, ydepth)
ydepth = ydepth - sidelen
if ydepth < cave_layer_def.y_min then
ydepth = snap_to_minp(cave_layer_def.y_max)
end
end
return true
end)
end
local outside_region = 0
local inside_ground = 1
local inside_cavern = 2
-- Spawn player underground in a giant cavern
function spawnplayer(cave_layer_def, player, ydepth)
local function spawnplayer(cave_layer_def, player, ydepth)
subterrane.set_defaults(cave_layer_def)
local YMIN = cave_layer_def.y_min
@ -99,7 +72,7 @@ function spawnplayer(cave_layer_def, player, ydepth)
-- inside a giant cavern
if cave_value > cave_local_threshold then
local column_value = 0
local inside_column = false
local inside_column
if column_def then
if column_points == nil then
column_points = subterrane.get_column_points(minp, maxp, column_def)
@ -107,7 +80,7 @@ function spawnplayer(cave_layer_def, player, ydepth)
end
column_value = subterrane.get_column_value({x=x, y=y, z=z}, column_points)
end
inside_column = column_value > 0 and cave_value - column_value * column_weight < cave_local_threshold
inside_column = column_value > 0 and cave_value - column_value * column_weight < cave_local_threshold
if previous_node_state == inside_ground and not inside_column then
-- we just entered the cavern from below. Do a quick check for head space.
local val_above = nvals_cave[vi+cave_area.ystride]
@ -139,3 +112,30 @@ function spawnplayer(cave_layer_def, player, ydepth)
end
return false
end
function subterrane:register_cave_spawn(cave_layer_def, start_depth)
minetest.register_on_newplayer(function(player)
local ydepth = snap_to_minp(start_depth or cave_layer_def.y_max)
local spawned = false
while spawned ~= true do
spawned = spawnplayer(cave_layer_def, player, ydepth)
ydepth = ydepth - sidelen
if ydepth < cave_layer_def.y_min then
ydepth = snap_to_minp(cave_layer_def.y_max)
end
end
end)
minetest.register_on_respawnplayer(function(player)
local ydepth = snap_to_minp(start_depth or cave_layer_def.y_max)
local spawned = false
while spawned ~= true do
spawned = spawnplayer(cave_layer_def, player, ydepth)
ydepth = ydepth - sidelen
if ydepth < cave_layer_def.y_min then
ydepth = snap_to_minp(cave_layer_def.y_max)
end
end
return true
end)
end

59
test_pos.lua Normal file
View File

@ -0,0 +1,59 @@
-- If pos is located inside a cavern volume, returns the list of cavern definitions that
-- are responsible for that cavern volume. If not inside a cavern volume returns an empty list.
-- This is a somewhat expensive function, take care not to use it more than necessary
subterrane.is_in_cavern = function(pos)
local results = {}
for _, cave_layer_def in pairs(subterrane.registered_layers) do
local YMIN = cave_layer_def.y_min
local YMAX = cave_layer_def.y_max
local y = pos.y
if y <= YMAX and y >= YMIN then
local BLEND = math.min(cave_layer_def.boundary_blend_range, (YMAX-YMIN)/2)
local TCAVE = cave_layer_def.cave_threshold
local np_cave = cave_layer_def.perlin_cave
local np_wave = cave_layer_def.perlin_wave
local y_blend_min = YMIN + BLEND * 1.5
local y_blend_max = YMAX - BLEND * 1.5
local nval_cave = minetest.get_perlin(np_cave):get_3d(pos) --cave noise for structure
local nval_wave = minetest.get_perlin(np_wave):get_3d(pos) --wavy structure of cavern ceilings and floors
nval_cave = (nval_cave + nval_wave)/2
local cave_local_threshold
if y < y_blend_min then
cave_local_threshold = TCAVE + ((y_blend_min - y) / BLEND) ^ 2
elseif y > y_blend_max then
cave_local_threshold = TCAVE + ((y - y_blend_max) / BLEND) ^ 2
else
cave_local_threshold = TCAVE
end
if cave_layer_def.double_frequency and nval_cave < 0 then
nval_cave = -nval_cave
end
if nval_cave > cave_local_threshold then
table.insert(results, cave_layer_def)
end
end
end
return results
end
-- returns the value of the cavern field at a particular location for a particular cavern definition.
subterrane.get_cavern_value = function(name, pos)
local cave_layer_def = subterrane.registered_layers[name]
local YMIN = cave_layer_def.y_min
local YMAX = cave_layer_def.y_max
local y = pos.y
if y > YMAX or y < YMIN then
return nil
end
local np_cave = cave_layer_def.perlin_cave
local np_wave = cave_layer_def.perlin_wave
local nval_cave = minetest.get_perlin(np_cave):get_3d(pos) --cave noise for structure
local nval_wave = minetest.get_perlin(np_wave):get_3d(pos) --wavy structure of cavern ceilings and floors
nval_cave = (nval_cave + nval_wave)/2
return nval_cave
end