Add papyrus and cactus growing
authorPilzAdam <pilzadam@minetest.net>
Mon, 18 Mar 2013 23:32:21 +0000 (00:32 +0100)
committerPilzAdam <pilzadam@minetest.net>
Tue, 19 Mar 2013 00:01:22 +0000 (01:01 +0100)
mods/default/init.lua

index c29a6c0a73daa0cf39b6d05c2f4f3d2343d4496c..a0b1e7982ae8278957140045dbee52510edee243 100644 (file)
@@ -2043,4 +2043,59 @@ minetest.register_abm({
        end,
 })
 
+--
+-- Papyrus and cactus growing
+--
+
+minetest.register_abm({
+       nodenames = {"default:cactus"},
+       neighbors = {"group:sand"},
+       interval = 50,
+       chance = 20,
+       action = function(pos, node)
+               pos.y = pos.y-1
+               local name = minetest.env:get_node(pos).name
+               if minetest.get_item_group(name, "sand") ~= 0 then
+                       pos.y = pos.y+1
+                       local height = 0
+                       while minetest.env:get_node(pos).name == "default:cactus" and height < 4 do
+                               height = height+1
+                               pos.y = pos.y+1
+                       end
+                       if height < 4 then
+                               if minetest.env:get_node(pos).name == "air" then
+                                       minetest.env:set_node(pos, {name="default:cactus"})
+                               end
+                       end
+               end
+       end,
+})
+
+minetest.register_abm({
+       nodenames = {"default:papyrus"},
+       neighbors = {"default:dirt", "default:dirt_with_grass"},
+       interval = 50,
+       chance = 20,
+       action = function(pos, node)
+               pos.y = pos.y-1
+               local name = minetest.env:get_node(pos).name
+               if name == "default:dirt" or name == "default:dirt_with_grass" then
+                       if minetest.env:find_node_near(pos, 3, {"group:water"}) == nil then
+                               return
+                       end
+                       pos.y = pos.y+1
+                       local height = 0
+                       while minetest.env:get_node(pos).name == "default:papyrus" and height < 4 do
+                               height = height+1
+                               pos.y = pos.y+1
+                       end
+                       if height < 4 then
+                               if minetest.env:get_node(pos).name == "air" then
+                                       minetest.env:set_node(pos, {name="default:papyrus"})
+                               end
+                       end
+               end
+       end,
+})
+
 -- END