forked from mtcontrib/plantlife_modpack
		
	[bushes] Tidy code
This commit is contained in:
		@@ -6,6 +6,8 @@
 | 
				
			|||||||
-- (Leaf texture created by RealBadAngel or VanessaE)
 | 
					-- (Leaf texture created by RealBadAngel or VanessaE)
 | 
				
			||||||
-- Branch textures created by Neuromancer.
 | 
					-- Branch textures created by Neuromancer.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local random = math.random
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- support for i18n
 | 
					-- support for i18n
 | 
				
			||||||
local S = minetest.get_translator("bushes")
 | 
					local S = minetest.get_translator("bushes")
 | 
				
			||||||
  abstract_bushes = {}
 | 
					  abstract_bushes = {}
 | 
				
			||||||
@@ -129,32 +131,21 @@ for i in pairs(BushLeafNode) do
 | 
				
			|||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
abstract_bushes.grow_bush = function(pos)
 | 
					abstract_bushes.grow_bush = function(pos)
 | 
				
			||||||
	local leaf_type = math.random(1,2)
 | 
						local leaf_type = random(1,2)
 | 
				
			||||||
	local bush_side_height = math.random(0,1)
 | 
						for _, pos_dir in ipairs({
 | 
				
			||||||
		local chance_of_bush_node_right = math.random(1,10)
 | 
							{ pos = {x=pos.x+1, y=pos.y+random(0,1), z=pos.z},
 | 
				
			||||||
		if chance_of_bush_node_right> 5 then
 | 
							  dir = 3},
 | 
				
			||||||
			local right_pos = {x=pos.x+1, y=pos.y+bush_side_height, z=pos.z}
 | 
							{ pos = {x=pos.x-1, y=pos.y+random(0,1), z=pos.z},
 | 
				
			||||||
			abstract_bushes.grow_bush_node(right_pos,3,leaf_type)
 | 
							  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
 | 
							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
 | 
						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)
 | 
						abstract_bushes.grow_bush_node(pos,5,leaf_type)
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -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.swap_node(right_here, {name="bushes:bushbranches"..bush_branch_type , param2=dir})
 | 
				
			||||||
						--minetest.chat_send_all("leaf_type: (" .. leaf_type .. ")")
 | 
											--minetest.chat_send_all("leaf_type: (" .. leaf_type .. ")")
 | 
				
			||||||
		minetest.swap_node(above_right_here, {name="bushes:BushLeaves"..leaf_type})
 | 
							minetest.swap_node(above_right_here, {name="bushes:BushLeaves"..leaf_type})
 | 
				
			||||||
		local chance_of_high_leaves = math.random(1,10)
 | 
							if random(1,10) > 5 then
 | 
				
			||||||
		if chance_of_high_leaves> 5 then
 | 
					 | 
				
			||||||
			local two_above_right_here = {x=pos.x, y=pos.y+3, z=pos.z}
 | 
					 | 
				
			||||||
							--minetest.chat_send_all("leaf_type: (" .. leaf_type .. ")")
 | 
												--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
 | 
						end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
@@ -213,8 +202,7 @@ biome_lib:register_generate_plant({
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 abstract_bushes.grow_youngtree2 = function(pos)
 | 
					 abstract_bushes.grow_youngtree2 = function(pos)
 | 
				
			||||||
	local height = math.random(4,5)
 | 
						abstract_bushes.grow_youngtree_node2(pos, random(4,5))
 | 
				
			||||||
	abstract_bushes.grow_youngtree_node2(pos,height)
 | 
					 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
abstract_bushes.grow_youngtree_node2 = function(pos, height)
 | 
					abstract_bushes.grow_youngtree_node2 = function(pos, height)
 | 
				
			||||||
@@ -225,9 +213,9 @@ abstract_bushes.grow_youngtree_node2 = function(pos, height)
 | 
				
			|||||||
	local two_above_right_here = {x=pos.x, y=pos.y+3, z=pos.z}
 | 
						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}
 | 
						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,
 | 
						if height == 4 and
 | 
				
			||||||
	or minetest.get_node(right_here).name == "default:junglegrass" then
 | 
							(minetest.get_node(right_here).name == "air"  -- instead of check_air = true,
 | 
				
			||||||
		if height == 4 then
 | 
							 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 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}
 | 
								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(right_here, {name="bushes:youngtree2_bottom"})
 | 
				
			||||||
@@ -237,8 +225,6 @@ abstract_bushes.grow_youngtree_node2 = function(pos, height)
 | 
				
			|||||||
			minetest.swap_node(three_above_right_here, {name="bushes:BushLeaves1" })
 | 
								minetest.swap_node(three_above_right_here, {name="bushes:BushLeaves1" })
 | 
				
			||||||
			minetest.swap_node(three_above_right_here_south, {name="bushes:BushLeaves1" })
 | 
								minetest.swap_node(three_above_right_here_south, {name="bushes:BushLeaves1" })
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					 | 
				
			||||||
	end
 | 
					 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user