cleanup with luacheck, remove old depends and description files

This commit is contained in:
FaceDeer 2023-09-29 20:15:23 -06:00
parent e5f8457e93
commit 7d0b7e3d4b
7 changed files with 107 additions and 120 deletions

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

@ -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

View File

@ -16,7 +16,6 @@ local c_desert_stone = minetest.get_content_id(subterrane.dependencies.desert_st
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(subterrane.dependencies.water)
local c_obsidian = minetest.get_content_id(subterrane.dependencies.obsidian)
@ -46,8 +45,8 @@ 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
@ -56,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, ", ")
@ -88,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
@ -102,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
@ -115,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
@ -197,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
@ -205,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
@ -278,10 +277,10 @@ subterrane.register_layer = function(cave_layer_def)
if error_out then return end
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
@ -294,7 +293,7 @@ subterrane.register_layer = function(cave_layer_def)
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)..
@ -316,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
@ -337,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
@ -345,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
----------------------------------------------------------------------------------
@ -369,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
@ -381,26 +380,26 @@ 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
@ -408,7 +407,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
-- 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 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
@ -417,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
@ -441,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
@ -454,7 +453,7 @@ 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
-- 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
@ -472,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
@ -535,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]
@ -544,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
@ -583,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
@ -598,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)

View File

@ -69,8 +69,6 @@ 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}))
@ -91,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)
@ -113,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

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
@ -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

View File

@ -4,19 +4,18 @@
-- 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 block_size = mapgen_helper.block_size
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 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
@ -36,14 +35,14 @@ subterrane.is_in_cavern = function(pos)
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
@ -51,13 +50,8 @@ subterrane.get_cavern_value = function(name, pos)
return nil
end
local block_size = mapgen_helper.block_size
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