This commit is contained in:
Jouni 2024-11-13 14:37:27 +02:00
commit b0f7f905d6
5 changed files with 156 additions and 0 deletions

21
LICENSE.txt Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 FaceDeer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

4
README.txt Normal file
View File

@ -0,0 +1,4 @@
Adds deep underground chasms to the world.
Copied from:
https://github.com/FaceDeer/dfcaverns/tree/master/chasms

124
init.lua Normal file
View File

@ -0,0 +1,124 @@
local data = {}
chasms = {}
local ignore = {}
-- Use this to set node types to be left alone by chasm-carving
chasms.register_ignore = function(node_name)
ignore[minetest.get_content_id(node_name)] = true
end
chasms.ignore_content_id = function(content_id)
return ignore[content_id]
end
local maxy = tonumber(minetest.settings:get("chasms_maxy")) or -50
local miny = tonumber(minetest.settings:get("chasms_miny")) or -2500
local falloff = tonumber(minetest.settings:get("chasms_falloff")) or 100
local chasms_threshold = tonumber(minetest.settings:get("chasms_threshold")) or 0.9
local np_chasms_default = {
offset = 0,
scale = 1,
spread = {x = 50, y = 1000, z = 3000},
seed = 94586,
octaves = 2,
persist = 0.63,
lacunarity = 2.0,
}
local np_chasms = minetest.settings:get_np_group("chasms_params") or np_chasms_default
local nobj_chasm
local chasm_data = {}
local waver_strength = 8
local waver_vector = {x=waver_strength, y=0, z=0}
local np_waver = {
offset = 0,
scale = waver_strength,
spread = {x = 50, y = 50, z = 50},
seed = 49585,
octaves = 2,
persist = 0.63,
lacunarity = 2.0,
}
local nobj_waver
local waver_data = {}
local minfalloff = miny + falloff
local maxfalloff = maxy - falloff
local get_intensity = function(y)
if y < miny or y > maxy then
return 0
end
if y <= maxfalloff and y >= minfalloff then
return 1
end
if y < minfalloff then
return (y-miny)/falloff
end
-- if y > maxfalloff then
return (maxy-y)/falloff
-- end
end
local c_air = minetest.get_content_id("air")
local log_location
if mapgen_helper.log_location_enabled then
log_location = mapgen_helper.log_first_location
end
minetest.register_on_generated(function(minp, maxp, seed)
if minp.y >= maxy or maxp.y <= miny then
return
end
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
vm:get_data(data)
nobj_chasm = nobj_chasm or minetest.get_perlin_map(np_chasms, {x = emax.x - emin.x + 1 + waver_strength*2, y = emax.y - emin.y + 1, z = emax.z - emin.z + 1})
nobj_chasm:get_3d_map_flat(vector.subtract(emin, waver_vector), chasm_data)
nobj_waver = nobj_waver or minetest.get_perlin_map(np_waver, {x = emax.x - emin.x + 1, y = emax.y - emin.y + 1, z = emax.z - emin.z + 1})
nobj_waver:get_3d_map_flat(emin, waver_data)
local chasm_area = VoxelArea:new{MinEdge = vector.subtract(emin, waver_vector), MaxEdge = vector.add(emax, waver_vector)}
local data_area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
for i, x, y, z in data_area:iterp_xyz(emin, emax) do
local waver = math.min(math.max(math.floor(waver_data[i]+0.5), -waver_strength), waver_strength)
local intensity = get_intensity(y)
if chasm_data[chasm_area:index(x+waver, y, z)]*intensity > chasms_threshold then
if not ignore[data[i]] then
data[i] = c_air
if log_location then log_location("chasm", vector.new(x,y,z)) end
end
end
end
vm:set_data(data)
vm:calc_lighting()
vm:write_to_map()
end)
local nobj_local_chasm = minetest.get_perlin(np_chasms)
local nobj_local_waver = minetest.get_perlin(np_waver)
chasms.is_in_chasm = function(pos)
nobj_local_chasm = nobj_local_chasm or minetest.get_perlin(np_chasms)
nobj_local_waver = nobj_local_waver or minetest.get_perlin(np_waver)
local waver = math.min(math.max(math.floor(nobj_local_waver:get_3d(pos)+0.5), -waver_strength), waver_strength)
local chasm_value = nobj_local_chasm:get_3d({x=pos.x+waver, y=pos.y, z=pos.z})
return chasm_value*get_intensity(pos.y) > chasms_threshold
end
-- A little cheaper to run, for mapgens that know they don't have to worry about the tops and bottoms of chasms
chasms.is_in_chasm_without_taper = function(pos)
nobj_local_chasm = nobj_local_chasm or minetest.get_perlin(np_chasms)
nobj_local_waver = nobj_local_waver or minetest.get_perlin(np_waver)
local waver = math.min(math.max(math.floor(nobj_local_waver:get_3d(pos)+0.5), -waver_strength), waver_strength)
local chasm_value = nobj_local_chasm:get_3d({x=pos.x+waver, y=pos.y, z=pos.z})
return chasm_value > chasms_threshold
end

2
mod.conf Normal file
View File

@ -0,0 +1,2 @@
name=chasms
depends=mapgen_helper

5
settingtypes.txt Normal file
View File

@ -0,0 +1,5 @@
chasms_params (Noise params for chasms) noise_params_3d 0, 1, (50, 1000, 3000), 94586, 2, 0.63, 2.0
chasms_threshold (Noise threshold for chasms) float 0.9
chasms_maxy (Maximum Y) int -50
chasms_miny (Minimum Y) int -2500
chasms_falloff (Taper range when approaching max or min) int 100