diff --git a/mods/ebiometrees/api.lua b/mods/ebiometrees/api.lua index 529e25b..6f73561 100644 --- a/mods/ebiometrees/api.lua +++ b/mods/ebiometrees/api.lua @@ -1,16 +1,22 @@ ebiometrees.registered_trees = {} -function ebiometrees.register_tree(name, data) - ebiometrees.registered_trees[name] = data +function ebiometrees.register_tree(name, treespec) + ebiometrees.registered_trees[name] = treespec ebiometrees.register_subnodes(name) end function ebiometrees.register_subnodes(tree_name) local modname = tree_name:match("([^:]*):") local basename = tree_name:match(":([^:]+)") - local data = ebiometrees.registered_trees[tree_name] - ebiometrees.register_tree_sapling(modname, basename, data) - ebiometrees.register_tree_sprout(modname, basename, data) - ebiometrees.register_tree_leaves(modname, basename, data) - ebiometrees.register_tree_trunks(modname, basename, data) + local treespec = ebiometrees.registered_trees[tree_name] + ebiometrees.register_tree_sapling(modname, basename, treespec) + ebiometrees.register_tree_sprout(modname, basename, treespec) + ebiometrees.register_tree_leaves(modname, basename, treespec) + ebiometrees.register_tree_trunks(modname, basename, treespec) end + +function ebiometrees.get_tree_leaves(tree_name) + return tree_name.."_leaves" +end + + diff --git a/mods/ebiometrees/sapling.lua b/mods/ebiometrees/sapling.lua index 07374d6..c46f518 100644 --- a/mods/ebiometrees/sapling.lua +++ b/mods/ebiometrees/sapling.lua @@ -17,10 +17,8 @@ function ebiometrees.where_to_grow_trunk_closure(grow_preferences, leaves_name) corner1 = pos:add({x=-1, y=-1, z=-1}):add(candidate_dir:multiply(2)) corner2 = pos:add({x= 1, y= 1, z= 1}):add(candidate_dir:multiply(2)) local spacious, _ = minetest.find_nodes_in_area( - corner1, corner2, "group:treetrunk" + corner1, corner2, {"group:treetrunk", "group:dirt" } ) - minetest.chat_send_all(dump2(spacious)) - minetest.chat_send_all(#spacious) if node and node.name == leaves_name and #spacious == 0 then return candidate @@ -45,6 +43,7 @@ function ebiometrees.grow_trunk_closure(trunk_terminal_name, grow_preferences, l minetest.set_node(there, {name=trunk_terminal_name}) local newmeta = minetest.get_meta(there) newmeta:set_int("ebiometrees:distance", meta:get_int("ebiometrees:distance")+1) + meta:set_int("ebiometrees:distance", meta:get_int("ebiometrees:distance")+1) end end return grow_trunk @@ -63,11 +62,17 @@ function ebiometrees.grow_leaves_closure(leaves_name) return grow_leaves end +function ebiometrees.tree_timer_lifecycle_closure(tree_name) + leaves_name = tree_name.."_leaves" + terminal_name = tree_name.."_trunk_growing_terminal" + nextstage = tree_name.."_trunk_normal_terminal" + grow_preferences = ebiometrees.registered_trees[tree_name]["growth_preferences"] + age_max = ebiometrees.registered_trees[tree_name]["age_max"] + grow_limit = ebiometrees.registered_trees[tree_name]["growth_limit"] -function ebiometrees.tree_grower(leaves_name, grow_preferences, terminal_name, nextstage, age_max, grow_limit) local grow_trunk = ebiometrees.grow_trunk_closure(terminal_name, grow_preferences, leaves_name, grow_limit) local grow_leaves = ebiometrees.grow_leaves_closure(leaves_name) - local function grow_tree(pos) + function tree_timer_lifecycle(pos) local meta = minetest.get_meta(pos) meta:set_int("ebiometrees:age", meta:get_int("ebiometrees:age")+1) grow_trunk(pos) @@ -81,6 +86,6 @@ function ebiometrees.tree_grower(leaves_name, grow_preferences, terminal_name, n end return true end - return grow_tree + return tree_timer_lifecycle end diff --git a/mods/ebiometrees/tree.lua b/mods/ebiometrees/tree.lua index 4b3375f..14e0ce2 100644 --- a/mods/ebiometrees/tree.lua +++ b/mods/ebiometrees/tree.lua @@ -6,14 +6,24 @@ local function growth_timer(pos) meta:set_int("ebiometrees:age", 0) end -function ebiometrees.register_tree_leaves(modname, basename, data) +local function setup_trunk_closure(treespec) + local function setup_trunk(pos) + minetest.get_node_timer(pos):start(3) + local meta = minetest.get_meta(pos) + meta:mark_as_private("ebiometrees:age") + meta:mark_as_private("ebiometrees:life") + meta:set_int("ebiometrees:age", 0) + end +end + +function ebiometrees.register_tree_leaves(modname, basename, treespec) local S = minetest.get_translator(modname) - local leaves_groups = table.copy(data.groups) + local leaves_groups = table.copy(treespec.groups) leaves_groups.leaves = 1 leaves_groups.leafdecay = 3 leaves_groups.snappy = 3 minetest.register_node(modname..":"..basename.."_leaves", { - description = S(data.description.." leaves"), + description = S(treespec.description.." leaves"), drawtype = "allfaces_optional", waving = 1, tiles = { modname.."_"..basename.."_leaves.png" }, @@ -24,15 +34,15 @@ function ebiometrees.register_tree_leaves(modname, basename, data) }) end -function ebiometrees.register_tree_sapling(modname, basename, data) +function ebiometrees.register_tree_sapling(modname, basename, treespec) -- register saplings local S = minetest.get_translator(modname) - local sapling_groups = table.copy(data.groups) + local sapling_groups = table.copy(treespec.groups) sapling_groups.sapling = 1 sapling_groups.snappy = 2 sapling_groups.dig_immediate = 3 minetest.register_node(modname..":"..basename.."_sapling", { - description = S(data.description.." sapling"), + description = S(treespec.description.." sapling"), drawtype = "plantlike", tiles = { modname.."_"..basename.."_sapling.png"}, paramtype = "light", @@ -46,14 +56,14 @@ function ebiometrees.register_tree_sapling(modname, basename, data) }) end -function ebiometrees.register_tree_sprout(modname, basename, data) +function ebiometrees.register_tree_sprout(modname, basename, treespec) -- register tree leaves local S = minetest.get_translator(modname) - local sprout_groups = table.copy(data.groups) + local sprout_groups = table.copy(treespec.groups) sprout_groups.sapling = 1 sprout_groups.snappy = 2 minetest.register_node(modname..":"..basename.."_sprout", { - description = S(data.description.." sprout"), + description = S(treespec.description.." sprout"), drawtype = "plantlike", visual_scale = 1.4, tiles = { modname.."_"..basename.."_sprout.png" }, @@ -68,10 +78,10 @@ function ebiometrees.register_tree_sprout(modname, basename, data) }) end -function ebiometrees.register_tree_trunks(modname, basename, data) +function ebiometrees.register_tree_trunks(modname, basename, treespec) local S = minetest.get_translator(modname) -- registers corresponding trunk nodes - local trunk_groups = table.copy(data.groups) + local trunk_groups = table.copy(treespec.groups) trunk_groups.choppy = 2 -- TODO: customizations trunk_groups.treetrunk = 1 local trunk_types = {"growing", "normal"} @@ -140,7 +150,7 @@ function ebiometrees.register_tree_trunks(modname, basename, data) for _, trunk_subtype in ipairs(trunk_subtypes) do local nodespec = { - description = S(data.description.." "..trunk_type.." "..trunk_subtype), + description = S(treespec.description.." "..trunk_type.." "..trunk_subtype), groups = trunk_groups, tiles = subtype_tiles[trunk_subtype], paramtype2 = "facedir", @@ -150,22 +160,7 @@ function ebiometrees.register_tree_trunks(modname, basename, data) } if trunk_type == "growing" then - nodespec.on_timer = ebiometrees.tree_grower( - modname..":"..basename.."_leaves", - { - {ebiometrees.directions.up}, - { - ebiometrees.directions.north, - ebiometrees.directions.east, - ebiometrees.directions.south, - ebiometrees.directions.west - } - }, - modname..":"..basename.."_trunk_growing_terminal", - modname..":"..basename.."_trunk_normal_"..trunk_subtype, - 20, - 10 - ) + nodespec.on_timer = ebiometrees.tree_timer_lifecycle_closure(modname..":"..basename) end minetest.register_node( modname..":"..basename.."_trunk_"..trunk_type.."_"..trunk_subtype, diff --git a/mods/electric_biomes/biomes/grasslands.lua b/mods/electric_biomes/biomes/grasslands.lua index c28de5d..09420f7 100644 --- a/mods/electric_biomes/biomes/grasslands.lua +++ b/mods/electric_biomes/biomes/grasslands.lua @@ -12,7 +12,19 @@ minetest.register_biome({ }) ebiometrees.register_tree("electric_biomes:oak",{ description = "Oak", - groups = {flammable = 2} + groups = {flammable = 2}, + life = 30, + growth_preferences = { + {ebiometrees.directions.up}, + { + ebiometrees.directions.north, + ebiometrees.directions.east, + ebiometrees.directions.south, + ebiometrees.directions.west + } + }, + growth_limit = 10, + age_max = 20, }) minetest.register_node("electric_biomes:grass", { description = S("Grass"),