80 lines
2.1 KiB
Lua
80 lines
2.1 KiB
Lua
fire = {}
|
|
fire.mod = "redo"
|
|
|
|
-- initial check to see if fire is disabled
|
|
local disable_fire = minetest.setting_getbool("disable_fire")
|
|
|
|
minetest.register_node("fire:basic_flame", {
|
|
description = "Fire",
|
|
drawtype = "plantlike",
|
|
tiles = {{
|
|
name="fire_basic_flame_animated.png",
|
|
animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=1},
|
|
}},
|
|
inventory_image = "fire_basic_flame.png",
|
|
light_source = 14,
|
|
groups = {igniter=2,dig_immediate=3},
|
|
drop = '',
|
|
walkable = false,
|
|
buildable_to = true,
|
|
damage_per_second = 4,
|
|
})
|
|
|
|
function fire.flame_should_extinguish(pos)
|
|
if disable_fire then return true end
|
|
local ps = minetest.find_nodes_in_area( {x=pos.x-1, y=pos.y, z=pos.z-1}, -- all 1's were 2
|
|
{x=pos.x+1, y=pos.y, z=pos.z+1},
|
|
{"group:puts_out_fire"})
|
|
return (#ps ~= 0)
|
|
end
|
|
|
|
-- Ignite neighboring nodes
|
|
minetest.register_abm({
|
|
nodenames = {"group:flammable"},
|
|
neighbors = {"group:igniter"},
|
|
interval = 5,
|
|
chance = 2,
|
|
action = function(p0, node, _, _)
|
|
-- If there is water or stuff like that around flame, don't ignite
|
|
if fire.flame_should_extinguish(p0) then return end
|
|
local p = minetest.find_node_near(p0, 1, {"air"})
|
|
if p then
|
|
minetest.set_node(p, {name="fire:basic_flame"})
|
|
end
|
|
end,
|
|
})
|
|
|
|
-- Remove flammable nodes and flame
|
|
minetest.register_abm({
|
|
nodenames = {"fire:basic_flame"},
|
|
interval = 3,
|
|
chance = 2,
|
|
action = function(p0, node, _, _)
|
|
-- check to see if fire is still disabled
|
|
disable_fire = minetest.setting_getbool("disable_fire")
|
|
|
|
-- If no flammable nodes around flame (or are extinguishers), remove flame
|
|
if not minetest.find_node_near(p0, 1, {"group:flammable"})
|
|
or fire.flame_should_extinguish(p0) then
|
|
minetest.set_node(p0, {name="air"})
|
|
return
|
|
end
|
|
|
|
if math.random(1,4) == 1 then
|
|
-- remove a flammable node around flame
|
|
local p = minetest.find_node_near(p0, 1, {"group:flammable"})
|
|
if p then
|
|
-- If there is water or stuff like that around flame, don't remove
|
|
if fire.flame_should_extinguish(p0) then
|
|
return
|
|
end
|
|
minetest.set_node(p, {name="air"})
|
|
-- nodeupdate(p)
|
|
end
|
|
else
|
|
-- remove flame
|
|
minetest.set_node(p0, {name="air"})
|
|
end
|
|
end,
|
|
})
|