structs: use mcl_register_generator, cave decos

This commit is contained in:
cora 2022-06-22 15:56:51 +02:00
parent eb8db0dc0b
commit fed81932e2
3 changed files with 99 additions and 73 deletions

View File

@ -3356,6 +3356,29 @@ local function register_decorations()
rotation = "0",
})
--Mushrooms in caves
minetest.register_decoration({
deco_type = "simple",
place_on = {"group:material_stone"},
sidelen = 80,
fill_ratio = 0.009,
noise_threshold = 2.0,
flags = "all_floors",
y_min = mcl_vars.mg_overworld_min,
y_max = mcl_vars.mg_overworld_max,
decoration = "mcl_mushrooms:mushroom_red",
})
minetest.register_decoration({
deco_type = "simple",
place_on = {"group:material_stone"},
sidelen = 80,
fill_ratio = 0.009,
noise_threshold = 2.0,
y_min = mcl_vars.mg_overworld_min,
y_max = mcl_vars.mg_overworld_max,
decoration = "mcl_mushrooms:mushroom_brown",
})
-- Mossy cobblestone boulder (3×3)
minetest.register_decoration({
deco_type = "schematic",

View File

@ -1720,7 +1720,7 @@ local function generate_tree_decorations(minp, maxp, seed, data, param2_data, ar
end
-- Generate mushrooms in caves manually.
-- Minetest's API does not support decorations in caves yet. :-(
-- only v6. minetest supports cave decos via "all_floors" flag now
local function generate_underground_mushrooms(minp, maxp, seed)
local pr_shroom = PseudoRandom(seed-24359)
-- Generate rare underground mushrooms
@ -1756,7 +1756,6 @@ end
-- Generate Nether decorations manually: Eternal fire, mushrooms, nether wart
-- (only v6)
local function generate_nether_decorations(minp, maxp, seed)
if mg_name == "v6" then
local pr_nether = PseudoRandom(seed+667)
if minp.y > mcl_vars.mg_nether_max or maxp.y < mcl_vars.mg_nether_min then
@ -1816,7 +1815,6 @@ local function generate_nether_decorations(minp, maxp, seed)
minetest.set_node(bpos, {name = "mcl_nether:nether_wart"})
end
end)
end
end
minetest.register_on_generated(function(minp, maxp, blockseed)
@ -2200,10 +2198,24 @@ end
local function basic_node(minp, maxp, blockseed)
if mg_name ~= "singlenode" then
-- Generate special decorations
if mg_name == "v6" then
generate_underground_mushrooms(minp, maxp, blockseed)
generate_nether_decorations(minp, maxp, blockseed)
end
generate_structures(minp, maxp, blockseed, minetest.get_mapgen_object("biomemap"))
end
end
mcl_mapgen_core.register_generator("main", basic, basic_node, 1, true)
mcl_mapgen_core.register_generator("structures",nil, function(minp, maxp, blockseed)
local gennotify = minetest.get_mapgen_object("gennotify")
local pr = PseudoRandom(blockseed + 42)
for _,struct in pairs(mcl_structures.registered_structures) do
for _, pos in pairs(gennotify["decoration#"..struct.deco_id] or {}) do
local realpos = vector.offset(pos,0,-1,0)
minetest.remove_node(realpos)
mcl_structures.place_structure(realpos,struct,pr)
end
end
end, 100, true)

View File

@ -53,17 +53,8 @@ function mcl_structures.register_structure(name,def,nospawn) --nospawn means it
y_max = def.y_max,
y_min = def.y_min
})
local deco_id = minetest.get_decoration_id("mcl_structures:deco_"..name)
minetest.set_gen_notify({decoration=true}, { deco_id })
minetest.register_on_generated(function(minp, maxp, blockseed)
local gennotify = minetest.get_mapgen_object("gennotify")
local pr = PseudoRandom(blockseed + 42)
for _, pos in pairs(gennotify["decoration#"..deco_id] or {}) do
local realpos = vector.offset(pos,0,-1,0)
minetest.remove_node(realpos)
mcl_structures.place_structure(realpos,def,pr)
end
end)
def.deco_id = minetest.get_decoration_id("mcl_structures:deco_"..name)
minetest.set_gen_notify({decoration=true}, { def.deco_id })
end
minetest.register_node(":"..structblock, {drawtype="airlike", walkable = false, pointable = false,groups = sbgroups})
def.structblock = structblock