Use node timers for growing saplings; THIS WILL BREAK OLDER WORLDS
This commit is contained in:
parent
5cfe6c8d4a
commit
45ad35e16c
@ -3,11 +3,15 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
-- Chest naming via signs
|
-- Chest naming via signs
|
||||||
|
|
||||||
function default.write_name(pos, text)
|
function default.write_name(pos, text)
|
||||||
-- check above, if allowed
|
-- Check above, if allowed
|
||||||
|
|
||||||
if minetest.settings:get_bool("signs_allow_name_above") then
|
if minetest.settings:get_bool("signs_allow_name_above") then
|
||||||
local above = {x = pos.x, y = pos.y + 1, z = pos.z}
|
local above = {x = pos.x, y = pos.y + 1, z = pos.z}
|
||||||
|
|
||||||
local abovedef = nil
|
local abovedef = nil
|
||||||
|
|
||||||
if minetest.registered_nodes[minetest.get_node(above).name] then
|
if minetest.registered_nodes[minetest.get_node(above).name] then
|
||||||
abovedef = minetest.registered_nodes[minetest.get_node(above).name]
|
abovedef = minetest.registered_nodes[minetest.get_node(above).name]
|
||||||
end
|
end
|
||||||
@ -16,20 +20,40 @@ function default.write_name(pos, text)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- then below
|
-- Then below
|
||||||
|
|
||||||
local below = {x = pos.x, y = pos.y - 1, z = pos.z}
|
local below = {x = pos.x, y = pos.y - 1, z = pos.z}
|
||||||
|
|
||||||
local belowdef = nil
|
local belowdef = nil
|
||||||
|
|
||||||
if minetest.registered_nodes[minetest.get_node(below).name] then
|
if minetest.registered_nodes[minetest.get_node(below).name] then
|
||||||
belowdef = minetest.registered_nodes[minetest.get_node(below).name]
|
belowdef = minetest.registered_nodes[minetest.get_node(below).name]
|
||||||
end
|
end
|
||||||
|
|
||||||
if belowdef and belowdef.write_name ~= nil then
|
if belowdef and belowdef.write_name ~= nil then
|
||||||
belowdef.write_name(below, text)
|
belowdef.write_name(below, text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Saplings growing
|
-- Saplings growing and placing
|
||||||
|
|
||||||
function default.grow_tree(pos, variety)
|
function default.place_sapling(itemstack, placer, pointed_thing)
|
||||||
|
-- Check growability
|
||||||
|
|
||||||
|
print(itemstack:get_name())
|
||||||
|
|
||||||
|
local underdef = minetest.get_node(pointed_thing.under)
|
||||||
|
|
||||||
|
if minetest.get_item_group(underdef.name, "soil") == 0 then
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.set_node(pointed_thing.above, {name = itemstack:get_name()})
|
||||||
|
|
||||||
|
return itemstack:take_item()
|
||||||
|
end
|
||||||
|
|
||||||
|
function default.grow_sapling(pos, variety)
|
||||||
local function grow()
|
local function grow()
|
||||||
if variety == "apple" then
|
if variety == "apple" then
|
||||||
minetest.place_schematic(
|
minetest.place_schematic(
|
||||||
@ -78,57 +102,6 @@ function default.grow_tree(pos, variety)
|
|||||||
default.log(variety.." tree sapling grows at "..minetest.pos_to_string(pos), "info")
|
default.log(variety.." tree sapling grows at "..minetest.pos_to_string(pos), "info")
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_abm( -- apple trees or default trees
|
|
||||||
{
|
|
||||||
label = "Grow apple saplings",
|
|
||||||
nodenames = {"default:sapling"},
|
|
||||||
interval = 10,
|
|
||||||
chance = 40,
|
|
||||||
action = function(pos, node)
|
|
||||||
local is_soil = minetest.registered_nodes[minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name].groups.soil
|
|
||||||
|
|
||||||
if is_soil == nil or is_soil == 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
default.grow_tree(pos, "apple")
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_abm( -- oak trees
|
|
||||||
{
|
|
||||||
label = "Grow oak saplings",
|
|
||||||
nodenames = {"default:sapling_oak"},
|
|
||||||
interval = 10,
|
|
||||||
chance = 60,
|
|
||||||
action = function(pos, node)
|
|
||||||
local is_soil = minetest.registered_nodes[minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name].groups.soil
|
|
||||||
|
|
||||||
if is_soil == nil or is_soil == 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
default.grow_tree(pos, "oak")
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_abm( -- birch trees
|
|
||||||
{
|
|
||||||
label = "Grow birch saplings",
|
|
||||||
nodenames = {"default:sapling_birch"},
|
|
||||||
interval = 10,
|
|
||||||
chance = 50,
|
|
||||||
action = function(pos, node)
|
|
||||||
local is_soil = minetest.registered_nodes[minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name].groups.soil
|
|
||||||
|
|
||||||
if is_soil == nil or is_soil == 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
default.grow_tree(pos, "birch")
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Vertical plants
|
-- Vertical plants
|
||||||
|
|
||||||
function default.dig_up(pos, node, digger)
|
function default.dig_up(pos, node, digger)
|
||||||
|
@ -442,6 +442,16 @@ minetest.register_node(
|
|||||||
groups = {snappy = 2, dig_immediate = 2, attached_node = 1, sapling = 1},
|
groups = {snappy = 2, dig_immediate = 2, attached_node = 1, sapling = 1},
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
sounds = default.node_sound_defaults(),
|
sounds = default.node_sound_defaults(),
|
||||||
|
|
||||||
|
on_timer = function(pos)
|
||||||
|
default.grow_sapling(pos, "apple")
|
||||||
|
end,
|
||||||
|
|
||||||
|
on_construct = function(pos)
|
||||||
|
minetest.get_node_timer(pos):start(math.random(300, 480))
|
||||||
|
end,
|
||||||
|
|
||||||
|
on_place = default.place_sapling,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node(
|
minetest.register_node(
|
||||||
@ -461,6 +471,16 @@ minetest.register_node(
|
|||||||
},
|
},
|
||||||
groups = {snappy = 2, dig_immediate = 2, attached_node = 1, sapling = 1},
|
groups = {snappy = 2, dig_immediate = 2, attached_node = 1, sapling = 1},
|
||||||
sounds = default.node_sound_defaults(),
|
sounds = default.node_sound_defaults(),
|
||||||
|
|
||||||
|
on_timer = function(pos)
|
||||||
|
default.grow_sapling(pos, "oak")
|
||||||
|
end,
|
||||||
|
|
||||||
|
on_construct = function(pos)
|
||||||
|
minetest.get_node_timer(pos):start(math.random(700, 960))
|
||||||
|
end,
|
||||||
|
|
||||||
|
on_place = default.place_sapling,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node(
|
minetest.register_node(
|
||||||
@ -481,6 +501,16 @@ minetest.register_node(
|
|||||||
groups = {snappy = 2, dig_immediate = 2, attached_node = 1, sapling = 1},
|
groups = {snappy = 2, dig_immediate = 2, attached_node = 1, sapling = 1},
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
sounds = default.node_sound_defaults(),
|
sounds = default.node_sound_defaults(),
|
||||||
|
|
||||||
|
on_timer = function(pos)
|
||||||
|
default.grow_sapling(pos, "birch")
|
||||||
|
end,
|
||||||
|
|
||||||
|
on_construct = function(pos)
|
||||||
|
minetest.get_node_timer(pos):start(math.random(480, 780))
|
||||||
|
end,
|
||||||
|
|
||||||
|
on_place = default.place_sapling,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Trees
|
-- Trees
|
||||||
|
Loading…
Reference in New Issue
Block a user