From ab3c67102997c6f057fb047b978071f7ccc180ee Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Sun, 4 Aug 2019 17:01:29 -0600 Subject: [PATCH] add cave pearls to some level 2 warrens and tunnels --- df_caverns/level2.lua | 34 ++++++++++++-- df_mapitems/cave_pearls.lua | 88 +++++++++++++++++++------------------ 2 files changed, 75 insertions(+), 47 deletions(-) diff --git a/df_caverns/level2.lua b/df_caverns/level2.lua index 555ed71..618f149 100644 --- a/df_caverns/level2.lua +++ b/df_caverns/level2.lua @@ -243,21 +243,29 @@ local decorate_level_2 = function(minp, maxp, seed, vm, node_arrays, area, data) local index2d = mapgen_helper.index2di(minp, maxp, area, vi) local biome_name = get_biome(heatmap[index2d], humiditymap[index2d]) local flooded_caverns = nvals_cave[cave_area:transform(area, vi)] < 0 -- this indicates if we're in the "flooded" set of caves or not. + local ystride = area.ystride if not (flooded_caverns and minp.y < subsea_level and area:get_y(vi) < subsea_level) then - if flooded_caverns or biome_name ~= "barren" then + if flooded_caverns or biome_name ~= "barren" then -- we're in flooded areas or are not barren df_caverns.tunnel_ceiling(minp, maxp, area, vi, nvals_cracks, data, data_param2, true) else df_caverns.tunnel_ceiling(minp, maxp, area, vi, nvals_cracks, data, data_param2, false) end + if not flooded_caverns and (biome_name == "barren" or biome_name == "sporetree") and nvals_cracks[index2d] > 0.5 then + for i= 1, 4 do + if math.random() > 0.5 then + df_mapitems.place_wall_pearls(vi-i*ystride, area, data, data_param2) + end + end + end else -- air pockets local ystride = area.ystride local cracks = nvals_cracks[index2d] - if cracks > 0.5 and data[vi-ystride] == c_water then + if cracks > 0.4 and data[vi-ystride] == c_water then data[vi-ystride] = c_air - if cracks > 0.7 and data[vi-ystride*2] == c_water then + if cracks > 0.6 and data[vi-ystride*2] == c_water then data[vi-ystride*2] = c_air end end @@ -289,6 +297,7 @@ local decorate_level_2 = function(minp, maxp, seed, vm, node_arrays, area, data) local index2d = mapgen_helper.index2di(minp, maxp, area, vi) local biome_name = get_biome(heatmap[index2d], humiditymap[index2d]) local flooded_caverns = nvals_cave[cave_area:transform(area, vi)] < 0 -- this indicates if we're in the "flooded" set of caves or not. + local ystride = area.ystride if not (flooded_caverns and minp.y < subsea_level and area:get_y(vi) < subsea_level) then if flooded_caverns or biome_name ~= "barren" then @@ -297,8 +306,25 @@ local decorate_level_2 = function(minp, maxp, seed, vm, node_arrays, area, data) else df_caverns.tunnel_ceiling(minp, maxp, area, vi, nvals_cracks, data, data_param2, false) end + + if not flooded_caverns and (biome_name == "barren" or biome_name == "sporetree") and nvals_cracks[index2d] > 0.5 then + for i= 1, 4 do + if math.random() > 0.5 then + df_mapitems.place_wall_pearls(vi-i*ystride, area, data, data_param2) + end + end + end + else + -- air pockets + local cracks = nvals_cracks[index2d] + if cracks > 0.4 and data[vi-ystride] == c_water then + data[vi-ystride] = c_air + if cracks > 0.6 and data[vi-ystride*2] == c_water then + data[vi-ystride*2] = c_air + end + end end - -- else air pockets? + end ---------------------------------------------- diff --git a/df_mapitems/cave_pearls.lua b/df_mapitems/cave_pearls.lua index 673f768..ba849d7 100644 --- a/df_mapitems/cave_pearls.lua +++ b/df_mapitems/cave_pearls.lua @@ -67,43 +67,12 @@ local pearl_on_place = function(itemstack, placer, pointed_thing) return itemstack end -local valid_mounting_node = function(pos) - local node = minetest.get_node(pos) - if not node then return false end - local def = minetest.registered_nodes[node.name] - if not def then return false end - if def.buildable_to then return false end - return true -end - local add_to_table = function(dest, source) for _, val in ipairs(source) do table.insert(dest, val) end end -local get_valid_facedirs = function(pos) - local dirs = {} - if valid_mounting_node(vector.add(pos, {x=1,y=0,z=0})) then - add_to_table(dirs, {16, 17, 18, 19}) - end - if valid_mounting_node(vector.add(pos, {x=-1,y=0,z=0})) then - add_to_table(dirs, {12, 13, 14, 15}) - end - if valid_mounting_node(vector.add(pos, {x=0,y=1,z=0})) then - add_to_table(dirs, {0, 1, 2, 3}) - end - if valid_mounting_node(vector.add(pos, {x=0,y=-1,z=0})) then - add_to_table(dirs, {20, 21, 22, 23}) - end - if valid_mounting_node(vector.add(pos, {x=0,y=0,z=1})) then - add_to_table(dirs, {8, 9, 10, 11}) - end - if valid_mounting_node(vector.add(pos, {x=0,y=0,z=-1})) then - add_to_table(dirs, {4, 5, 6, 7}) - end -end - minetest.register_node("df_mapitems:wall_pearls", { description = S("Cave Pearls"), tiles = {"dfcaverns_cave_pearl.png"}, @@ -126,28 +95,61 @@ minetest.register_node("df_mapitems:wall_pearls", { }) local c_air = minetest.get_content_id("air") -local c_stone = minetest.get_content_id("default:stone") local c_pearls = minetest.get_content_id("df_mapitems:wall_pearls") +local valid_nodes = {} -- cache values +local is_valid_mounting_node = function(c_node) + if valid_nodes[c_node] ~= nil then + return valid_nodes[c_node] + end + local def = minetest.registered_nodes[minetest.get_name_from_content_id(c_node)] + if def ~= nil and (def.drawtype == "normal" or def.drawtype == nil) and (not def.buildable_to) then + valid_nodes[c_node] = true + return true + end + valid_nodes[c_node] = false + return false +end + --facing +x: 16, 17, 18, 19, --facing -x: 12, 13, 14, 15 --facing +z: 8, 9, 10, 11 --facing -z: 4, 5, 6, 7 --facing -y: 20, 21, 22, 23, (ceiling) +--facing +y: 0, 1, 2, 3 + +local get_valid_facedirs_vm = function(vi, area, data) + local dirs = {} + local ystride = area.ystride + local zstride = area.zstride + if is_valid_mounting_node(data[vi+1]) then + add_to_table(dirs, {16, 17, 18, 19}) + end + if is_valid_mounting_node(data[vi-1]) then + add_to_table(dirs, {12, 13, 14, 15}) + end + if is_valid_mounting_node(data[vi-ystride]) then + add_to_table(dirs, {0, 1, 2, 3}) + end + if is_valid_mounting_node(data[vi+ystride]) then + add_to_table(dirs, {20, 21, 22, 23}) + end + if is_valid_mounting_node(data[vi+zstride]) then + add_to_table(dirs, {8, 9, 10, 11}) + end + if is_valid_mounting_node(data[vi-zstride]) then + add_to_table(dirs, {4, 5, 6, 7}) + end + return dirs +end + df_mapitems.place_wall_pearls = function(vi, area, data, data_param2) if data[vi] == c_air then - if data[vi+1] == c_stone then -- positive X + local facedirs = get_valid_facedirs_vm(vi, area, data) + local count = #facedirs + if count > 0 then data[vi] = c_pearls - data_param2[vi] = 15 + math.random(1,4) - elseif data[vi-1] == c_stone then -- negative X - data[vi] = c_pearls - data_param2[vi] = 11 + math.random(1,4) - elseif data[vi+area.zstride] == c_stone then -- positive Z - data[vi] = c_pearls - data_param2[vi] = 7 + math.random(1,4) - elseif data[vi-area.zstride] == c_stone then -- negative Z - data[vi] = c_pearls - data_param2[vi] = 3 + math.random(1,4) + data_param2[vi] = facedirs[math.random(1, count)] end end end