From: tenplus1 Date: Sun, 3 Apr 2016 15:31:19 +0000 (+0100) Subject: Flowers: Tweak flower and mushroom spreading X-Git-Tag: 0.4.14~31 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=9ece86cc7ada071f6eb64ff9f13e40f34a3c5ac0;p=oweals%2Fminetest_game.git Flowers: Tweak flower and mushroom spreading Tidy up position numbers and code Check for flora group aswell Improve node light check for mushroom growth Shrooms grow in 3 and below light --- diff --git a/mods/flowers/init.lua b/mods/flowers/init.lua index d5581d0c..73a66bfa 100644 --- a/mods/flowers/init.lua +++ b/mods/flowers/init.lua @@ -83,6 +83,7 @@ minetest.register_abm({ pos.y = pos.y + 1 if under.name == "default:desert_sand" then minetest.set_node(pos, {name = "default:dry_shrub"}) + return elseif under.name ~= "default:dirt_with_grass" then return end @@ -92,18 +93,14 @@ minetest.register_abm({ return end - local pos0 = {x = pos.x - 4, y = pos.y - 4, z = pos.z - 4} - local pos1 = {x = pos.x + 4, y = pos.y + 4, z = pos.z + 4} - if #minetest.find_nodes_in_area(pos0, pos1, "group:flora_block") > 0 then + local pos0 = vector.subtract(pos, 4) + local pos1 = vector.add(pos, 4) + if #minetest.find_nodes_in_area(pos0, pos1, "group:flora") > 3 or + #minetest.find_nodes_in_area(pos0, pos1, "group:flora_block") > 0 then return end - local flowers = minetest.find_nodes_in_area(pos0, pos1, "group:flora") - if #flowers > 3 then - return - end - - local seedling = minetest.find_nodes_in_area(pos0, pos1, "default:dirt_with_grass") + local seedling = minetest.find_nodes_in_area_under_air(pos0, pos1, "default:dirt_with_grass") if #seedling > 0 then seedling = seedling[math.random(#seedling)] seedling.y = seedling.y + 1 @@ -111,9 +108,7 @@ minetest.register_abm({ if not light or light < 13 then return end - if minetest.get_node(seedling).name == "air" then - minetest.set_node(seedling, {name = node.name}) - end + minetest.set_node(seedling, {name = node.name}) end end, }) @@ -169,17 +164,15 @@ minetest.register_abm({ action = function(pos, node) if minetest.get_node_light(pos, nil) == 15 then minetest.remove_node(pos) + return end local random = { - x = pos.x + math.random(-2,2), - y = pos.y + math.random(-1,1), - z = pos.z + math.random(-2,2) + x = pos.x + math.random(-2, 2), + y = pos.y + math.random(-1, 1), + z = pos.z + math.random(-2, 2) } local random_node = minetest.get_node_or_nil(random) - if not random_node then - return - end - if random_node.name ~= "air" then + if not random_node or random_node.name ~= "air" then return end local node_under = minetest.get_node_or_nil({x = random.x, @@ -187,9 +180,11 @@ minetest.register_abm({ if not node_under then return end - if minetest.get_item_group(node_under.name, "soil") ~= 0 and - minetest.get_node_light(pos, nil) <= 9 and - minetest.get_node_light(random, nil) <= 9 then + + if (minetest.get_item_group(node_under.name, "soil") ~= 0 or + minetest.get_item_group(node_under.name, "tree") ~= 0) and + minetest.get_node_light(pos, 0.5) <= 3 and + minetest.get_node_light(random, 0.5) <= 3 then minetest.set_node(random, {name = node.name}) end end