Refactor a bit to be more concise
This commit is contained in:
parent
b2a291fc4a
commit
78cd12d2eb
|
@ -1,6 +1,10 @@
|
||||||
unused_args = false
|
unused_args = false
|
||||||
allow_defined_top = true
|
allow_defined_top = true
|
||||||
|
|
||||||
|
globals = {
|
||||||
|
"default"
|
||||||
|
}
|
||||||
|
|
||||||
read_globals = {
|
read_globals = {
|
||||||
"DIR_DELIM",
|
"DIR_DELIM",
|
||||||
"minetest",
|
"minetest",
|
||||||
|
|
|
@ -1041,9 +1041,7 @@ Trees
|
||||||
{
|
{
|
||||||
can_grow = default.can_grow, -- Function called to determine whether the sapling can grow, should return a boolean
|
can_grow = default.can_grow, -- Function called to determine whether the sapling can grow, should return a boolean
|
||||||
on_grow_failed = default.on_grow_failed, -- Function called when the growth fails
|
on_grow_failed = default.on_grow_failed, -- Function called when the growth fails
|
||||||
grow_callback = function(pos) -- Function called when the growth has success. Conventionally, this should replace the sapling with a tree
|
grow = function(pos) -- Function called when the growth has success. This should replace the sapling with a tree.
|
||||||
default.grow_tree(pos, random(1, 4) == 1)
|
|
||||||
end
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
* default.grow_sapling(pos)
|
* default.grow_sapling(pos)
|
||||||
|
|
|
@ -535,7 +535,11 @@ end
|
||||||
default.sapling_growth_defs = {}
|
default.sapling_growth_defs = {}
|
||||||
|
|
||||||
function default.register_sapling_growth(name, def)
|
function default.register_sapling_growth(name, def)
|
||||||
default.sapling_growth_defs[name] = def
|
default.sapling_growth_defs[name] = {
|
||||||
|
can_grow = def.can_grow or default.can_grow,
|
||||||
|
on_grow_failed = def.on_grow_failed or default.on_grow_failed,
|
||||||
|
grow = assert(def.grow)
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
function default.grow_sapling(pos)
|
function default.grow_sapling(pos)
|
||||||
|
@ -553,115 +557,44 @@ function default.grow_sapling(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.log("action", "Growing sapling " .. node.name .. " at " .. minetest.pos_to_string(pos))
|
minetest.log("action", "Growing sapling " .. node.name .. " at " .. minetest.pos_to_string(pos))
|
||||||
local grow_callback = sapling_def.grow_callback
|
sapling_def.grow(pos)
|
||||||
if not grow_callback then
|
end
|
||||||
minetest.log("warning", "Unknown grow callback for sapling " .. node.name)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
sapling_def.grow_callback(pos)
|
local function register_sapling_growth(nodename, grow)
|
||||||
|
default.register_sapling_growth("default:" .. nodename, {grow = grow})
|
||||||
end
|
end
|
||||||
|
|
||||||
if minetest.get_mapgen_setting("mg_name") == "v6" then
|
if minetest.get_mapgen_setting("mg_name") == "v6" then
|
||||||
-- Tree sapling
|
register_sapling_growth("sapling", function(pos)
|
||||||
default.register_sapling_growth("default:sapling", {
|
default.grow_tree(pos, random(1, 4) == 1)
|
||||||
can_grow = default.can_grow,
|
end)
|
||||||
on_grow_failed = default.on_grow_failed,
|
register_sapling_growth("junglesapling", default.grow_jungle_tree)
|
||||||
grow_callback = function(pos)
|
register_sapling_growth("pine_sapling", function(pos)
|
||||||
default.grow_tree(pos, random(1, 4) == 1)
|
local snow = is_snow_nearby(pos)
|
||||||
end
|
default.grow_pine_tree(pos, snow)
|
||||||
})
|
end)
|
||||||
|
|
||||||
-- Jungle tree sapling
|
|
||||||
default.register_sapling_growth("default:junglesapling", {
|
|
||||||
can_grow = default.can_grow,
|
|
||||||
on_grow_failed = default.on_grow_failed,
|
|
||||||
grow_callback = default.grow_jungle_tree
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Pine sapling
|
|
||||||
default.register_sapling_growth("default:pine_sapling", {
|
|
||||||
can_grow = default.can_grow,
|
|
||||||
on_grow_failed = default.on_grow_failed,
|
|
||||||
grow_callback = function(pos)
|
|
||||||
local snow = is_snow_nearby(pos)
|
|
||||||
default.grow_pine_tree(pos, snow)
|
|
||||||
end
|
|
||||||
})
|
|
||||||
else
|
else
|
||||||
-- Tree sapling
|
register_sapling_growth("sapling", default.grow_new_apple_tree)
|
||||||
default.register_sapling_growth("default:sapling", {
|
register_sapling_growth("junglesapling", default.grow_new_jungle_tree)
|
||||||
can_grow = default.can_grow,
|
register_sapling_growth("pine_sapling", function(pos)
|
||||||
on_grow_failed = default.on_grow_failed,
|
local snow = is_snow_nearby(pos)
|
||||||
grow_callback = function(pos)
|
if snow then
|
||||||
default.grow_new_apple_tree(pos)
|
default.grow_new_snowy_pine_tree(pos)
|
||||||
|
else
|
||||||
|
default.grow_new_pine_tree(pos)
|
||||||
end
|
end
|
||||||
})
|
end)
|
||||||
|
|
||||||
-- Jungle tree sapling
|
|
||||||
default.register_sapling_growth("default:junglesapling", {
|
|
||||||
can_grow = default.can_grow,
|
|
||||||
on_grow_failed = default.on_grow_failed,
|
|
||||||
grow_callback = default.grow_new_jungle_tree
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Pine sapling
|
|
||||||
default.register_sapling_growth("default:pine_sapling", {
|
|
||||||
can_grow = default.can_grow,
|
|
||||||
on_grow_failed = default.on_grow_failed,
|
|
||||||
grow_callback = function(pos)
|
|
||||||
local snow = is_snow_nearby(pos)
|
|
||||||
if snow then
|
|
||||||
default.grow_new_snowy_pine_tree(pos)
|
|
||||||
else
|
|
||||||
default.grow_new_pine_tree(pos)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
default.register_sapling_growth("default:acacia_sapling", {
|
register_sapling_growth("acacia_sapling", default.grow_new_acacia_tree)
|
||||||
can_grow = default.can_grow,
|
register_sapling_growth("aspen_sapling", default.grow_new_aspen_tree)
|
||||||
on_grow_failed = default.on_grow_failed,
|
register_sapling_growth("bush_sapling", default.grow_bush)
|
||||||
grow_callback = default.grow_new_acacia_tree
|
register_sapling_growth("blueberry_bush_sapling", default.grow_blueberry_bush)
|
||||||
})
|
register_sapling_growth("acacia_bush_sapling", default.grow_acacia_bush)
|
||||||
|
register_sapling_growth("pine_bush_sapling", default.grow_pine_bush)
|
||||||
default.register_sapling_growth("default:aspen_sapling", {
|
register_sapling_growth("emergent_jungle_sapling", default.grow_new_emergent_jungle_tree)
|
||||||
can_grow = default.can_grow,
|
|
||||||
on_grow_failed = default.on_grow_failed,
|
|
||||||
grow_callback = default.grow_new_aspen_tree
|
|
||||||
})
|
|
||||||
|
|
||||||
default.register_sapling_growth("default:bush_sapling", {
|
|
||||||
can_grow = default.can_grow,
|
|
||||||
on_grow_failed = default.on_grow_failed,
|
|
||||||
grow_callback = default.grow_bush
|
|
||||||
})
|
|
||||||
|
|
||||||
default.register_sapling_growth("default:blueberry_bush_sapling", {
|
|
||||||
can_grow = default.can_grow,
|
|
||||||
on_grow_failed = default.on_grow_failed,
|
|
||||||
grow_callback = default.grow_blueberry_bush
|
|
||||||
})
|
|
||||||
|
|
||||||
default.register_sapling_growth("default:acacia_bush_sapling", {
|
|
||||||
can_grow = default.can_grow,
|
|
||||||
on_grow_failed = default.on_grow_failed,
|
|
||||||
grow_callback = default.grow_acacia_bush
|
|
||||||
})
|
|
||||||
|
|
||||||
default.register_sapling_growth("default:pine_bush_sapling", {
|
|
||||||
can_grow = default.can_grow,
|
|
||||||
on_grow_failed = default.on_grow_failed,
|
|
||||||
grow_callback = default.grow_pine_bush
|
|
||||||
})
|
|
||||||
|
|
||||||
default.register_sapling_growth("default:emergent_jungle_sapling", {
|
|
||||||
can_grow = default.can_grow,
|
|
||||||
on_grow_failed = default.on_grow_failed,
|
|
||||||
grow_callback = default.grow_new_emergent_jungle_tree
|
|
||||||
})
|
|
||||||
|
|
||||||
|
-- TODO: Is it correct for this to omit some saplings?
|
||||||
minetest.register_lbm({
|
minetest.register_lbm({
|
||||||
name = "default:convert_saplings_to_node_timer",
|
name = "default:convert_saplings_to_node_timer",
|
||||||
nodenames = {"default:sapling", "default:junglesapling",
|
nodenames = {"default:sapling", "default:junglesapling",
|
||||||
|
|
Loading…
Reference in New Issue