Skip to content

Commit

Permalink
Flower spread ABM: Optimise
Browse files Browse the repository at this point in the history
Match maximum spread density to maximum mapgen density for flowers.
Place 3 flora nodes at once instead of 1.
Change ABM chance value to 300 to match previous spread rate.
ABM becomes 3 times less intensive.
  • Loading branch information
paramat committed Feb 1, 2018
1 parent d1ece74 commit 1c7691c
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions mods/flowers/init.lua
Expand Up @@ -139,32 +139,34 @@ function flowers.flower_spread(pos, node)


local pos0 = vector.subtract(pos, 4) local pos0 = vector.subtract(pos, 4)
local pos1 = vector.add(pos, 4) local pos1 = vector.add(pos, 4)
if #minetest.find_nodes_in_area(pos0, pos1, "group:flora") > 3 then -- A limit of 11 in a 9*9 area, and 3 added at once, results in an average
-- maximum density of 13, this matches maximum mapgen flower density.
if #minetest.find_nodes_in_area(pos0, pos1, "group:flora") > 11 then
return return
end end


local soils = minetest.find_nodes_in_area_under_air( local soils = minetest.find_nodes_in_area_under_air(
pos0, pos1, "group:soil") pos0, pos1, "group:soil")
if #soils > 0 then local num_soils = #soils
local seedling = soils[math.random(#soils)] if num_soils >= 1 then
local seedling_above = for si = 1, math.min(3, num_soils) do
{x = seedling.x, y = seedling.y + 1, z = seedling.z} local soil = soils[math.random(num_soils)]
light = minetest.get_node_light(seedling_above) local soil_above = {x = soil.x, y = soil.y + 1, z = soil.z}
if not light or light < 13 or light = minetest.get_node_light(soil_above)
-- Desert sand is in the soil group if light and light >= 13 and
minetest.get_node(seedling).name == "default:desert_sand" then -- Desert sand is in the soil group
return minetest.get_node(soil).name ~= "default:desert_sand" then
minetest.set_node(soil_above, {name = node.name})
end
end end

minetest.set_node(seedling_above, {name = node.name})
end end
end end


minetest.register_abm({ minetest.register_abm({
label = "Flower spread", label = "Flower spread",
nodenames = {"group:flora"}, nodenames = {"group:flora"},
interval = 13, interval = 13,
chance = 96, chance = 300,
action = function(...) action = function(...)
flowers.flower_spread(...) flowers.flower_spread(...)
end, end,
Expand Down

0 comments on commit 1c7691c

Please sign in to comment.