added the ability to redefine apples so that they'll fall when nearby leaves
authorVanessa Ezekowitz <vanessaezekowitz@gmail.com>
Mon, 11 Feb 2013 17:23:05 +0000 (12:23 -0500)
committerVanessa Ezekowitz <vanessaezekowitz@gmail.com>
Mon, 11 Feb 2013 17:23:05 +0000 (12:23 -0500)
disappear (defaults to true).  Moved leafdecay code into its own file.  Moved
sapling configs into settings.lua

init.lua
leafdecay.lua [new file with mode: 0644]
node_defs.lua
settings.lua

index 9c63d7a87313b88dba6d0f3a38b885d70ca19d30..936c1d0c91dbf40279d752274dd3358ba73c7e72 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -36,6 +36,7 @@ dofile(minetest.get_modpath("moretrees").."/node_defs.lua")
 dofile(minetest.get_modpath("moretrees").."/tree_models.lua")
 dofile(minetest.get_modpath("moretrees").."/biome_defs.lua")
 dofile(minetest.get_modpath("moretrees").."/crafts.lua")
+dofile(minetest.get_modpath("moretrees").."/leafdecay.lua")
 
 -- tree spawning setup
 
@@ -54,9 +55,6 @@ plantslib:register_generate_plant(moretrees.fir_biome, "moretrees:grow_fir")
 
 -- sapling growth
 
-local sapling_interval = 500
-local sapling_chance = 20
-
 for i in ipairs(moretrees.simple_trees) do
        local tree_name = trees[i][1]
        local tree_model = tree_name.."_model"
@@ -65,8 +63,8 @@ for i in ipairs(moretrees.simple_trees) do
        plantslib:dbg(dump(moretrees[tree_biome].surface))
        
        plantslib:grow_plants({
-               grow_delay = sapling_interval,
-               grow_chance = sapling_chance,
+               grow_delay = moretrees.sapling_interval,
+               grow_chance = moretrees.sapling_chance,
                grow_plant = "moretrees:"..tree_name.."_sapling",
                grow_nodes = moretrees[tree_biome].surface,
                grow_function = moretrees[tree_model],
@@ -74,32 +72,32 @@ for i in ipairs(moretrees.simple_trees) do
 end
 
 plantslib:grow_plants({
-       grow_delay = sapling_interval,
-       grow_chance = sapling_chance,
+       grow_delay = moretrees.sapling_interval,
+       grow_chance = moretrees.sapling_chance,
        grow_plant = "moretrees:birch_sapling",
        grow_nodes = moretrees.birch_biome.surface,
        grow_function = "moretrees:grow_birch"
 })
 
 plantslib:grow_plants({
-       grow_delay = sapling_interval,
-       grow_chance = sapling_chance,
+       grow_delay = moretrees.sapling_interval,
+       grow_chance = moretrees.sapling_chance,
        grow_plant = "moretrees:spruce_sapling",
        grow_nodes = moretrees.spruce_biome.surface,
        grow_function = "moretrees:grow_spruce"
 })
 
 plantslib:grow_plants({
-       grow_delay = sapling_interval,
-       grow_chance = sapling_chance,
+       grow_delay = moretrees.sapling_interval,
+       grow_chance = moretrees.sapling_chance,
        grow_plant = "moretrees:fir_sapling",
        grow_nodes = moretrees.fir_biome.surface,
        grow_function = "moretrees:grow_fir"
 })
 
 plantslib:grow_plants({
-       grow_delay = sapling_interval,
-       grow_chance = sapling_chance,
+       grow_delay = moretrees.sapling_interval,
+       grow_chance = moretrees.sapling_chance,
        grow_plant = "moretrees:jungletree_sapling",
        grow_nodes = moretrees.jungletree_biome.surface,
        grow_function = "moretrees:grow_jungletree"
@@ -226,49 +224,4 @@ if moretrees.firs_remove_default_trees == true then
        })
 end
 
--- leaf decay
-
-minetest.register_abm({
-       nodenames = moretrees.leaves_list,
-       interval = moretrees.leafdecay_delay,
-       chance = moretrees.leafdecay_chance,
-       action = function(pos, node, active_object_count, active_object_count_wider)
-               if not minetest.env:find_node_near(pos, moretrees.leafdecay_radius, moretrees.trunks_list) then
-                       minetest.env:remove_node(pos)
-                       minetest.env:dig_node(pos)
-               end
-       end
-})
-
-minetest.register_abm({
-       nodenames = "moretrees:palm_leaves",
-       interval = moretrees.leafdecay_delay,
-       chance = moretrees.leafdecay_chance,
-       action = function(pos, node, active_object_count, active_object_count_wider)
-               if not minetest.env:find_node_near(pos, moretrees.palm_leafdecay_radius, moretrees.trunks_list) then
-                       minetest.env:remove_node(pos)
-                       minetest.env:dig_node(pos)
-               end
-       end
-})
-
-
-if moretrees.enable_replace_default_trees then
-       minetest.register_alias("mapgen_tree", "air")
-       minetest.register_alias("mapgen_leaves", "air")
-       plantslib:register_generate_plant(moretrees.beech_biome, moretrees.beech_model)
-elseif moretrees.enable_default_leafdecay then
-       minetest.register_abm({
-               nodenames = "default:leaves",
-               interval = moretrees.default_leafdecay_delay,
-               chance = moretrees.default_leafdecay_chance,
-               action = function(pos, node, active_object_count, active_object_count_wider)
-                       if not minetest.env:find_node_near(pos, moretrees.default_leafdecay_radius, {"default:tree"}) then
-                               minetest.env:remove_node(pos)
-                               minetest.env:dig_node(pos)
-                       end
-               end
-       })      
-end
-
 print("[Moretrees] Loaded (2013-01-18)")
diff --git a/leafdecay.lua b/leafdecay.lua
new file mode 100644 (file)
index 0000000..cab0281
--- /dev/null
@@ -0,0 +1,44 @@
+-- leaf decay
+
+minetest.register_abm({
+       nodenames = moretrees.leaves_list,
+       interval = moretrees.leafdecay_delay,
+       chance = moretrees.leafdecay_chance,
+       action = function(pos, node, active_object_count, active_object_count_wider)
+               if not minetest.env:find_node_near(pos, moretrees.leafdecay_radius, moretrees.trunks_list) then
+                       minetest.env:remove_node(pos)
+                       minetest.env:dig_node(pos)
+               end
+       end
+})
+
+minetest.register_abm({
+       nodenames = "moretrees:palm_leaves",
+       interval = moretrees.leafdecay_delay,
+       chance = moretrees.leafdecay_chance,
+       action = function(pos, node, active_object_count, active_object_count_wider)
+               if not minetest.env:find_node_near(pos, moretrees.palm_leafdecay_radius, moretrees.trunks_list) then
+                       minetest.env:remove_node(pos)
+                       minetest.env:dig_node(pos)
+               end
+       end
+})
+
+
+if moretrees.enable_replace_default_trees then
+       minetest.register_alias("mapgen_tree", "air")
+       minetest.register_alias("mapgen_leaves", "air")
+       plantslib:register_generate_plant(moretrees.beech_biome, moretrees.beech_model)
+elseif moretrees.enable_default_leafdecay then
+       minetest.register_abm({
+               nodenames = "default:leaves",
+               interval = moretrees.default_leafdecay_delay,
+               chance = moretrees.default_leafdecay_chance,
+               action = function(pos, node, active_object_count, active_object_count_wider)
+                       if not minetest.env:find_node_near(pos, moretrees.default_leafdecay_radius, {"default:tree"}) then
+                               minetest.env:remove_node(pos)
+                               minetest.env:dig_node(pos)
+                       end
+               end
+       })      
+end
index e8f0ba98206a1285ede0e72a1898a14dae134e7d..858f5aff653ced1bff7efcd932a4e2b6344ecd08 100644 (file)
@@ -186,6 +186,27 @@ minetest.register_node("moretrees:fir_leaves_bright", {
 })
 table.insert(moretrees.leaves_list, "moretrees:fir_leaves_bright")
 
+if moretrees.enable_redefine_apple then
+       minetest.register_node(":default:apple", {
+               description = "Apple",
+               drawtype = "plantlike",
+               visual_scale = 1.0,
+               tiles = {"default_apple.png"},
+               inventory_image = "default_apple.png",
+               paramtype = "light",
+               sunlight_propagates = true,
+               walkable = false,
+               selection_box = {
+                       type = "fixed",
+                       fixed = {-0.2, -0.5, -0.2, 0.2, 0, 0.2}
+               },
+               groups = {fleshy=3,dig_immediate=3,flammable=2,attached_node=1},
+               on_use = minetest.item_eat(4),
+               sounds = default.node_sound_defaults(),
+       })
+end
+
+
 
 -- Backward compatbility with old mods/nodes:
 
index 0da6be3cea643b680260db16930bc762f6a1b15b..f9974ef70353f451023e11ac75aee87f475adce5 100644 (file)
@@ -12,6 +12,11 @@ moretrees.enable_replace_default_trees = false
 
 moretrees.enable_default_leafdecay = false
 
+-- Enable this if you want moretrees to redefine default apples so that they
+-- fall when leaves decay/are dug.
+
+moretrees.enable_redefine_apple = true
+
 -- various settings to configure leaf decay in general.
 
 moretrees.leafdecay_delay = 2
@@ -31,3 +36,7 @@ moretrees.firs_remove_default_trees = false
 moretrees.firs_remove_interval = 2
 moretrees.firs_remove_chance = 150
 
+-- Sapling settings
+
+moretrees.sapling_interval = 500
+moretrees.sapling_chance = 20