remove duplicated legacy code, add a get_cavern_value method, and store registered layers by name
This commit is contained in:
parent
2e523b1ba1
commit
40215b772e
15
init.lua
15
init.lua
@ -276,8 +276,6 @@ subterrane.register_layer = function(cave_layer_def)
|
|||||||
error_out = true
|
error_out = true
|
||||||
end
|
end
|
||||||
if error_out then return end
|
if error_out then return end
|
||||||
|
|
||||||
local cave_name = cave_layer_def.name
|
|
||||||
|
|
||||||
subterrane.set_defaults(cave_layer_def)
|
subterrane.set_defaults(cave_layer_def)
|
||||||
|
|
||||||
@ -287,21 +285,26 @@ subterrane.register_layer = function(cave_layer_def)
|
|||||||
if cave_layer_def.name == nil then
|
if cave_layer_def.name == nil then
|
||||||
cave_layer_def.name = tostring(YMIN) .. " to " .. tostring(YMAX)
|
cave_layer_def.name = tostring(YMIN) .. " to " .. tostring(YMAX)
|
||||||
end
|
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
|
local block_size = mapgen_helper.block_size
|
||||||
|
|
||||||
if (YMAX+32+1)%block_size ~= 0 then
|
if (YMAX+32+1)%block_size ~= 0 then
|
||||||
local boundary = YMAX -(YMAX+32+1)%block_size
|
local boundary = YMAX -(YMAX+32+1)%block_size
|
||||||
minetest.log("warning", "[subterrane] The y_max setting "..tostring(YMAX)..
|
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.")
|
tostring(boundary) .. " or " .. tostring(boundary+block_size) .. " for maximum mapgen efficiency.")
|
||||||
end
|
end
|
||||||
if (YMIN+32)%block_size ~= 0 then
|
if (YMIN+32)%block_size ~= 0 then
|
||||||
local boundary = YMIN - (YMIN+32)%block_size
|
local boundary = YMIN - (YMIN+32)%block_size
|
||||||
minetest.log("warning", "[subterrane] The y_min setting "..tostring(YMIN)..
|
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.")
|
tostring(boundary) .. " or " .. tostring(boundary+block_size) .. " for maximum mapgen efficiency.")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
20
legacy.lua
20
legacy.lua
@ -448,26 +448,6 @@ function subterrane:vertically_consistent_random(vi, area)
|
|||||||
return subterrane:vertically_consistent_randomp(pos)
|
return subterrane:vertically_consistent_randomp(pos)
|
||||||
end
|
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)
|
subterrane.get_point_heat = function(pos, points)
|
||||||
local heat = 0
|
local heat = 0
|
||||||
for _, point in ipairs(points) do
|
for _, point in ipairs(points) do
|
||||||
|
24
test_pos.lua
24
test_pos.lua
@ -38,4 +38,28 @@ subterrane.is_in_cavern = function(pos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return results
|
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 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
|
||||||
|
return nval_cave
|
||||||
end
|
end
|
Loading…
x
Reference in New Issue
Block a user