Default/functions: Fix cactus growing by rotation again. Cleanup code

This commit is contained in:
paramat 2015-06-07 22:48:26 +01:00
parent 64fa8e6be5
commit f92d49feff
1 changed files with 55 additions and 52 deletions

View File

@ -123,6 +123,8 @@ minetest.register_abm({
-- Papyrus and cactus growing
--
-- wrapping the functions in abm action is necessary to make overriding them possible
function default.grow_cactus(pos, node)
if node.param2 >= 4 then
return
@ -133,13 +135,12 @@ function default.grow_cactus(pos, node)
end
pos.y = pos.y + 1
local height = 0
while node.name == "default:cactus" and height < 4 and node.param2 == 0 do
while node.name == "default:cactus" 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
if height == 4 or node.name ~= "air" then
return
end
minetest.set_node(pos, {name = "default:cactus"})
@ -149,8 +150,7 @@ 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
if name ~= "default:dirt_with_grass" and name ~= "default:dirt" then
return
end
if not minetest.find_node_near(pos, 3, {"group:water"}) then
@ -163,15 +163,13 @@ function default.grow_papyrus(pos, node)
pos.y = pos.y + 1
node = minetest.get_node(pos)
end
if height == 4
or node.name ~= "air" then
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"},
@ -255,8 +253,10 @@ minetest.register_abm({
if trunkp then
local n = minetest.get_node(trunkp)
local reg = minetest.registered_nodes[n.name]
-- Assume ignore is a trunk, to make the thing work at the border of the active area
if n.name == "ignore" or (reg and reg.groups.tree and reg.groups.tree ~= 0) then
-- Assume ignore is a trunk, to make the thing
-- work at the border of the active area
if n.name == "ignore" or (reg and reg.groups.tree and
reg.groups.tree ~= 0) then
--print("cached trunk still exists")
return
end
@ -270,7 +270,8 @@ minetest.register_abm({
end
default.leafdecay_trunk_find_allow_accumulator =
default.leafdecay_trunk_find_allow_accumulator - 1
-- Assume ignore is a trunk, to make the thing work at the border of the active area
-- Assume ignore is a trunk, to make the thing
-- work at the border of the active area
local p1 = minetest.find_node_near(p0, d, {"ignore", "group:tree"})
if p1 then
do_preserve = true
@ -301,6 +302,7 @@ minetest.register_abm({
end
})
--
-- Grass growing
--
@ -313,9 +315,9 @@ minetest.register_abm({
local above = {x = pos.x, y = pos.y + 1, z = pos.z}
local name = minetest.get_node(above).name
local nodedef = minetest.registered_nodes[name]
if nodedef and (nodedef.sunlight_propagates or nodedef.paramtype == "light")
and nodedef.liquidtype == "none"
and (minetest.get_node_light(above) or 0) >= 13 then
if nodedef and (nodedef.sunlight_propagates or nodedef.paramtype == "light") and
nodedef.liquidtype == "none" and
(minetest.get_node_light(above) or 0) >= 13 then
if name == "default:snow" or name == "default:snowblock" then
minetest.set_node(pos, {name = "default:dirt_with_snow"})
else
@ -333,10 +335,11 @@ minetest.register_abm({
local above = {x = pos.x, y = pos.y + 1, z = pos.z}
local name = minetest.get_node(above).name
local nodedef = minetest.registered_nodes[name]
if name ~= "ignore" and nodedef
and not ((nodedef.sunlight_propagates or nodedef.paramtype == "light")
and nodedef.liquidtype == "none") then
if name ~= "ignore" and nodedef and not ((nodedef.sunlight_propagates or
nodedef.paramtype == "light") and
nodedef.liquidtype == "none") then
minetest.set_node(pos, {name = "default:dirt"})
end
end
})