mirror of
https://github.com/minetest/minetest_game.git
synced 2024-11-15 06:20:19 +01:00
feat: generic sapling grow APIs and porting for default apple tree
This commit is contained in:
parent
9e77e00c65
commit
e6b2500124
|
@ -26,6 +26,10 @@ function default.can_grow(pos)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function default.on_grow_failed(pos)
|
||||||
|
minetest.get_node_timer(pos):start(300)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- 'is snow nearby' function
|
-- 'is snow nearby' function
|
||||||
|
|
||||||
|
@ -36,24 +40,32 @@ end
|
||||||
|
|
||||||
-- Grow sapling
|
-- Grow sapling
|
||||||
|
|
||||||
|
default.sapling_defs = {}
|
||||||
|
|
||||||
|
function default.register_sapling(name, def)
|
||||||
|
default.sapling_defs[name] = def
|
||||||
|
end
|
||||||
|
|
||||||
function default.grow_sapling(pos)
|
function default.grow_sapling(pos)
|
||||||
if not default.can_grow(pos) then
|
local mg_name = minetest.get_mapgen_setting("mg_name")
|
||||||
-- try again 5 min later
|
local node = minetest.get_node(pos)
|
||||||
minetest.get_node_timer(pos):start(300)
|
local sapling_def = default.sapling_defs[node.name]
|
||||||
|
|
||||||
|
if not sapling_def then
|
||||||
|
minetest.log("warning", "default.grow_sapling called on undefined sapling .. " .. node.name)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local mg_name = minetest.get_mapgen_setting("mg_name")
|
if not sapling_def.can_grow(pos) then
|
||||||
local node = minetest.get_node(pos)
|
sapling_def.on_grow_failed(pos)
|
||||||
if node.name == "default:sapling" then
|
return
|
||||||
minetest.log("action", "A sapling grows into a tree at "..
|
end
|
||||||
minetest.pos_to_string(pos))
|
|
||||||
if mg_name == "v6" then
|
minetest.log("action", "Calling grow callback for " ..
|
||||||
default.grow_tree(pos, random(1, 4) == 1)
|
node.name .. " at " .. minetest.pos_to_string(pos))
|
||||||
else
|
sapling_def.grow_callback(pos)
|
||||||
default.grow_new_apple_tree(pos)
|
|
||||||
end
|
if node.name == "default:junglesapling" then
|
||||||
elseif node.name == "default:junglesapling" then
|
|
||||||
minetest.log("action", "A jungle sapling grows into a tree at "..
|
minetest.log("action", "A jungle sapling grows into a tree at "..
|
||||||
minetest.pos_to_string(pos))
|
minetest.pos_to_string(pos))
|
||||||
if mg_name == "v6" then
|
if mg_name == "v6" then
|
||||||
|
@ -103,6 +115,25 @@ function default.grow_sapling(pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if minetest.get_mapgen_setting("mg_name") == "v6" then
|
||||||
|
-- Tree sapling
|
||||||
|
default.register_sapling("default:sapling", {
|
||||||
|
can_grow = default.can_grow,
|
||||||
|
on_grow_failed = default.on_grow_failed,
|
||||||
|
grow_callback = function(pos)
|
||||||
|
default.grow_tree(pos, random(1, 4) == 1)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
else
|
||||||
|
default.register_sapling("default:sapling", {
|
||||||
|
can_grow = default.can_grow,
|
||||||
|
on_grow_failed = default.on_grow_failed,
|
||||||
|
grow_callback = function(pos)
|
||||||
|
default.grow_new_apple_tree(pos)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
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
Block a user