1
0
mirror of https://github.com/mt-mods/plantlife_modpack.git synced 2024-11-13 22:00:39 +01:00

Refactor abstract_ferns.grow_giant_tree_fern

Arguably more readable; definately more maintainable

Potentially slower but if it is the difference would be negligable
This commit is contained in:
Craig Robbins 2014-08-20 18:00:59 +10:00 committed by Vanessa Ezekowitz
parent 76414325cf
commit 62b27570f4

View File

@ -20,26 +20,45 @@ abstract_ferns.grow_giant_tree_fern = function(pos)
local size = math.random(12,16) -- min of range must be >= 4 local size = math.random(12,16) -- min of range must be >= 4
local leaf_a_1 = {x = pos.x + 1, y = pos.y + size - 1, z = pos.z } local leafchecks = {
local leaf_a_2 = {x = pos.x + 2, y = pos.y + size , z = pos.z } {
local leaf_a_3 = {x = pos.x + 3, y = pos.y + size - 1, z = pos.z } direction = 3,
local leaf_a_4 = {x = pos.x + 4, y = pos.y + size - 2, z = pos.z } positions = {
{x = pos.x + 1, y = pos.y + size - 1, z = pos.z },
local leaf_b_1 = {x = pos.x - 1, y = pos.y + size - 1, z = pos.z } {x = pos.x + 2, y = pos.y + size , z = pos.z },
local leaf_b_2 = {x = pos.x - 2, y = pos.y + size, z = pos.z } {x = pos.x + 3, y = pos.y + size - 1, z = pos.z },
local leaf_b_3 = {x = pos.x - 3, y = pos.y + size - 1, z = pos.z } {x = pos.x + 4, y = pos.y + size - 2, z = pos.z }
local leaf_b_4 = {x = pos.x - 4, y = pos.y + size - 2, z = pos.z } }
},
local leaf_c_1 = {x = pos.x , y = pos.y + size - 1, z = pos.z + 1} {
local leaf_c_2 = {x = pos.x , y = pos.y + size , z = pos.z + 2} direction = 1,
local leaf_c_3 = {x = pos.x , y = pos.y + size - 1, z = pos.z + 3} positions = {
local leaf_c_4 = {x = pos.x , y = pos.y + size - 2, z = pos.z + 4} {x = pos.x - 1, y = pos.y + size - 1, z = pos.z },
{x = pos.x - 2, y = pos.y + size, z = pos.z },
local leaf_d_1 = {x = pos.x , y = pos.y + size - 1, z = pos.z - 1} {x = pos.x - 3, y = pos.y + size - 1, z = pos.z },
local leaf_d_2 = {x = pos.x , y = pos.y + size , z = pos.z - 2} {x = pos.x - 4, y = pos.y + size - 2, z = pos.z }
local leaf_d_3 = {x = pos.x , y = pos.y + size - 1, z = pos.z - 3} }
local leaf_d_4 = {x = pos.x , y = pos.y + size - 2, z = pos.z - 4} },
{
direction = 2,
positions = {
{x = pos.x , y = pos.y + size - 1, z = pos.z + 1},
{x = pos.x , y = pos.y + size , z = pos.z + 2},
{x = pos.x , y = pos.y + size - 1, z = pos.z + 3},
{x = pos.x , y = pos.y + size - 2, z = pos.z + 4}
}
},
{
direction = 0,
positions = {
{x = pos.x , y = pos.y + size - 1, z = pos.z - 1},
{x = pos.x , y = pos.y + size , z = pos.z - 2},
{x = pos.x , y = pos.y + size - 1, z = pos.z - 3},
{x = pos.x , y = pos.y + size - 2, z = pos.z - 4}
}
}
}
for i = 1, size-3 do for i = 1, size-3 do
minetest.set_node({x = pos.x, y = pos.y + i, z = pos.z}, {name="ferns:fern_trunk_big"}) minetest.set_node({x = pos.x, y = pos.y + i, z = pos.z}, {name="ferns:fern_trunk_big"})
end end
@ -48,78 +67,26 @@ abstract_ferns.grow_giant_tree_fern = function(pos)
-- all the checking for air below is to prevent some ugly bugs (incomplete trunks of neighbouring trees), it's a bit slower, but worth the result -- all the checking for air below is to prevent some ugly bugs (incomplete trunks of neighbouring trees), it's a bit slower, but worth the result
if minetest.get_node(leaf_a_1).name == "air" then -- assert(#leafchecks == 4)
minetest.set_node(leaf_a_1, {name="ferns:tree_fern_leaf_big"}) for i = 1, 4 do
if minetest.get_node(leaf_a_2).name == "air" then local positions = leafchecks[i].positions
minetest.set_node(leaf_a_2, {name="ferns:tree_fern_leaf_big"}) local rot = leafchecks[i].direction
if minetest.get_node(leaf_a_3).name == "air" then local endpos = 4 -- If the loop below adds all intermediate leaves then the "terminating" leaf will be at positions[4]
minetest.set_node(leaf_a_3, {name="ferns:tree_fern_leaf_big"}) -- assert(#positions == 4)
if minetest.get_node(leaf_a_4).name == "air" then -- add leaves so long as the destination nodes are air
minetest.set_node(leaf_a_4, {name="ferns:tree_fern_leaf_big_end", param2=3}) for j = 1, 3 do
end if minetest.get_node(positions[j]).name == "air" then
minetest.set_node(positions[j], {name="ferns:tree_fern_leaf_big"})
else
endpos = j
break
end end
end end
end -- add the terminating leaf if required and possible
if endpos == 4 and minetest.get_node(positions[endpos]).name == "air" then
if minetest.get_node(leaf_b_1).name == "air" then minetest.set_node(positions[endpos], {name="ferns:tree_fern_leaf_big_end", param2=rot})
minetest.set_node(leaf_b_1, {name="ferns:tree_fern_leaf_big"})
if minetest.get_node(leaf_b_2).name == "air" then
minetest.set_node(leaf_b_2, {name="ferns:tree_fern_leaf_big"})
if minetest.get_node(leaf_b_3).name == "air" then
minetest.set_node(leaf_b_3, {name="ferns:tree_fern_leaf_big"})
if minetest.get_node(leaf_b_4).name == "air" then
minetest.set_node(leaf_b_4, {name="ferns:tree_fern_leaf_big_end", param2=1})
end
end
end end
end end
if minetest.get_node(leaf_c_1).name == "air" then
minetest.set_node(leaf_c_1, {name="ferns:tree_fern_leaf_big"})
if minetest.get_node(leaf_c_2).name == "air" then
minetest.set_node(leaf_c_2, {name="ferns:tree_fern_leaf_big"})
if minetest.get_node(leaf_c_3).name == "air" then
minetest.set_node(leaf_c_3, {name="ferns:tree_fern_leaf_big"})
if minetest.get_node(leaf_c_4).name == "air" then
minetest.set_node(leaf_c_4, {name="ferns:tree_fern_leaf_big_end", param2=2})
end
end
end
end
if minetest.get_node(leaf_d_1).name == "air" then
minetest.set_node(leaf_d_1, {name="ferns:tree_fern_leaf_big"})
if minetest.get_node(leaf_d_2).name == "air" then
minetest.set_node(leaf_d_2, {name="ferns:tree_fern_leaf_big"})
if minetest.get_node(leaf_d_3).name == "air" then
minetest.set_node(leaf_d_3, {name="ferns:tree_fern_leaf_big"})
if minetest.get_node(leaf_d_4).name == "air" then
minetest.set_node(leaf_d_4, {name="ferns:tree_fern_leaf_big_end", param2=0})
end
end
end
end
-- bug fixes # 2 - doesn't really work, so disabled for now
--[[if minetest.get_node(leaf_a_4).name == "ferns:tree_fern_leaf_big_end"
and minetest.get_node(leaf_a_3).name == "ferns:fern_trunk_big" then
minetest.set_node(leaf_a_4, {name="air"})
end
if minetest.get_node(leaf_b_4).name == "ferns:tree_fern_leaf_big_end"
and minetest.get_node(leaf_b_3).name == "ferns:fern_trunk_big" then
minetest.set_node(leaf_b_4, {name="air"})
end
if minetest.get_node(leaf_c_4).name == "ferns:tree_fern_leaf_big_end"
and minetest.get_node(leaf_c_3).name == "ferns:fern_trunk_big" then
minetest.set_node(leaf_c_4, {name="air"})
end
if minetest.get_node(leaf_d_4).name == "ferns:tree_fern_leaf_big_end"
and minetest.get_node(leaf_d_3).name == "ferns:fern_trunk_big" then
minetest.set_node(leaf_d_4, {name="air"})
end]]
end end
----------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------