regrowing_fruits/init.lua

145 lines
4.4 KiB
Lua
Raw Normal View History

2020-04-20 16:57:44 +00:00
local regrowing_bananas = minetest.settings:get_bool("regrowing_bananas", true)
local regrowing_coconuts = minetest.settings:get_bool("regrowing_coconuts", true)
local regrowing_goldapples = minetest.settings:get_bool("regrowing_goldapples", true)
local regrowing_oranges = minetest.settings:get_bool("regrowing_oranges", true)
-- override ethereal fruits
if regrowing_bananas then
minetest.override_item("ethereal:banana", {
after_dig_node = function(pos, oldnode, oldmetadata, digger)
if oldnode.param2 == 0 then
minetest.set_node(pos, {name = "regrowing_fruits:banana_mark"})
minetest.get_node_timer(pos):start(math.random(300, 1500))
end
end,
})
end
if regrowing_coconuts then
minetest.override_item("ethereal:coconut", {
after_dig_node = function(pos, oldnode, oldmetadata, digger)
if oldnode.param2 == 0 then
minetest.set_node(pos, {name = "regrowing_fruits:coconut_mark"})
minetest.get_node_timer(pos):start(math.random(300, 1500))
end
end,
})
end
if regrowing_goldapples then
minetest.override_item("ethereal:golden_apple", {
after_dig_node = function(pos, oldnode, oldmetadata, digger)
if oldnode.param2 == 0 then
minetest.set_node(pos, {name = "regrowing_fruits:goldapple_mark"})
minetest.get_node_timer(pos):start(math.random(300, 1500))
end
end,
})
end
if regrowing_oranges then
minetest.override_item("ethereal:orange", {
after_dig_node = function(pos, oldnode, oldmetadata, digger)
if oldnode.param2 == 0 then
minetest.set_node(pos, {name = "regrowing_fruits:orange_mark"})
minetest.get_node_timer(pos):start(math.random(300, 1500))
end
end,
})
end
-- air nodes to mark fruit pos
minetest.register_node("regrowing_fruits:banana_mark", {
description = "Air!",
drawtype = "airlike",
paramtype = "light",
sunlight_propagates = true,
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
drop = "",
groups = {not_in_creative_inventory = 1},
on_timer = function(pos, elapsed)
if not minetest.find_node_near(pos, 1, "ethereal:bananaleaves")
or not regrowing_bananas then
minetest.remove_node(pos)
elseif minetest.get_node_light(pos) < 13 then
minetest.get_node_timer(pos):start(200)
else
minetest.set_node(pos, {name = "ethereal:banana"})
end
end
})
minetest.register_node("regrowing_fruits:coconut_mark", {
description = "Air!",
drawtype = "airlike",
paramtype = "light",
sunlight_propagates = true,
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
drop = "",
groups = {not_in_creative_inventory = 1},
on_timer = function(pos, elapsed)
if not minetest.find_node_near(pos, 1, "ethereal:palmleaves")
or not regrowing_coconuts then
minetest.remove_node(pos)
elseif minetest.get_node_light(pos) < 13 then
minetest.get_node_timer(pos):start(200)
else
minetest.set_node(pos, {name = "ethereal:coconut"})
end
end
})
minetest.register_node("regrowing_fruits:goldapple_mark", {
description = "Air!",
drawtype = "airlike",
paramtype = "light",
sunlight_propagates = true,
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
drop = "",
groups = {not_in_creative_inventory = 1},
on_timer = function(pos, elapsed)
if not minetest.find_node_near(pos, 1, "ethereal:yellowleaves")
or not regrowing_goldapples then
minetest.remove_node(pos)
elseif not regrowing_goldapples then
return
elseif minetest.get_node_light(pos) < 13 then
minetest.get_node_timer(pos):start(200)
else
minetest.set_node(pos, {name = "ethereal:golden_apple"})
end
end
})
minetest.register_node("regrowing_fruits:orange_mark", {
description = "Air!",
drawtype = "airlike",
paramtype = "light",
sunlight_propagates = true,
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
drop = "",
groups = {not_in_creative_inventory = 1},
on_timer = function(pos, elapsed)
if not minetest.find_node_near(pos, 1, "ethereal:orange_leaves")
or not regrowing_oranges then
minetest.remove_node(pos)
elseif minetest.get_node_light(pos) < 13 then
minetest.get_node_timer(pos):start(200)
else
minetest.set_node(pos, {name = "ethereal:orange"})
end
end
})