Skip to content

Commit a587972

Browse files
committed
Flower spread ABM: Optimise
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.
1 parent d5907d5 commit a587972

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

mods/flowers/init.lua

+18-13
Original file line numberDiff line numberDiff line change
@@ -139,32 +139,37 @@ function flowers.flower_spread(pos, node)
139139

140140
local pos0 = vector.subtract(pos, 4)
141141
local pos1 = vector.add(pos, 4)
142-
if #minetest.find_nodes_in_area(pos0, pos1, "group:flora") > 3 then
142+
-- Maximum flower density created by mapgen is 13 per 9x9 area.
143+
-- The limit of 7 below was tuned by in-game testing to result in a maximum
144+
-- flower density by ABM spread of 13 per 9x9 area.
145+
-- Warning: Setting this limit theoretically without in-game testing
146+
-- results in a maximum flower density by ABM spread that is far too high.
147+
if #minetest.find_nodes_in_area(pos0, pos1, "group:flora") > 7 then
143148
return
144149
end
145150

146151
local soils = minetest.find_nodes_in_area_under_air(
147152
pos0, pos1, "group:soil")
148-
if #soils > 0 then
149-
local seedling = soils[math.random(#soils)]
150-
local seedling_above =
151-
{x = seedling.x, y = seedling.y + 1, z = seedling.z}
152-
light = minetest.get_node_light(seedling_above)
153-
if not light or light < 13 or
154-
-- Desert sand is in the soil group
155-
minetest.get_node(seedling).name == "default:desert_sand" then
156-
return
153+
local num_soils = #soils
154+
if num_soils >= 1 then
155+
for si = 1, math.min(3, num_soils) do
156+
local soil = soils[math.random(num_soils)]
157+
local soil_above = {x = soil.x, y = soil.y + 1, z = soil.z}
158+
light = minetest.get_node_light(soil_above)
159+
if light and light >= 13 and
160+
-- Desert sand is in the soil group
161+
minetest.get_node(soil).name ~= "default:desert_sand" then
162+
minetest.set_node(soil_above, {name = node.name})
163+
end
157164
end
158-
159-
minetest.set_node(seedling_above, {name = node.name})
160165
end
161166
end
162167

163168
minetest.register_abm({
164169
label = "Flower spread",
165170
nodenames = {"group:flora"},
166171
interval = 13,
167-
chance = 96,
172+
chance = 300,
168173
action = function(...)
169174
flowers.flower_spread(...)
170175
end,

0 commit comments

Comments
 (0)