Mushroom spread: make overridable and reduce spread

* Move mushroom spread ABM action into a global and overridable function.
  but do not optimise spread code
* backported bcf98df5fac3eb59b02d9fdb066ab92c6228d787
* Reduce spread range to reduce spread through walls.
This commit is contained in:
Герхард PICCORO Lenz McKAY 2021-12-10 15:24:32 -04:00
parent 535204298e
commit be96530e20

View File

@ -214,19 +214,28 @@ function flowers.mushroom_spread(pos, node)
minetest.remove_node(pos) minetest.remove_node(pos)
return return
end end
local positions = minetest.find_nodes_in_area_under_air( local random = {
{x = pos.x - 1, y = pos.y - 2, z = pos.z - 1}, x = pos.x + math.random(-2, 2),
{x = pos.x + 1, y = pos.y + 1, z = pos.z + 1}, y = pos.y + math.random(-1, 1),
{"group:soil", "group:tree"}) z = pos.z + math.random(-2, 2)
if #positions == 0 then }
return local random_node = minetest.get_node_or_nil(random)
if not random_node or random_node.name ~= "air" then
return
end end
local pos2 = positions[math.random(#positions)] local node_under = minetest.get_node_or_nil({x = random.x,
pos2.y = pos2.y + 1 y = random.y - 1, z = random.z})
if minetest.get_node_light(pos, 0.5) <= 3 and if not node_under then
minetest.get_node_light(pos2, 0.5) <= 3 then return
minetest.set_node(pos2, {name = node.name})
end end
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 end
minetest.register_abm({ minetest.register_abm({