1
0
mirror of https://github.com/minetest/minetest_game.git synced 2024-12-23 07:10:19 +01:00

Mushroom spread: Optimise and make overridable

Move mushroom spread ABM action into a global and overridable function.
Optimise spread code.
Reduce spread range to reduce spread through walls.
This commit is contained in:
tenplus1 2017-07-30 14:02:10 +01:00 committed by sfan5
parent cc2f75b2f9
commit 6053456af1

View File

@ -204,38 +204,34 @@ minetest.register_node("flowers:mushroom_brown", {
-- Mushroom spread and death -- Mushroom spread and death
minetest.register_abm({ function flowers.mushroom_spread(pos, node)
label = "Mushroom spread",
nodenames = {"flowers:mushroom_brown", "flowers:mushroom_red"},
interval = 11,
chance = 50,
action = function(pos, node)
if minetest.get_node_light(pos, nil) == 15 then if minetest.get_node_light(pos, nil) == 15 then
minetest.remove_node(pos) minetest.remove_node(pos)
return return
end end
local random = { local positions = minetest.find_nodes_in_area_under_air(
x = pos.x + math.random(-2, 2), {x = pos.x - 1, y = pos.y - 2, z = pos.z - 1},
y = pos.y + math.random(-1, 1), {x = pos.x + 1, y = pos.y + 1, z = pos.z + 1},
z = pos.z + math.random(-2, 2) {"group:soil", "group:tree"})
} if #positions == 0 then
local random_node = minetest.get_node_or_nil(random)
if not random_node or random_node.name ~= "air" then
return return
end end
local node_under = minetest.get_node_or_nil({x = random.x, local pos2 = positions[math.random(#positions)]
y = random.y - 1, z = random.z}) pos2.y = pos2.y + 1
if not node_under then if minetest.get_node_light(pos, 0.5) <= 3 and
return minetest.get_node_light(pos2, 0.5) <= 3 then
minetest.set_node(pos2, {name = node.name})
end
end end
if (minetest.get_item_group(node_under.name, "soil") ~= 0 or minetest.register_abm({
minetest.get_item_group(node_under.name, "tree") ~= 0) and label = "Mushroom spread",
minetest.get_node_light(pos, 0.5) <= 3 and nodenames = {"flowers:mushroom_brown", "flowers:mushroom_red"},
minetest.get_node_light(random, 0.5) <= 3 then interval = 11,
minetest.set_node(random, {name = node.name}) chance = 150,
end action = function(...)
end flowers.mushroom_spread(...)
end,
}) })