Skip to content

Commit d61803b

Browse files
sofarparamat
authored andcommittedMay 28, 2016
Fire: move fire node removal out of ABM.
Because the fire nodes are not removed 100% when there are no more burnable nodes nearby, they can potentially stay around for very, very long times, leading to ABM trains every 5 seconds for no good reason (only 1 in 16 will be removed every interval). A much better method to remove fire nodes is to remove them by timer, and give removal a 100% chance if no flammable nodes are adjacent. This makes fire cleanup a lot faster and more natural, and will reduce the amount of ABM hits making fire overall more responsive. We also remove the 1 in 4 chance and fold the removal of flammable nodes into the ABM chance. There's some low hanging fruit cleanups in here as well.
1 parent e0cb3fc commit d61803b

File tree

1 file changed

+18
-38
lines changed

1 file changed

+18
-38
lines changed
 

‎mods/fire/init.lua

+18-38
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,24 @@ minetest.register_node("fire:basic_flame", {
2828
sunlight_propagates = true,
2929
damage_per_second = 4,
3030
groups = {igniter = 2, dig_immediate = 3, not_in_creative_inventory = 1},
31+
on_timer = function(pos)
32+
local f = minetest.find_node_near(pos, 1, {"group:flammable"})
33+
if not f then
34+
minetest.remove_node(pos)
35+
return
36+
end
37+
-- restart timer
38+
return true
39+
end,
3140
drop = "",
3241

3342
on_construct = function(pos)
34-
minetest.after(0, fire.on_flame_add_at, pos)
43+
minetest.get_node_timer(pos):start(math.random(30, 60))
44+
minetest.after(0, fire.update_sounds_around, pos)
3545
end,
3646

3747
on_destruct = function(pos)
38-
minetest.after(0, fire.on_flame_remove_at, pos)
48+
minetest.after(0, fire.update_sounds_around, pos)
3949
end,
4050

4151
on_blast = function()
@@ -169,32 +179,6 @@ function fire.update_sounds_around(pos)
169179
end
170180

171181

172-
-- Update fire sounds on flame node construct or destruct
173-
174-
function fire.on_flame_add_at(pos)
175-
fire.update_sounds_around(pos)
176-
end
177-
178-
179-
function fire.on_flame_remove_at(pos)
180-
fire.update_sounds_around(pos)
181-
end
182-
183-
184-
-- Return positions for flames around a burning node
185-
186-
function fire.find_pos_for_flame_around(pos)
187-
return minetest.find_node_near(pos, 1, {"air"})
188-
end
189-
190-
191-
-- Detect nearby extinguishing nodes
192-
193-
function fire.flame_should_extinguish(pos)
194-
return minetest.find_node_near(pos, 1, {"group:puts_out_fire"})
195-
end
196-
197-
198182
-- Extinguish all flames quickly with water, snow, ice
199183

200184
minetest.register_abm({
@@ -239,31 +223,27 @@ else
239223
catch_up = false,
240224
action = function(p0, node, _, _)
241225
-- If there is water or stuff like that around node, don't ignite
242-
if fire.flame_should_extinguish(p0) then
226+
if minetest.find_node_near(p0, 1, {"group:puts_out_fire"}) then
243227
return
244228
end
245-
local p = fire.find_pos_for_flame_around(p0)
229+
local p = minetest.find_node_near(p0, 1, {"air"})
246230
if p then
247231
minetest.set_node(p, {name = "fire:basic_flame"})
248232
end
249233
end,
250234
})
251235

252-
-- Remove basic flames and flammable nodes
236+
-- Remove flammable nodes
253237

254238
minetest.register_abm({
255239
nodenames = {"fire:basic_flame"},
240+
neighbors = "group:flammable",
256241
interval = 5,
257-
chance = 6,
242+
chance = 18,
258243
catch_up = false,
259244
action = function(p0, node, _, _)
260-
-- If there are no flammable nodes around flame, remove flame
261245
local p = minetest.find_node_near(p0, 1, {"group:flammable"})
262-
if not p then
263-
minetest.remove_node(p0)
264-
return
265-
end
266-
if math.random(1, 3) == 1 then
246+
if p then
267247
-- remove flammable nodes around flame
268248
local node = minetest.get_node(p)
269249
local def = minetest.registered_nodes[node.name]

0 commit comments

Comments
 (0)
Please sign in to comment.