]> git.lizzy.rs Git - Crafter.git/blobdiff - mods/main/saplings.lua
remove server debug
[Crafter.git] / mods / main / saplings.lua
index 63cc9bb1ce438c2b470a42929426734d333b50d7..436d68aa932df751dbe2fb76279b3520ad8dd8c7 100644 (file)
@@ -1,13 +1,11 @@
 --saplings
 --
 --
-local sapling_min = 120
-local sapling_max = 720
+--local sapling_min = 120
+--local sapling_max = 720
 --make sapling grow
 local function sapling_grow(pos)
        if minetest.get_node_light(pos, nil) < 10 then
-               local timer = minetest.get_node_timer(pos)
-               timer:start(math.random(sapling_min,sapling_max))
                --print("failed to grow at "..dump(pos))
                return
        end
@@ -23,9 +21,18 @@ local function sapling_grow(pos)
                end
                if good_to_grow == true then
                        minetest.set_node(pos,{name="main:tree"})
-                       minetest.place_schematic(pos, treeSchematic,"0",nil,false,"place_center_x, place_center_z")
+                       local schemmy = math.random(1,2)
+                       if schemmy == 1 then
+                               minetest.place_schematic(pos, tree_big,"0",nil,false,"place_center_x, place_center_z")
+                       elseif schemmy == 2 then
+                               minetest.place_schematic(pos, tree_small,"0",nil,false,"place_center_x, place_center_z")
+                       end
                        --override leaves
-                       for i = 1,4 do
+                       local max = 3
+                       if schemmy == 2 then
+                               max = 1
+                       end
+                       for i = 1,max do
                                minetest.set_node(vector.new(pos.x,pos.y+i,pos.z),{name="main:tree"})
                        end
                end
@@ -50,7 +57,7 @@ minetest.register_node("main:sapling", {
                type = "fixed",
                fixed = {-4 / 16, -0.5, -4 / 16, 4 / 16, 7 / 16, 4 / 16}
        },
-       on_place =  on_rightclick or function(itemstack, placer, pointed_thing)
+       on_place =  function(itemstack, placer, pointed_thing)
                if not pointed_thing.type == "node" then
                        return
                end
@@ -81,11 +88,18 @@ minetest.register_node("main:sapling", {
                        return(itemstack)
                end
        end,
-       on_construct = function(pos)
-               local timer = minetest.get_node_timer(pos)
-               timer:start(math.random(sapling_min,sapling_max))
-       end,
-       on_timer = function(pos)
+})
+
+
+--growing abm for sapling
+minetest.register_abm({
+       label = "Tree Grow",
+       nodenames = {"group:sapling"},
+       neighbors = {"group:soil"},
+       interval = 6,
+       chance = 250,
+       catch_up = true,
+       action = function(pos)
                sapling_grow(pos)
        end,
 })