Skip to content

Commit

Permalink
allow overriding papyrus and cactus grow functions
Browse files Browse the repository at this point in the history
dont grow cactus on a lying one

use minetest.get_node 2 times less

do a bit what ShadowNinja wrote

add comment

return true if the plant is set
  • Loading branch information
HybridDog authored and paramat committed Apr 27, 2015
1 parent d0070f2 commit fe3c5a7
Showing 1 changed file with 63 additions and 41 deletions.
104 changes: 63 additions & 41 deletions mods/default/functions.lua
Expand Up @@ -83,6 +83,7 @@ function default.node_sound_glass_defaults(table)
return table
end


--
-- Lavacooling
--
Expand All @@ -102,8 +103,8 @@ minetest.register_abm({
neighbors = {"group:water"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
default.cool_lava_flowing(pos, node, active_object_count, active_object_count_wider)
action = function(...)
default.cool_lava_flowing(...)
end,
})

Expand All @@ -112,66 +113,86 @@ minetest.register_abm({
neighbors = {"group:water"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
default.cool_lava_source(pos, node, active_object_count, active_object_count_wider)
action = function(...)
default.cool_lava_source(...)
end,
})


--
-- Papyrus and cactus growing
--

function default.grow_cactus(pos, node)
if node.param2 ~= 0 then
return
end
pos.y = pos.y-1
if minetest.get_item_group(minetest.get_node(pos).name, "sand") == 0 then
return
end
pos.y = pos.y+1
local height = 0
while node.name == "default:cactus" and height < 4 and node.param2 == 0 do
height = height+1
pos.y = pos.y+1
node = minetest.get_node(pos)
end
if height == 4
or node.name ~= "air" then
return
end
minetest.set_node(pos, {name="default:cactus"})
return true
end

function default.grow_papyrus(pos, node)
pos.y = pos.y-1
local name = minetest.get_node(pos).name
if name ~= "default:dirt_with_grass"
and name ~= "default:dirt" then
return
end
if not minetest.find_node_near(pos, 3, {"group:water"}) then
return
end
pos.y = pos.y+1
local height = 0
while node.name == "default:papyrus" and height < 4 do
height = height+1
pos.y = pos.y+1
node = minetest.get_node(pos)
end
if height == 4
or node.name ~= "air" then
return
end
minetest.set_node(pos, {name="default:papyrus"})
return true
end

-- wrapping the functions in abm action is necessary to make overriding them possible
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.get_node(pos).name
if minetest.get_item_group(name, "sand") ~= 0 then
pos.y = pos.y+1
local height = 0
while minetest.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.get_node(pos).name == "air" then
minetest.set_node(pos, {name="default:cactus"})
end
end
end
end,
action = function(...)
default.grow_cactus(...)
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.get_node(pos).name
if name == "default:dirt" or name == "default:dirt_with_grass" then
if minetest.find_node_near(pos, 3, {"group:water"}) == nil then
return
end
pos.y = pos.y+1
local height = 0
while minetest.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.get_node(pos).name == "air" then
minetest.set_node(pos, {name="default:papyrus"})
end
end
end
end,
action = function(...)
default.grow_papyrus(...)
end
})


--
-- dig upwards
--
Expand All @@ -185,6 +206,7 @@ function default.dig_up(pos, node, digger)
end
end


--
-- Leafdecay
--
Expand Down

0 comments on commit fe3c5a7

Please sign in to comment.