use gennotify for lakegen

This commit is contained in:
cora 2022-06-07 04:22:50 +02:00
parent 81cc114a0f
commit eaa06289a1
2 changed files with 21 additions and 16 deletions

View File

@ -2451,7 +2451,7 @@ local function register_dimension_ores()
end
local deco_id_makelake
-- All mapgens except mgv6
-- Template to register a grass or fern decoration
@ -4389,13 +4389,14 @@ local function register_decorations()
})
minetest.register_decoration({
name = "mcl_biomes:lake_structblock",
decoration = "mcl_lush_caves:lake_structblock",
deco_type = "simple",
place_on = {"group:material_stone","mcl_core:gravel","mcl_lush_caves:moss","mcl_core:clay"},
spawn_by = {"air"},
num_spawn_by = 4,
sidelen = 16,
fill_ratio = 10,
fill_ratio = 4,
flags = "place_center_x, place_center_z, force_placement, all_floors",
biomes = lushcaves,
})
@ -4825,6 +4826,9 @@ local function register_dimension_decorations()
deco_id_chorus_plant = minetest.get_decoration_id("mcl_biomes:chorus_plant")
minetest.set_gen_notify({decoration=true}, { deco_id_chorus_plant })
deco_id_makelake = minetest.get_decoration_id("mcl_biomes:lake_structblock")
minetest.set_gen_notify({decoration=true}, { deco_id_makelake })
-- TODO: End cities
end
@ -4895,4 +4899,16 @@ if mg_name ~= "singlenode" then
end)
end
mcl_mapgen_core.register_generator("mcl_lush_caves:lakegen", nil, function(minp, maxp, blockseed)
local gennotify = minetest.get_mapgen_object("gennotify")
local pr = PseudoRandom(blockseed + 15)
for _, pos in ipairs(gennotify["decoration#"..deco_id_makelake] or {}) do
local realpos = vector.offset(pos,0,1,0)
local node = minetest.get_node(realpos)
if node and node.name == "mcl_lush_caves:lake_structblock" then
minetest.remove_node(realpos)
mcl_lush_caves.makelake(realpos, pr)
end
end
end)
end

View File

@ -1,6 +1,5 @@
local S = minetest.get_translator(minetest.get_current_modname())
local pr = PseudoRandom(minetest.get_mapgen_setting("seed"))
local adjacents = {
vector.new(1,0,0),
vector.new(-1,0,0),
@ -14,8 +13,8 @@ local vector_distance_xz = function(a, b)
{ x=b.x, y=0, z=b.z }
)
end
local function makelake(pos)
mcl_lush_caves = {}
function mcl_lush_caves.makelake(pos,pr)
local p1 = vector.offset(pos,-5,-2,-5)
local p2 = vector.offset(pos,5,1,5)
local nn = minetest.find_nodes_in_area_under_air(p1,p2,{"group:material_stone","mcl_core:clay"})
@ -23,7 +22,7 @@ local function makelake(pos)
return vector_distance_xz(pos, a) < vector_distance_xz(pos, b)
end)
if not nn[1] then return end
for i=1,math.random(#nn) do
for i=1,pr:next(1,#nn) do
minetest.set_node(nn[i],{name="mcl_core:water_source"})
end
local nnn = minetest.find_nodes_in_area_under_air(p1,p2,{"mcl_core:water_source","group:water"})
@ -348,13 +347,3 @@ minetest.register_abm({
end
end
})
minetest.register_lbm({
name = "mcl_lush_caves:make_lakes",
run_at_every_load = true,
nodenames = {"mcl_lush_caves:lake_structblock"},
action = function(pos, node)
minetest.set_node(pos,{name="air"})
makelake(pos)
end
})