From 2e9a878a7f6006e860b1a4f1bb45e50c444e0834 Mon Sep 17 00:00:00 2001 From: philipmi Date: Sat, 27 Jun 2020 21:03:25 +0200 Subject: [PATCH] complete revision --- README.md | 10 +-- depends.txt | 3 +- init.lua | 182 +++++++++++------------------------------------ license.txt | 2 +- mod.conf | 4 +- settingtypes.txt | 8 +-- 6 files changed, 54 insertions(+), 155 deletions(-) diff --git a/README.md b/README.md index 5f879f3..358d6c4 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,19 @@ -Regrowing Fruits for Ethereal Mod +Regrowing Fruits === Info ---- -This mod causes fruits on ethereal trees to regrow like apples in the 0.5 release of Minetest Game. If you placed the fruits by hand or removed the tree leaves, the fruits don't regrow. +This mod causes fruits on trees from other mods to regrow like apples in the 5.0 release of Minetest Game. If you placed the fruits by hand or removed the tree leaves, the fruits don't regrow. -In Minetest Settings you can disable the different types of regrowing fruits. Regrowing golden apples are disabled in default settings to keep them special fruits. Bananas, coconuts and oranges are all enabled. +In the moment only ethereal mod is supported, but I'm sure there are other mods with this problem I do not use. Please tell me on Minetest Forum page! + +There is also the possibility to enable regrowing apples in Minetest Settings. Notice that this is only necessary for older versions than MT 5.0. Credits ---- -This mod is based on "endless_apples" by Shara RedCat (2018). +This mod is inspired on "endless_apples" by Shara RedCat (2018). License ---- diff --git a/depends.txt b/depends.txt index 205d2d3..331d858 100644 --- a/depends.txt +++ b/depends.txt @@ -1,2 +1 @@ -default -ethereal +default \ No newline at end of file diff --git a/init.lua b/init.lua index 46e4900..84cb411 100644 --- a/init.lua +++ b/init.lua @@ -1,144 +1,48 @@ -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) +local regrowing_apples = minetest.settings:get_bool("regrowing_apples", 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, - }) +local add_fruit_regrowable = function(fruit, node, leaves) + + -- override fruit + minetest.override_item(node, { + after_dig_node = function(pos, oldnode, oldmetadata, digger) + if oldnode.param2 == 0 then + minetest.set_node(pos, {name = "regrowing_fruits:"..fruit.."_mark"}) + minetest.get_node_timer(pos):start(math.random(300, 1500)) + end + end, + }) + + -- air node to mark fruit pos + minetest.register_node("regrowing_fruits:"..fruit.."_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, leaves) 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 = node}) + 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, - }) +if regrowing_apples then + add_fruit_regrowable("apple", "default:apple", "default:leaves") 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 -}) +if minetest.get_modpath("ethereal") then + add_fruit_regrowable("banana","ethereal:banana", "ethereal:bananaleaves") + add_fruit_regrowable("coconut", "ethereal:coconut", "ethereal:palmleaves") + add_fruit_regrowable("goldapple", "ethereal:golden_apple", "ethereal:yellowleaves") + add_fruit_regrowable("orange", "ethereal:orange", "ethereal:orange_leaves") +end \ No newline at end of file diff --git a/license.txt b/license.txt index 612ea2b..2c38778 100644 --- a/license.txt +++ b/license.txt @@ -1,7 +1,7 @@ The MIT License (MIT) -Copyright (c) 2020 philipmi, 2018 Shara RedCat +Copyright (c) 2020 philipmi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/mod.conf b/mod.conf index 28174ca..9fb6774 100644 --- a/mod.conf +++ b/mod.conf @@ -1,4 +1,4 @@ name = regrowing_fruits author = philipmi -description = Fruits on ethereal trees will regrow. -title = Regrowing Fruits for Ethereal Mod +description = Fruits on trees from other mods will regrow. +title = Regrowing Fruits diff --git a/settingtypes.txt b/settingtypes.txt index ad79562..a9a916b 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -1,7 +1 @@ -regrowing_bananas (Enable regrowing bananas) bool true - -regrowing_coconuts (Enable regrowing coconuts) bool true - -regrowing_goldapples (Enable regrowing golden apples) bool false - -regrowing_oranges (Enable regrowing oranges) bool true +regrowing_apples (Regrowing apples(unnecessary for MT 5.x)) bool false \ No newline at end of file