From 3d709dfa1d3aee61e0325895ff077f7074c676f6 Mon Sep 17 00:00:00 2001 From: Ezhh Date: Fri, 11 May 2018 16:42:28 +0100 Subject: [PATCH] Enable regrowth of apples Apples only regrow where they first appear on trees, either on mapgen or when grown from saplings (meaning apples that were placed by players won't regrow). Once the tree is cut down in full (leaves removed), regrowth will stop. New apples only grow in daylight, and take the same time as a sapling to grow. --- mods/default/nodes.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/mods/default/nodes.lua b/mods/default/nodes.lua index 7d65f300..c07cc6ef 100644 --- a/mods/default/nodes.lua +++ b/mods/default/nodes.lua @@ -737,6 +737,35 @@ minetest.register_node("default:apple", { after_place_node = function(pos, placer, itemstack) minetest.set_node(pos, {name = "default:apple", param2 = 1}) end, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + if oldnode.param2 == 0 then + minetest.set_node(pos, {name = "default:apple_mark"}) + minetest.get_node_timer(pos):start(math.random(300, 1500)) + end + end, +}) + +minetest.register_node("default:apple_mark", { + description = "Apple Marker", + 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, "default:leaves") then + minetest.remove_node(pos) + elseif minetest.get_node_light(pos) < 11 then + minetest.get_node_timer(pos):start(200) + else + minetest.set_node(pos, {name = "default:apple"}) + end + end }) -- 2.25.1