add rare big webs to the chasms, to give them a unique feature

This commit is contained in:
FaceDeer
2021-03-27 03:51:58 -06:00
parent d2b5443a25
commit c6f26e5bec
7 changed files with 193 additions and 2 deletions

View File

@ -4,6 +4,8 @@ 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 web_probability = 0.1 -- the chance that a given mapblock will have webbing criss-crossing the chasm
local chasms_threshold = tonumber(minetest.settings:get("chasms_threshold")) or 0.9
local np_chasms_default = {
offset = 0,
@ -61,12 +63,44 @@ local get_intensity = function(y)
end
local c_air = minetest.get_content_id("air")
local c_web
local big_webs_path = minetest.get_modpath("big_webs")
if big_webs_path then
c_web = minetest.get_content_id("big_webs:webbing")
end
local z_displace = 10000
minetest.register_on_generated(function(minp, maxp, seed)
if minp.y >= maxy or maxp.y <= miny then
return
end
-- build a set of web patterns
local webs
if big_webs_path then
local seed = math.random()*10000000
math.randomseed(minp.y + z_displace*minp.z) -- use consistent seeds across the x axis
if math.random() < web_probability then
webs = {}
for count = 1, math.random(10,30) do
local width = math.random(5, 20)
local direction_vertical = math.random() > 0.5
local web_y = math.random(minp.y+8, maxp.y-8)
local web_z = math.random(minp.z+8, maxp.z-8)
for i = -math.floor(width/2), math.ceil(width/2) do
if direction_vertical then
webs[(web_y+i) + web_z*z_displace] = true
else
webs[web_y + (web_z+i)*z_displace] = true
end
end
end
end
math.randomseed(seed)
end
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
vm:get_data(data)
@ -83,9 +117,19 @@ minetest.register_on_generated(function(minp, maxp, seed)
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
data[i] = c_air
if webs then
if webs[y + z*z_displace] and math.random() < 0.85 then -- random holes in the web
data[i] = c_web
minetest.get_node_timer({x=x,y=y,z=z}):start(1) -- this timer will check for unsupported webs
else
data[i] = c_air
end
else
data[i] = c_air
end
end
end
vm:set_data(data)
vm:calc_lighting()
vm:write_to_map()

View File

@ -1,3 +1,3 @@
name=chasms
depends=mapgen_helper
optional_depends=df_caverns
optional_depends=df_caverns, big_webs