[bushes] Tidy code

This commit is contained in:
Sys Quatre 2020-07-23 22:03:13 +02:00
parent 1f52bbea19
commit 2c433e0b57

View File

@ -6,6 +6,8 @@
-- (Leaf texture created by RealBadAngel or VanessaE)
-- Branch textures created by Neuromancer.
local random = math.random
-- support for i18n
local S = minetest.get_translator("bushes")
abstract_bushes = {}
@ -129,33 +131,22 @@ for i in pairs(BushLeafNode) do
end
abstract_bushes.grow_bush = function(pos)
local leaf_type = math.random(1,2)
local bush_side_height = math.random(0,1)
local chance_of_bush_node_right = math.random(1,10)
if chance_of_bush_node_right> 5 then
local right_pos = {x=pos.x+1, y=pos.y+bush_side_height, z=pos.z}
abstract_bushes.grow_bush_node(right_pos,3,leaf_type)
local leaf_type = random(1,2)
for _, pos_dir in ipairs({
{ pos = {x=pos.x+1, y=pos.y+random(0,1), z=pos.z},
dir = 3},
{ pos = {x=pos.x-1, y=pos.y+random(0,1), z=pos.z},
dir = 1},
{ pos = {x=pos.x, y=pos.y+random(0,1), z=pos.z+1},
dir = 2},
{ pos = {x=pos.x, y=pos.y+random(0,1), z=pos.z-1},
dir = 0}
}) do
if random(1,10) > 5 then
abstract_bushes.grow_bush_node(pos_dir.pos, pos_dir.dir, leaf_type)
end
local chance_of_bush_node_left = math.random(1,10)
if chance_of_bush_node_left> 5 then
bush_side_height = math.random(0,1)
local left_pos = {x=pos.x-1, y=pos.y+bush_side_height, z=pos.z}
abstract_bushes.grow_bush_node(left_pos,1,leaf_type)
end
local chance_of_bush_node_front = math.random(1,10)
if chance_of_bush_node_front> 5 then
bush_side_height = math.random(0,1)
local front_pos = {x=pos.x, y=pos.y+bush_side_height, z=pos.z+1}
abstract_bushes.grow_bush_node(front_pos,2,leaf_type)
end
local chance_of_bush_node_back = math.random(1,10)
if chance_of_bush_node_back> 5 then
bush_side_height = math.random(0,1)
local back_pos = {x=pos.x, y=pos.y+bush_side_height, z=pos.z-1}
abstract_bushes.grow_bush_node(back_pos,0,leaf_type)
end
abstract_bushes.grow_bush_node(pos,5,leaf_type)
end
abstract_bushes.grow_bush_node(pos,5,leaf_type)
end
abstract_bushes.grow_bush_node = function(pos,dir, leaf_type)
@ -187,11 +178,9 @@ abstract_bushes.grow_bush_node = function(pos,dir, leaf_type)
minetest.swap_node(right_here, {name="bushes:bushbranches"..bush_branch_type , param2=dir})
--minetest.chat_send_all("leaf_type: (" .. leaf_type .. ")")
minetest.swap_node(above_right_here, {name="bushes:BushLeaves"..leaf_type})
local chance_of_high_leaves = math.random(1,10)
if chance_of_high_leaves> 5 then
local two_above_right_here = {x=pos.x, y=pos.y+3, z=pos.z}
if random(1,10) > 5 then
--minetest.chat_send_all("leaf_type: (" .. leaf_type .. ")")
minetest.swap_node(two_above_right_here, {name="bushes:BushLeaves"..leaf_type})
minetest.swap_node({x=pos.x, y=pos.y+3, z=pos.z}, {name="bushes:BushLeaves"..leaf_type})
end
end
end
@ -213,8 +202,7 @@ biome_lib:register_generate_plant({
)
abstract_bushes.grow_youngtree2 = function(pos)
local height = math.random(4,5)
abstract_bushes.grow_youngtree_node2(pos,height)
abstract_bushes.grow_youngtree_node2(pos, random(4,5))
end
abstract_bushes.grow_youngtree_node2 = function(pos, height)
@ -225,19 +213,17 @@ abstract_bushes.grow_youngtree_node2 = function(pos, height)
local two_above_right_here = {x=pos.x, y=pos.y+3, z=pos.z}
local three_above_right_here = {x=pos.x, y=pos.y+4, z=pos.z}
if minetest.get_node(right_here).name == "air" -- instead of check_air = true,
or minetest.get_node(right_here).name == "default:junglegrass" then
if height == 4 then
local two_above_right_here_south = {x=pos.x, y=pos.y+3, z=pos.z-1}
local three_above_right_here_south = {x=pos.x, y=pos.y+4, z=pos.z-1}
minetest.swap_node(right_here, {name="bushes:youngtree2_bottom"})
minetest.swap_node(above_right_here, {name="bushes:youngtree2_bottom"})
minetest.swap_node(two_above_right_here, {name="bushes:bushbranches2" , param2=2})
minetest.swap_node(two_above_right_here_south, {name="bushes:bushbranches2" , param2=0})
minetest.swap_node(three_above_right_here, {name="bushes:BushLeaves1" })
minetest.swap_node(three_above_right_here_south, {name="bushes:BushLeaves1" })
end
if height == 4 and
(minetest.get_node(right_here).name == "air" -- instead of check_air = true,
or minetest.get_node(right_here).name == "default:junglegrass") then
local two_above_right_here_south = {x=pos.x, y=pos.y+3, z=pos.z-1}
local three_above_right_here_south = {x=pos.x, y=pos.y+4, z=pos.z-1}
minetest.swap_node(right_here, {name="bushes:youngtree2_bottom"})
minetest.swap_node(above_right_here, {name="bushes:youngtree2_bottom"})
minetest.swap_node(two_above_right_here, {name="bushes:bushbranches2" , param2=2})
minetest.swap_node(two_above_right_here_south, {name="bushes:bushbranches2" , param2=0})
minetest.swap_node(three_above_right_here, {name="bushes:BushLeaves1" })
minetest.swap_node(three_above_right_here_south, {name="bushes:BushLeaves1" })
end
end