Skip to content

Commit acb0cec

Browse files
committedSep 4, 2015
Fire: Move flame extinguishing to separate faster ABM
Add extinguish sounds (from default mod lavacooling) 'disable fire' setting extinguishes fire quickly using a dedicated ABM 'disable fire' also disables all other ABMs Simplify flammable node removal ABM Speed up node ignition, it was too slow Add 'sunlight propagates = true' and 'paramtype = "light" to flame Balance fire sounds' gain
1 parent c2307b8 commit acb0cec

File tree

4 files changed

+86
-76
lines changed

4 files changed

+86
-76
lines changed
 

Diff for: ‎mods/fire/init.lua

+86-76
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ minetest.register_node("fire:basic_flame", {
1616
aspect_w = 16, aspect_h = 16, length = 1},
1717
}},
1818
inventory_image = "fire_basic_flame.png",
19+
paramtype = "light",
1920
light_source = 14,
2021
groups = {igniter = 2, dig_immediate = 3},
2122
drop = '',
2223
walkable = false,
2324
buildable_to = true,
25+
sunlight_propagates = true,
2426
damage_per_second = 4,
2527

2628
on_construct = function(pos)
@@ -31,21 +33,13 @@ minetest.register_node("fire:basic_flame", {
3133
minetest.after(0, fire.on_flame_remove_at, pos)
3234
end,
3335

34-
-- unaffected by explosions
35-
on_blast = function() end,
36+
on_blast = function() end, -- unaffected by explosions
3637
})
3738

3839

39-
-- Fire sounds table
40-
-- key: position hash of low corner of area
41-
-- value: {handle=sound handle, name=sound name}
42-
fire.sounds = {}
43-
44-
4540
-- Get sound area of position
4641

47-
-- size of sound areas
48-
fire.D = 6
42+
fire.D = 6 -- size of sound areas
4943

5044
function fire.get_area_p0p1(pos)
5145
local p0 = {
@@ -62,6 +56,12 @@ function fire.get_area_p0p1(pos)
6256
end
6357

6458

59+
-- Fire sounds table
60+
-- key: position hash of low corner of area
61+
-- value: {handle=sound handle, name=sound name}
62+
fire.sounds = {}
63+
64+
6565
-- Update fire sounds in sound area of position
6666

6767
function fire.update_sounds_around(pos)
@@ -73,9 +73,9 @@ function fire.update_sounds_around(pos)
7373
local should_have_sound = (#flames_p > 0)
7474
local wanted_sound = nil
7575
if #flames_p >= 9 then
76-
wanted_sound = {name = "fire_large", gain = 1.5}
76+
wanted_sound = {name = "fire_large", gain = 0.7}
7777
elseif #flames_p > 0 then
78-
wanted_sound = {name = "fire_small", gain = 1.5}
78+
wanted_sound = {name = "fire_small", gain = 0.9}
7979
end
8080
local p0_hash = minetest.hash_node_position(p0)
8181
local sound = fire.sounds[p0_hash]
@@ -125,33 +125,84 @@ end
125125
-- Detect nearby extinguishing nodes
126126

127127
function fire.flame_should_extinguish(pos)
128-
if minetest.setting_getbool("disable_fire") then return true end
129-
--return minetest.find_node_near(pos, 1, {"group:puts_out_fire"})
130-
local p0 = {x = pos.x - 1, y = pos.y, z = pos.z - 1}
131-
local p1 = {x = pos.x + 1, y = pos.y + 1, z = pos.z + 1}
132-
local ps = minetest.find_nodes_in_area(p0, p1, {"group:puts_out_fire"})
133-
return (#ps ~= 0)
128+
return minetest.find_node_near(pos, 1, {"group:puts_out_fire"})
134129
end
135130

136131

137-
-- Ignite neighboring nodes
132+
-- Enable ABMs according to 'disable fire' setting
138133

139-
minetest.register_abm({
140-
nodenames = {"group:flammable"},
141-
neighbors = {"group:igniter"},
142-
interval = 7,
143-
chance = 32,
144-
action = function(p0, node, _, _)
145-
-- If there is water or stuff like that around flame, don't ignite
146-
if fire.flame_should_extinguish(p0) then
147-
return
148-
end
149-
local p = fire.find_pos_for_flame_around(p0)
150-
if p then
151-
minetest.set_node(p, {name = "fire:basic_flame"})
152-
end
153-
end,
154-
})
134+
if minetest.setting_getbool("disable_fire") then
135+
136+
-- Extinguish flames quickly with dedicated ABM
137+
138+
minetest.register_abm({
139+
nodenames = {"fire:basic_flame"},
140+
interval = 3,
141+
chance = 2,
142+
action = function(p0, node, _, _)
143+
minetest.remove_node(p0)
144+
end,
145+
})
146+
147+
else
148+
149+
-- Extinguish flames quickly with water, snow, ice
150+
151+
minetest.register_abm({
152+
nodenames = {"fire:basic_flame"},
153+
neighbors = {"group:puts_out_fire"},
154+
interval = 3,
155+
chance = 2,
156+
action = function(p0, node, _, _)
157+
minetest.remove_node(p0)
158+
minetest.sound_play("fire_extinguish_flame",
159+
{pos = p0, max_hear_distance = 16, gain = 0.25})
160+
end,
161+
})
162+
163+
-- Ignite neighboring nodes
164+
165+
minetest.register_abm({
166+
nodenames = {"group:flammable"},
167+
neighbors = {"group:igniter"},
168+
interval = 7,
169+
chance = 16,
170+
action = function(p0, node, _, _)
171+
-- If there is water or stuff like that around node, don't ignite
172+
if fire.flame_should_extinguish(p0) then
173+
return
174+
end
175+
local p = fire.find_pos_for_flame_around(p0)
176+
if p then
177+
minetest.set_node(p, {name = "fire:basic_flame"})
178+
end
179+
end,
180+
})
181+
182+
-- Remove flames and flammable nodes
183+
184+
minetest.register_abm({
185+
nodenames = {"fire:basic_flame"},
186+
interval = 5,
187+
chance = 16,
188+
action = function(p0, node, _, _)
189+
-- If there are no flammable nodes around flame, remove flame
190+
if not minetest.find_node_near(p0, 1, {"group:flammable"}) then
191+
minetest.remove_node(p0)
192+
return
193+
end
194+
if math.random(1, 4) == 1 then
195+
-- remove flammable nodes around flame
196+
local p = minetest.find_node_near(p0, 1, {"group:flammable"})
197+
if p then
198+
minetest.remove_node(p)
199+
nodeupdate(p)
200+
end
201+
end
202+
end,
203+
})
204+
205+
end
155206

156207

157208
-- Rarely ignite things from far
@@ -184,44 +235,3 @@ minetest.register_abm({
184235
end,
185236
})
186237
--]]
187-
188-
189-
-- Remove flammable nodes and flame
190-
191-
minetest.register_abm({
192-
nodenames = {"fire:basic_flame"},
193-
interval = 5,
194-
chance = 16,
195-
action = function(p0, node, _, _)
196-
-- If there is water or stuff like that around flame, remove flame
197-
if fire.flame_should_extinguish(p0) then
198-
minetest.remove_node(p0)
199-
return
200-
end
201-
-- Make the following things rarer
202-
if math.random(1, 3) == 1 then
203-
return
204-
end
205-
-- If there are no flammable nodes around flame, remove flame
206-
if not minetest.find_node_near(p0, 1, {"group:flammable"}) then
207-
minetest.remove_node(p0)
208-
return
209-
end
210-
if math.random(1, 4) == 1 then
211-
-- remove a flammable node around flame
212-
local p = minetest.find_node_near(p0, 1, {"group:flammable"})
213-
if p then
214-
-- If there is water or stuff like that around flame, don't remove
215-
if fire.flame_should_extinguish(p0) then
216-
return
217-
end
218-
minetest.remove_node(p)
219-
nodeupdate(p)
220-
end
221-
else
222-
-- remove flame
223-
minetest.remove_node(p0)
224-
end
225-
end,
226-
})
227-

Diff for: ‎mods/fire/sounds/fire_extinguish_flame.1.ogg

9.36 KB
Binary file not shown.

Diff for: ‎mods/fire/sounds/fire_extinguish_flame.2.ogg

7.79 KB
Binary file not shown.

Diff for: ‎mods/fire/sounds/fire_extinguish_flame.3.ogg

6.35 KB
Binary file not shown.

0 commit comments

Comments
 (0)