Skip to content

Commit

Permalink
Flowers: Tweak flower and mushroom spreading
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tenplus1 authored and paramat committed Apr 16, 2016
1 parent 7d93272 commit 9ece86c
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions mods/flowers/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -92,28 +93,22 @@ 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
light = minetest.get_node_light(seedling)
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,
})
Expand Down Expand Up @@ -169,27 +164,27 @@ 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,
y = random.y - 1, z = random.z})
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
Expand Down

0 comments on commit 9ece86c

Please sign in to comment.