Compare commits
10 Commits
561b121bc0
...
7d0b7e3d4b
Author | SHA1 | Date | |
---|---|---|---|
|
7d0b7e3d4b | ||
|
e5f8457e93 | ||
|
75fe53f5eb | ||
|
c5f46e113e | ||
|
40215b772e | ||
|
2e523b1ba1 | ||
|
331d08b156 | ||
|
1f385fc84a | ||
|
6cc2fe8fae | ||
|
6439ca59bf |
28
dependencies.lua
Normal file
28
dependencies.lua
Normal 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
|
@ -1,3 +0,0 @@
|
||||
default
|
||||
intllib?
|
||||
mapgen_helper
|
@ -1 +0,0 @@
|
||||
A mod that creates vast underground caverns and allows biomes to be defined for them
|
32
features.lua
32
features.lua
@ -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
|
||||
@ -76,7 +76,7 @@ subterrane.register_stalagmite_nodes = function(base_name, base_node_def, drop_b
|
||||
base_node_def.paramtype = "light"
|
||||
base_node_def.paramtype2 = "facedir"
|
||||
base_node_def.node_box = {type = "fixed"}
|
||||
|
||||
|
||||
local def1 = deep_copy(base_node_def)
|
||||
def1.groups.fall_damage_add_percent = 100
|
||||
def1.node_box.fixed = stal_box_1
|
||||
@ -110,7 +110,7 @@ subterrane.register_stalagmite_nodes = function(base_name, base_node_def, drop_b
|
||||
def4.drop = drop_base_name.."_4"
|
||||
end
|
||||
minetest.register_node(base_name.."_4", def4)
|
||||
|
||||
|
||||
return {
|
||||
minetest.get_content_id(base_name.."_1"),
|
||||
minetest.get_content_id(base_name.."_2"),
|
||||
@ -126,7 +126,7 @@ end
|
||||
function subterrane.stalagmite(vi, area, data, param2_data, param2, height, stalagmite_id)
|
||||
if height == nil then height = math.random(1,4) end
|
||||
if param2 == nil then param2 = math.random(0,3) end
|
||||
|
||||
|
||||
local sign, id_modifier
|
||||
if height > 0 then
|
||||
sign = 1
|
||||
@ -135,14 +135,14 @@ function subterrane.stalagmite(vi, area, data, param2_data, param2, height, stal
|
||||
sign = -1
|
||||
id_modifier = 0
|
||||
end
|
||||
|
||||
|
||||
for i = 1, math.abs(height) do
|
||||
local svi = vi + (height - i * sign) * area.ystride
|
||||
if data[svi] == c_air then -- test for air because we don't want these poking into water
|
||||
data[svi] = stalagmite_id[math.min(i+id_modifier,4)]
|
||||
param2_data[svi] = param2
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function subterrane.stalactite(vi, area, data, param2_data, param2, height, stalagmite_id)
|
||||
@ -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
|
||||
if not ignore_bounds and
|
||||
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
|
||||
|
135
init.lua
135
init.lua
@ -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,25 +33,20 @@ 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()
|
||||
local mg_name = minetest.get_mapgen_setting("mg_name")
|
||||
local flags_name
|
||||
local default_flags
|
||||
|
||||
if mg_name == "v7" then
|
||||
|
||||
if mg_name == "v7" then
|
||||
flags_name = "mgv7_spflags"
|
||||
default_flags = "mountains,ridges,nofloatlands"
|
||||
elseif mg_name == "v5" then
|
||||
@ -55,14 +55,14 @@ local disable_mapgen_caverns = function()
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
local function split(source, delimiters)
|
||||
local elements = {}
|
||||
local pattern = '([^'..delimiters..']+)'
|
||||
string.gsub(source, pattern, function(value) elements[#elements + 1] = value; end);
|
||||
return elements
|
||||
end
|
||||
|
||||
|
||||
local flags_setting = minetest.get_mapgen_setting(flags_name) or default_flags
|
||||
local new_flags = {}
|
||||
local flags = split(flags_setting, ", ")
|
||||
@ -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
|
||||
@ -101,7 +101,7 @@ subterrane.get_column_points = function(minp, maxp, column_def)
|
||||
and point.z > minp.z - point.y
|
||||
and point.z < maxp.z + point.y then
|
||||
table.insert(points, point)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return points
|
||||
@ -114,12 +114,12 @@ subterrane.get_column_value = function(pos, points)
|
||||
local radius = point.y
|
||||
if (pos.x >= axis_point.x-radius and pos.x <= axis_point.x+radius
|
||||
and pos.z >= axis_point.z-radius and pos.z <= axis_point.z+radius) then
|
||||
|
||||
|
||||
local dist = vector.distance(pos, axis_point)
|
||||
if dist < radius then
|
||||
heat = math.max(heat, 1 - dist/radius)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
return heat
|
||||
@ -196,7 +196,7 @@ local clear_node_arrays = function()
|
||||
cavern_data.tunnel_ceiling_count = 0
|
||||
cavern_data.tunnel_floor_count = 0
|
||||
cavern_data.column_count = 0
|
||||
|
||||
|
||||
-- for k,v in pairs(cavern_ceiling_nodes) do cavern_ceiling_nodes[k] = nil end
|
||||
-- for k,v in pairs(cavern_floor_nodes) do cavern_floor_nodes[k] = nil end
|
||||
-- for k,v in pairs(warren_ceiling_nodes) do warren_ceiling_nodes[k] = nil end
|
||||
@ -204,7 +204,7 @@ local clear_node_arrays = function()
|
||||
-- for k,v in pairs(tunnel_ceiling_nodes) do tunnel_ceiling_nodes[k] = nil end
|
||||
-- for k,v in pairs(tunnel_floor_nodes) do tunnel_floor_nodes[k] = nil end
|
||||
-- for k,v in pairs(column_nodes) do column_nodes[k] = nil end
|
||||
|
||||
|
||||
close_node_arrays()
|
||||
end
|
||||
|
||||
@ -275,32 +275,35 @@ subterrane.register_layer = function(cave_layer_def)
|
||||
error_out = true
|
||||
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
|
||||
local YMAX = cave_layer_def.y_max
|
||||
|
||||
|
||||
if cave_layer_def.name == nil then
|
||||
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
|
||||
|
||||
@ -312,15 +315,15 @@ subterrane.register_layer = function(cave_layer_def)
|
||||
local warren_threshold = cave_layer_def.warren_threshold -- determines narrowness of warrens themselves
|
||||
|
||||
local solidify_lava = cave_layer_def.solidify_lava
|
||||
|
||||
|
||||
local np_cave = cave_layer_def.perlin_cave
|
||||
local np_wave = cave_layer_def.perlin_wave
|
||||
local np_warren_area = cave_layer_def.perlin_warren_area
|
||||
local np_warrens = cave_layer_def.perlin_warrens
|
||||
|
||||
|
||||
local y_blend_min = YMIN + BLEND * 1.5
|
||||
local y_blend_max = YMAX - BLEND * 1.5
|
||||
|
||||
local y_blend_max = YMAX - BLEND * 1.5
|
||||
|
||||
local column_def = cave_layer_def.columns
|
||||
local c_column
|
||||
local c_warren_column
|
||||
@ -333,7 +336,7 @@ subterrane.register_layer = function(cave_layer_def)
|
||||
end
|
||||
|
||||
local double_frequency = cave_layer_def.double_frequency
|
||||
|
||||
|
||||
local decorate = cave_layer_def.decorate
|
||||
|
||||
if subterrane_enable_singlenode_mapping_mode then
|
||||
@ -341,12 +344,12 @@ subterrane.register_layer = function(cave_layer_def)
|
||||
c_column = c_air
|
||||
c_warren_column = nil
|
||||
end
|
||||
|
||||
|
||||
local is_ground_content = cave_layer_def.is_ground_content
|
||||
if is_ground_content == nil then
|
||||
is_ground_content = mapgen_helper.is_ground_content
|
||||
end
|
||||
|
||||
|
||||
-- On generated
|
||||
----------------------------------------------------------------------------------
|
||||
|
||||
@ -365,7 +368,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local vm, data, data_param2, area = mapgen_helper.mapgen_vm_data_param2()
|
||||
local emin = area.MinEdge
|
||||
local emax = area.MaxEdge
|
||||
@ -377,34 +380,34 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
for vi, value in ipairs(nvals_cave) do
|
||||
nvals_cave[vi] = (value + nvals_wave[vi])/2
|
||||
end
|
||||
|
||||
|
||||
local warren_area_uninitialized = true
|
||||
local nvals_warren_area
|
||||
local warrens_uninitialized = true
|
||||
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
|
||||
local column_weight = nil
|
||||
|
||||
|
||||
-- This information might be of use to the decorate function.
|
||||
cavern_data.contains_cavern = false
|
||||
cavern_data.contains_warren = false
|
||||
cavern_data.nvals_cave = nvals_cave
|
||||
cavern_data.cave_area = cave_area
|
||||
cavern_data.cavern_def = cave_layer_def
|
||||
|
||||
|
||||
-- The interp_yxz iterator iterates upwards in columns along the y axis.
|
||||
-- starts at miny, goes to maxy, then switches to a new x,z and repeats.
|
||||
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
|
||||
-- we've switched to a new column
|
||||
previous_node_state = outside_region
|
||||
@ -413,7 +416,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
end
|
||||
previous_y = y
|
||||
this_node_state = inside_ground
|
||||
|
||||
|
||||
local cave_local_threshold
|
||||
if y < y_blend_min then
|
||||
cave_local_threshold = TCAVE + ((y_blend_min - y) / BLEND) ^ 2
|
||||
@ -437,9 +440,9 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
c_warren_air = c_clay
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- inside a giant cavern
|
||||
if cave_value > cave_local_threshold then
|
||||
local column_value = 0
|
||||
@ -450,9 +453,11 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
end
|
||||
column_value = subterrane.get_column_value({x=x, y=y, z=z}, column_points)
|
||||
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
|
||||
@ -466,37 +471,37 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- If there's lava near the edges of the cavern, solidify it.
|
||||
if solidify_lava and cave_value > cave_local_threshold - 0.05 and c_lava_set[data[vi]] then
|
||||
data[vi] = c_obsidian
|
||||
end
|
||||
|
||||
|
||||
--borderlands of a giant cavern, possible warren area
|
||||
if cave_value <= cave_local_threshold and cave_value > warren_area_threshold then
|
||||
|
||||
|
||||
if warren_area_uninitialized then
|
||||
nvals_warren_area = mapgen_helper.perlin3d("subterrane:warren_area", emin, emax, np_warren_area) -- determine which areas are spongey with warrens
|
||||
warren_area_uninitialized = false
|
||||
end
|
||||
|
||||
|
||||
local warren_area_value = nvals_warren_area[vi]
|
||||
if warren_area_value > warren_area_variability_threshold then
|
||||
-- we're in a warren-containing area
|
||||
if solidify_lava and c_lava_set[data[vi]] then
|
||||
data[vi] = c_obsidian
|
||||
data[vi] = c_obsidian
|
||||
end
|
||||
|
||||
|
||||
if warrens_uninitialized then
|
||||
nvals_warrens = mapgen_helper.perlin3d("subterrane:warrens", emin, emax, np_warrens) --spongey warrens
|
||||
warrens_uninitialized = false
|
||||
end
|
||||
|
||||
|
||||
-- we don't want warrens "cutting off" abruptly at the large-scale boundary noise thresholds, so turn these into gradients
|
||||
-- that can be applied to choke off the warren gradually.
|
||||
local cave_value_edge = math.min(1, (cave_value - warren_area_threshold) * 20) -- make 0.3 = 0 and 0.25 = 1 to produce a border gradient
|
||||
local warren_area_value_edge = math.min(1, warren_area_value * 50) -- make 0 = 0 and 0.02 = 1 to produce a border gradient
|
||||
|
||||
|
||||
local warren_value = nvals_warrens[vi]
|
||||
local warren_local_threshold = warren_threshold + (2 - warren_area_value_edge - cave_value_edge)
|
||||
if warren_value > warren_local_threshold then
|
||||
@ -529,7 +534,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- If decorate is defined, we want to track all this stuff
|
||||
if decorate ~= nil then
|
||||
local c_current_node = data[vi]
|
||||
@ -538,7 +543,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
-- we're in a preexisting open space (tunnel).
|
||||
this_node_state = inside_tunnel
|
||||
end
|
||||
|
||||
|
||||
if is_within_current_mapblock then
|
||||
if this_node_state == inside_column then
|
||||
cavern_data.column_count = cavern_data.column_count + 1
|
||||
@ -577,13 +582,13 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if decorate then
|
||||
close_node_arrays() -- inserts nil after the last node so that ipairs will function correctly
|
||||
decorate(minp, maxp, seed, vm, cavern_data, area, data)
|
||||
clear_node_arrays() -- if decorate is not defined these arrays will never have anything added to them, so it's safe to not call this in that case
|
||||
end
|
||||
|
||||
|
||||
--send data back to voxelmanip
|
||||
vm:set_data(data)
|
||||
--calc lighting
|
||||
@ -592,7 +597,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
vm:update_liquids()
|
||||
--write it to world
|
||||
vm:write_to_map()
|
||||
|
||||
|
||||
local time_taken = os.clock() - t_start -- how long this chunk took, in seconds
|
||||
mapgen_helper.record_time(cave_name, time_taken)
|
||||
end)
|
||||
|
404
legacy.lua
404
legacy.lua
@ -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
|
||||
@ -475,7 +89,7 @@ subterrane.get_point_heat = function(pos, points)
|
||||
local radius = point.y
|
||||
if (pos.x >= axis_point.x-radius and pos.x <= axis_point.x+radius
|
||||
and pos.z >= axis_point.z-radius and pos.z <= axis_point.z+radius) then
|
||||
|
||||
|
||||
local dist = vector.distance(pos, axis_point)
|
||||
if dist < radius then
|
||||
heat = math.max(heat, 1 - dist/radius)
|
||||
@ -497,7 +111,7 @@ function subterrane:override_biome(biome_def)
|
||||
minetest.unregister_biome(biome_def.name)
|
||||
minetest.register_biome(biome_def)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local registered_biomes_copy = {}
|
||||
for old_biome_key, old_biome_def in pairs(minetest.registered_biomes) do
|
||||
|
13
locale/subterrane.it.tr
Normal file
13
locale/subterrane.it.tr
Normal 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
|
3
mod.conf
3
mod.conf
@ -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
|
@ -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
|
||||
@ -44,13 +17,13 @@ function spawnplayer(cave_layer_def, player, ydepth)
|
||||
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 y_blend_max = YMAX - BLEND * 1.5
|
||||
|
||||
local column_def = cave_layer_def.columns
|
||||
local double_frequency = cave_layer_def.double_frequency
|
||||
|
||||
@ -58,7 +31,7 @@ function spawnplayer(cave_layer_def, player, ydepth)
|
||||
|
||||
for chunk = 1, 64 do
|
||||
minetest.log("info", "[subterrane] searching for spawn "..chunk)
|
||||
|
||||
|
||||
local minp = {x = sidelen * math.random(-32, 32) - 32, z = sidelen * math.random(-32, 32) - 32, y = ydepth}
|
||||
local maxp = {x = minp.x + sidelen - 1, z = minp.z + sidelen - 1, y = ydepth + sidelen - 1}
|
||||
|
||||
@ -70,18 +43,18 @@ function spawnplayer(cave_layer_def, player, ydepth)
|
||||
nvals_cave[vi] = (value + nvals_wave[vi])/2
|
||||
end
|
||||
local column_points = nil
|
||||
local column_weight = nil
|
||||
|
||||
local column_weight = nil
|
||||
|
||||
local previous_y = minp.y
|
||||
local previous_node_state = outside_region
|
||||
|
||||
|
||||
for vi, x, y, z in cave_area:iterp_yxz(vector.add(minp, 2), vector.subtract(maxp, 2)) do
|
||||
|
||||
|
||||
if y < previous_y then
|
||||
previous_node_state = outside_region
|
||||
end
|
||||
previous_y = y
|
||||
|
||||
|
||||
local cave_local_threshold
|
||||
if y < y_blend_min then
|
||||
cave_local_threshold = TCAVE + ((y_blend_min - y) / BLEND) ^ 2
|
||||
@ -94,12 +67,12 @@ function spawnplayer(cave_layer_def, player, ydepth)
|
||||
local cave_value = nvals_cave[vi]
|
||||
if double_frequency then
|
||||
cave_value = math.abs(cave_value)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- 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
59
test_pos.lua
Normal 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
|
Loading…
x
Reference in New Issue
Block a user