2023-04-12 14:12:51 +02:00
|
|
|
pl = {}
|
2023-04-12 17:00:18 +02:00
|
|
|
local deco = {}
|
2023-04-12 14:12:51 +02:00
|
|
|
|
2023-04-12 17:00:18 +02:00
|
|
|
function pl.get_def_from_id(id)
|
|
|
|
for i, _ in pairs(deco) do
|
|
|
|
if deco[i][1].id and deco[i][1].id == id then
|
|
|
|
return deco[i]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function pl.register_on_generate(def, plantname, index, func)
|
2023-04-12 17:52:29 +02:00
|
|
|
if not index then index = 1 end -- Do we need `index`?
|
|
|
|
local deco_def = { -- This needs some good values (and noise param support)
|
2023-04-12 14:12:51 +02:00
|
|
|
name = plantname .. "_" .. index,
|
|
|
|
deco_type = "simple",
|
|
|
|
place_on = def.place_on or def.surface,
|
|
|
|
sidelen = 16,
|
|
|
|
fill_ratio = def.fill_ratio or 0.001,
|
|
|
|
y_min = def.min_elevation,
|
|
|
|
y_max = def.max_elevation,
|
|
|
|
spawn_by = def.near_nodes,
|
|
|
|
num_spawn_by = def.near_nodes_count,
|
|
|
|
decoration = "air"
|
|
|
|
}
|
2023-04-12 17:00:18 +02:00
|
|
|
local next = #deco + 1
|
|
|
|
deco[next] = {}
|
|
|
|
deco[next][1] = deco_def
|
|
|
|
deco[next][2] = func or nil
|
2023-04-12 14:12:51 +02:00
|
|
|
minetest.register_decoration(deco_def)
|
2023-04-12 17:00:18 +02:00
|
|
|
print(dump(deco))
|
2023-04-12 14:12:51 +02:00
|
|
|
end
|
|
|
|
|
2023-04-12 17:00:18 +02:00
|
|
|
local ids = {}
|
2023-04-12 14:12:51 +02:00
|
|
|
minetest.register_on_mods_loaded(function()
|
2023-04-12 17:52:29 +02:00
|
|
|
-- print(dump(deco))
|
2023-04-12 17:00:18 +02:00
|
|
|
for k, v in pairs(deco) do
|
|
|
|
local id = minetest.get_decoration_id(deco[k][1].name)
|
|
|
|
deco[k][1].id = id
|
|
|
|
table.insert(ids, id)
|
2023-04-12 14:12:51 +02:00
|
|
|
end
|
2023-04-12 17:52:29 +02:00
|
|
|
-- print(dump2(ids))
|
2023-04-12 17:00:18 +02:00
|
|
|
minetest.set_gen_notify("decoration", ids)
|
2023-04-12 17:52:29 +02:00
|
|
|
-- print(dump(deco))
|
2023-04-12 14:12:51 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_generated(function(minp, maxp, blockseed)
|
|
|
|
local g = minetest.get_mapgen_object("gennotify")
|
|
|
|
local locations = {}
|
2023-04-12 17:00:18 +02:00
|
|
|
for _, id in pairs(ids) do
|
2023-04-12 14:12:51 +02:00
|
|
|
local deco_locations = g["decoration#" .. id] or {}
|
2023-04-12 17:52:29 +02:00
|
|
|
-- print("dl: " .. dump2(deco_locations))
|
2023-04-12 17:00:18 +02:00
|
|
|
for k, pos in pairs(deco_locations) do
|
2023-04-12 17:52:29 +02:00
|
|
|
-- print(id)
|
2023-04-12 17:00:18 +02:00
|
|
|
local next = #locations + 1
|
|
|
|
locations[next] = {}
|
|
|
|
locations[next].pos = pos
|
|
|
|
locations[next].id = id
|
|
|
|
-- dbg() ^ - This must be ID!
|
2023-04-12 14:12:51 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if #locations == 0 then return end
|
2023-04-12 17:52:29 +02:00
|
|
|
-- print("locations: " .. dump2(locations))
|
2023-04-12 17:00:18 +02:00
|
|
|
for _, t in ipairs(locations) do
|
|
|
|
local def = pl.get_def_from_id(t.id)
|
|
|
|
local spawn_func = def[2]
|
|
|
|
spawn_func(t.pos)
|
2023-04-12 17:52:29 +02:00
|
|
|
-- local player = minetest.get_player_by_name("Niklp")
|
|
|
|
-- player:set_pos(t.pos)
|
2023-04-12 14:12:51 +02:00
|
|
|
end
|
2023-04-12 17:52:29 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
--[[ Example plant
|
|
|
|
{
|
|
|
|
{
|
|
|
|
y_min = 1,
|
|
|
|
decoration = "air",
|
|
|
|
deco_type = "simple",
|
|
|
|
id = 45,
|
|
|
|
name = "bushes:bushes_1",
|
|
|
|
place_on = {
|
|
|
|
"default:dirt_with_grass",
|
|
|
|
"stoneage:grass_with_silex",
|
|
|
|
"sumpf:peat",
|
|
|
|
"sumpf:sumpf"
|
|
|
|
},
|
|
|
|
sidelen = 16,
|
|
|
|
fill_ratio = 0.001
|
|
|
|
},
|
|
|
|
^ - decoration def; object ID
|
|
|
|
<function>
|
|
|
|
}, ^ - spawn function
|
|
|
|
]]--
|