89 lines
2.8 KiB
Lua
Raw Normal View History

-- LUALOCALS < ---------------------------------------------------------
local math, minetest, nodecore
= math, minetest, nodecore
local math_pow, math_random
= math.pow, math.random
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
local fueltest = {groups = {ember = true}}
nodecore.register_limited_abm({
label = "Fire Requires Embers",
interval = 1,
chance = 1,
nodenames = {modname .. ":fire"},
action = function(pos)
2019-02-03 12:44:33 -05:00
if not nodecore.match({x = pos.x, y = pos.y - 1, z = pos.z }, fueltest)
and not nodecore.match({x = pos.x + 1, y = pos.y, z = pos.z }, fueltest)
and not nodecore.match({x = pos.x - 1, y = pos.y, z = pos.z }, fueltest)
and not nodecore.match({x = pos.x, y = pos.y, z = pos.z + 1 }, fueltest)
and not nodecore.match({x = pos.x, y = pos.y, z = pos.z - 1 }, fueltest)
2019-01-06 14:26:27 -05:00
then return minetest.remove_node(pos) end
end
})
2019-01-23 23:06:06 -05:00
local function mkfire(pos, dx, dy, dz, testonly)
pos = {x = pos.x + dx, y = pos.y + dy, z = pos.z + dz}
2019-02-03 12:44:33 -05:00
if nodecore.match(pos, modname .. ":fire") then return true end
if nodecore.match(pos, "air") then
2019-01-23 23:06:06 -05:00
return testonly or minetest.set_node(pos, {name = modname .. ":fire"})
end
2019-02-03 12:44:33 -05:00
if nodecore.match(pos, "ignore") then return true end
if nodecore.match(pos, {groups = {flammable = true, fire_fuel = false}}) then
2019-01-23 23:06:06 -05:00
return testonly or minetest.set_node(pos, {name = modname .. ":fire"})
end
end
nodecore.register_limited_abm({
label = "Flammables Ignite",
interval = 5,
chance = 1,
nodenames = {"group:flammable"},
neighbors = {"group:igniter"},
action = function(pos, node)
2019-01-23 23:06:06 -05:00
-- Cannot be wet.
if nodecore.quenched(pos) then return end
2019-01-23 23:06:06 -05:00
-- Must have oxygen supply.
if not mkfire(pos, 0, 1, 0, true)
and not mkfire(pos, 1, 0, 0, true)
and not mkfire(pos, -1, 0, 0, true)
and not mkfire(pos, 0, 0, 1, true)
and not mkfire(pos, 0, 0, -1, true)
then return end
-- Get flammability level.
node = node or minetest.get_node(pos)
local def = minetest.registered_items[node.name] or {}
local flam = def.groups and def.groups.flammable
if not flam then return end
2019-01-23 23:06:06 -05:00
-- Ignite randomly.
if math_random(1, flam) ~= 1 then return end
nodecore.ignite(pos, node)
end
})
nodecore.register_limited_abm({
label = "Fuel Burning/Snuffing",
interval = 1,
chance = 1,
nodenames = {"group:ember"},
action = function(pos, node)
if nodecore.quenched(pos) then
2019-01-23 23:06:06 -05:00
return nodecore.snuff(pos, node)
end
local f = mkfire(pos, 0, 1, 0)
f = mkfire(pos, 1, 0, 0) or f
f = mkfire(pos, -1, 0, 0) or f
f = mkfire(pos, 0, 0, 1) or f
f = mkfire(pos, 0, 0, -1) or f
if math_random(1, math_pow(2,
nodecore.node_group("ember", pos, node)
+ (f and 4 or 0))) == 1 then
return nodecore.snuff(pos, node)
end
end
})