Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try out lsystem decoration #51

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 35 additions & 27 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ function translate_biome_defs(def, treename, index)
if not index then index = 1 end
local deco_def = {
name = treename .. "_" .. index,
deco_type = "simple",
place_on = def.place_on,
sidelen = 16,
fill_ratio = def.fill_ratio or 0.001,
Expand All @@ -143,9 +142,16 @@ function translate_biome_defs(def, treename, index)
y_max = def.max_elevation,
spawn_by = def.spawn_by,
num_spawn_by = def.num_spawn_by,
decoration = "moretrees:"..treename.."_sapling_ongen"
}

if minetest.features.lsystem_decoration_type then
deco_def.deco_type = "lsystem"
deco_def.treedef = moretrees[treename .. "_model"]
else
deco_def.deco_type = "simple"
deco_def.decoration = "moretrees:"..treename.."_sapling_ongen"
end

deco_ids[#deco_ids+1] = treename .. ("_" .. index or "_1")

return deco_def
Expand Down Expand Up @@ -176,33 +182,35 @@ minetest.register_decoration(translate_biome_defs(moretrees.poplar_biome_3, "pop
minetest.register_decoration(translate_biome_defs(moretrees.poplar_small_biome, "poplar_small", 4))
minetest.register_decoration(translate_biome_defs(moretrees.poplar_small_biome_2, "poplar_small", 5))

--[[
this is purposefully wrapped in a on mods loaded callback to that it gets the proper ids
if other mods clear the registered decorations
]]
minetest.register_on_mods_loaded(function()
for k, v in pairs(deco_ids) do
deco_ids[k] = minetest.get_decoration_id(v)
end
minetest.set_gen_notify("decoration", deco_ids)
end)

minetest.register_on_generated(function(minp, maxp, blockseed)
local g = minetest.get_mapgen_object("gennotify")
local locations = {}
for _, id in pairs(deco_ids) do
local deco_locations = g["decoration#" .. id] or {}
for _, pos in pairs(deco_locations) do
locations[#locations+1] = pos
if not minetest.features.lsystem_decoration_type then
--[[
this is purposefully wrapped in a on mods loaded callback to that it gets the proper ids
if other mods clear the registered decorations
]]
minetest.register_on_mods_loaded(function()
for k, v in pairs(deco_ids) do
deco_ids[k] = minetest.get_decoration_id(v)
end
minetest.set_gen_notify("decoration", deco_ids)
end)

minetest.register_on_generated(function(minp, maxp, blockseed)
local g = minetest.get_mapgen_object("gennotify")
local locations = {}
for _, id in pairs(deco_ids) do
local deco_locations = g["decoration#" .. id] or {}
for _, pos in pairs(deco_locations) do
locations[#locations+1] = pos
end
end
end

if #locations == 0 then return end
for _, pos in ipairs(locations) do
local timer = minetest.get_node_timer({x=pos.x, y=pos.y+1, z=pos.z})
timer:start(math.random(2,10))
end
end)
if #locations == 0 then return end
for _, pos in ipairs(locations) do
local timer = minetest.get_node_timer({x=pos.x, y=pos.y+1, z=pos.z})
timer:start(math.random(2,10))
end
end)
end

-- Code to spawn a birch tree

Expand Down
3 changes: 1 addition & 2 deletions tree_models.lua
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,14 @@ moretrees.jungletree_model={
trunk_type=nil,
thin_branches=true,
fruit_chance=15,
fruit="vines:vine"
}

moretrees.fir_model={
axiom="FFFAF[&&-F][&&+F][&&---F][&&+++F]Fff",
rules_a=nil,
rules_b=nil,
trunk="moretrees:fir_trunk",
leaves=nil,
leaves="moretrees:fir_leaves",
angle=45,
iterations=7,
random_level=5,
Expand Down