mirror of
https://github.com/mt-mods/plantlife_modpack.git
synced 2025-02-14 16:50:23 +01:00
add support for custom spawn functions
This commit is contained in:
parent
15f62452b8
commit
252c2bd1d2
@ -255,8 +255,7 @@ abstract_bushes.grow_youngtree_node2 = function(pos, height)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
pl.register_on_generate({
|
||||||
biome_lib.register_on_generate({
|
|
||||||
surface = {
|
surface = {
|
||||||
"default:dirt_with_grass",
|
"default:dirt_with_grass",
|
||||||
"stoneage:grass_with_silex",
|
"stoneage:grass_with_silex",
|
||||||
@ -268,6 +267,7 @@ biome_lib.register_on_generate({
|
|||||||
plantlife_limit = bushes_youngtrees_fertility,
|
plantlife_limit = bushes_youngtrees_fertility,
|
||||||
min_elevation = 1, -- above sea level
|
min_elevation = 1, -- above sea level
|
||||||
},
|
},
|
||||||
|
"bushes:youngtrees",
|
||||||
|
nil,
|
||||||
abstract_bushes.grow_youngtree2
|
abstract_bushes.grow_youngtree2
|
||||||
)
|
)
|
||||||
]]--
|
|
@ -1,8 +1,15 @@
|
|||||||
pl = {}
|
pl = {}
|
||||||
local deco_ids = {}
|
local deco = {}
|
||||||
local spawn_funcs = {}
|
|
||||||
|
|
||||||
function pl.register_on_generate(def, plantname, index, func) -- add spawnfunction support
|
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)
|
||||||
if not index then index = 1 end
|
if not index then index = 1 end
|
||||||
local deco_def = {
|
local deco_def = {
|
||||||
name = plantname .. "_" .. index,
|
name = plantname .. "_" .. index,
|
||||||
@ -16,36 +23,50 @@ function pl.register_on_generate(def, plantname, index, func) -- add spawnfuncti
|
|||||||
num_spawn_by = def.near_nodes_count,
|
num_spawn_by = def.near_nodes_count,
|
||||||
decoration = "air"
|
decoration = "air"
|
||||||
}
|
}
|
||||||
deco_ids[#deco_ids+1] = plantname .. ("_" .. index or "_1")
|
local next = #deco + 1
|
||||||
spawn_funcs[#deco_ids+1] = func
|
deco[next] = {}
|
||||||
|
deco[next][1] = deco_def
|
||||||
|
deco[next][2] = func or nil
|
||||||
minetest.register_decoration(deco_def)
|
minetest.register_decoration(deco_def)
|
||||||
|
print(dump(deco))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local ids = {}
|
||||||
minetest.register_on_mods_loaded(function()
|
minetest.register_on_mods_loaded(function()
|
||||||
print(dump(deco_ids))
|
print(dump(deco))
|
||||||
for k, v in pairs(deco_ids) do
|
for k, v in pairs(deco) do
|
||||||
deco_ids[k] = minetest.get_decoration_id(v)
|
local id = minetest.get_decoration_id(deco[k][1].name)
|
||||||
|
deco[k][1].id = id
|
||||||
|
table.insert(ids, id)
|
||||||
end
|
end
|
||||||
minetest.set_gen_notify("decoration", deco_ids)
|
print(dump2(ids))
|
||||||
print(dump(deco_ids))
|
minetest.set_gen_notify("decoration", ids)
|
||||||
|
print(dump2(deco))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_generated(function(minp, maxp, blockseed)
|
minetest.register_on_generated(function(minp, maxp, blockseed)
|
||||||
local g = minetest.get_mapgen_object("gennotify")
|
local g = minetest.get_mapgen_object("gennotify")
|
||||||
print(dump(g))
|
|
||||||
local locations = {}
|
local locations = {}
|
||||||
for _, id in pairs(deco_ids) do
|
for _, id in pairs(ids) do
|
||||||
local deco_locations = g["decoration#" .. id] or {}
|
local deco_locations = g["decoration#" .. id] or {}
|
||||||
for _, pos in pairs(deco_locations) do
|
print("dl: " .. dump2(deco_locations))
|
||||||
locations[#locations+1] = pos
|
for k, pos in pairs(deco_locations) do
|
||||||
|
print(id)
|
||||||
|
local next = #locations + 1
|
||||||
|
locations[next] = {}
|
||||||
|
locations[next].pos = pos
|
||||||
|
locations[next].id = id
|
||||||
|
-- dbg() ^ - This must be ID!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
print(dump(locations))
|
|
||||||
if #locations == 0 then return end
|
if #locations == 0 then return end
|
||||||
for _, pos in ipairs(locations) do
|
print("locations: " .. dump2(locations))
|
||||||
print("yay")
|
for _, t in ipairs(locations) do
|
||||||
abstract_bushes.grow_bush(pos)
|
local def = pl.get_def_from_id(t.id)
|
||||||
|
local spawn_func = def[2]
|
||||||
|
spawn_func(t.pos)
|
||||||
|
abstract_bushes.grow_bush(t.pos)
|
||||||
local player = minetest.get_player_by_name("Niklp")
|
local player = minetest.get_player_by_name("Niklp")
|
||||||
player:set_pos(pos)
|
player:set_pos(t.pos)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
@ -1 +1,2 @@
|
|||||||
name = plantlife_lib
|
name = plantlife_lib
|
||||||
|
optional_depends = dbg
|
Loading…
Reference in New Issue
Block a user