Default/functions: Fix cactus growing by rotation again. Cleanup code
This commit is contained in:
parent
64fa8e6be5
commit
f92d49feff
|
@ -123,6 +123,8 @@ minetest.register_abm({
|
||||||
-- Papyrus and cactus growing
|
-- Papyrus and cactus growing
|
||||||
--
|
--
|
||||||
|
|
||||||
|
-- wrapping the functions in abm action is necessary to make overriding them possible
|
||||||
|
|
||||||
function default.grow_cactus(pos, node)
|
function default.grow_cactus(pos, node)
|
||||||
if node.param2 >= 4 then
|
if node.param2 >= 4 then
|
||||||
return
|
return
|
||||||
|
@ -133,13 +135,12 @@ function default.grow_cactus(pos, node)
|
||||||
end
|
end
|
||||||
pos.y = pos.y + 1
|
pos.y = pos.y + 1
|
||||||
local height = 0
|
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
|
height = height + 1
|
||||||
pos.y = pos.y + 1
|
pos.y = pos.y + 1
|
||||||
node = minetest.get_node(pos)
|
node = minetest.get_node(pos)
|
||||||
end
|
end
|
||||||
if height == 4
|
if height == 4 or node.name ~= "air" then
|
||||||
or node.name ~= "air" then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
minetest.set_node(pos, {name = "default:cactus"})
|
minetest.set_node(pos, {name = "default:cactus"})
|
||||||
|
@ -149,8 +150,7 @@ end
|
||||||
function default.grow_papyrus(pos, node)
|
function default.grow_papyrus(pos, node)
|
||||||
pos.y = pos.y - 1
|
pos.y = pos.y - 1
|
||||||
local name = minetest.get_node(pos).name
|
local name = minetest.get_node(pos).name
|
||||||
if name ~= "default:dirt_with_grass"
|
if name ~= "default:dirt_with_grass" and name ~= "default:dirt" then
|
||||||
and name ~= "default:dirt" then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if not minetest.find_node_near(pos, 3, {"group:water"}) then
|
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
|
pos.y = pos.y + 1
|
||||||
node = minetest.get_node(pos)
|
node = minetest.get_node(pos)
|
||||||
end
|
end
|
||||||
if height == 4
|
if height == 4 or node.name ~= "air" then
|
||||||
or node.name ~= "air" then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
minetest.set_node(pos, {name = "default:papyrus"})
|
minetest.set_node(pos, {name = "default:papyrus"})
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- wrapping the functions in abm action is necessary to make overriding them possible
|
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = {"default:cactus"},
|
nodenames = {"default:cactus"},
|
||||||
neighbors = {"group:sand"},
|
neighbors = {"group:sand"},
|
||||||
|
@ -255,8 +253,10 @@ minetest.register_abm({
|
||||||
if trunkp then
|
if trunkp then
|
||||||
local n = minetest.get_node(trunkp)
|
local n = minetest.get_node(trunkp)
|
||||||
local reg = minetest.registered_nodes[n.name]
|
local reg = minetest.registered_nodes[n.name]
|
||||||
-- 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
|
||||||
if n.name == "ignore" or (reg and reg.groups.tree and reg.groups.tree ~= 0) then
|
-- 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")
|
--print("cached trunk still exists")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -270,7 +270,8 @@ minetest.register_abm({
|
||||||
end
|
end
|
||||||
default.leafdecay_trunk_find_allow_accumulator =
|
default.leafdecay_trunk_find_allow_accumulator =
|
||||||
default.leafdecay_trunk_find_allow_accumulator - 1
|
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"})
|
local p1 = minetest.find_node_near(p0, d, {"ignore", "group:tree"})
|
||||||
if p1 then
|
if p1 then
|
||||||
do_preserve = true
|
do_preserve = true
|
||||||
|
@ -301,6 +302,7 @@ minetest.register_abm({
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Grass growing
|
-- Grass growing
|
||||||
--
|
--
|
||||||
|
@ -313,9 +315,9 @@ minetest.register_abm({
|
||||||
local above = {x = pos.x, y = pos.y + 1, z = pos.z}
|
local above = {x = pos.x, y = pos.y + 1, z = pos.z}
|
||||||
local name = minetest.get_node(above).name
|
local name = minetest.get_node(above).name
|
||||||
local nodedef = minetest.registered_nodes[name]
|
local nodedef = minetest.registered_nodes[name]
|
||||||
if nodedef and (nodedef.sunlight_propagates or nodedef.paramtype == "light")
|
if nodedef and (nodedef.sunlight_propagates or nodedef.paramtype == "light") and
|
||||||
and nodedef.liquidtype == "none"
|
nodedef.liquidtype == "none" and
|
||||||
and (minetest.get_node_light(above) or 0) >= 13 then
|
(minetest.get_node_light(above) or 0) >= 13 then
|
||||||
if name == "default:snow" or name == "default:snowblock" then
|
if name == "default:snow" or name == "default:snowblock" then
|
||||||
minetest.set_node(pos, {name = "default:dirt_with_snow"})
|
minetest.set_node(pos, {name = "default:dirt_with_snow"})
|
||||||
else
|
else
|
||||||
|
@ -333,10 +335,11 @@ minetest.register_abm({
|
||||||
local above = {x = pos.x, y = pos.y + 1, z = pos.z}
|
local above = {x = pos.x, y = pos.y + 1, z = pos.z}
|
||||||
local name = minetest.get_node(above).name
|
local name = minetest.get_node(above).name
|
||||||
local nodedef = minetest.registered_nodes[name]
|
local nodedef = minetest.registered_nodes[name]
|
||||||
if name ~= "ignore" and nodedef
|
if name ~= "ignore" and nodedef and not ((nodedef.sunlight_propagates or
|
||||||
and not ((nodedef.sunlight_propagates or nodedef.paramtype == "light")
|
nodedef.paramtype == "light") and
|
||||||
and nodedef.liquidtype == "none") then
|
nodedef.liquidtype == "none") then
|
||||||
minetest.set_node(pos, {name = "default:dirt"})
|
minetest.set_node(pos, {name = "default:dirt"})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue