2019-01-06 13:04:07 -05:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
|
|
|
local math, minetest, nodecore
|
2019-01-06 14:51:09 -05:00
|
|
|
= math, minetest, nodecore
|
2019-01-06 13:04:07 -05:00
|
|
|
local math_random
|
2019-01-06 14:51:09 -05:00
|
|
|
= math.random
|
2019-01-06 13:04:07 -05:00
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
|
|
|
local modname = minetest.get_current_modname()
|
|
|
|
|
|
|
|
local fueltest = {groups = {fire_fuel = true}}
|
|
|
|
nodecore.register_limited_abm({
|
|
|
|
label = "Fire Requires Fuel",
|
|
|
|
interval = 1,
|
|
|
|
chance = 1,
|
|
|
|
nodenames = {modname .. ":fire"},
|
|
|
|
action = function(pos)
|
|
|
|
if not nodecore.node_is({x = pos.x, y = pos.y - 1, z = pos.z }, fueltest)
|
|
|
|
and not nodecore.node_is({x = pos.x + 1, y = pos.y, z = pos.z }, fueltest)
|
|
|
|
and not nodecore.node_is({x = pos.x - 1, y = pos.y, z = pos.z }, fueltest)
|
|
|
|
and not nodecore.node_is({x = pos.x, y = pos.y, z = pos.z + 1 }, fueltest)
|
|
|
|
and not nodecore.node_is({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
|
2019-01-06 13:04:07 -05:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
nodecore.register_limited_abm({
|
|
|
|
label = "Flammables Ignite",
|
|
|
|
interval = 5,
|
|
|
|
chance = 1,
|
|
|
|
nodenames = {"group:flammable"},
|
|
|
|
neighbors = {"group:igniter"},
|
|
|
|
action = function(pos, node)
|
|
|
|
node = node or minetest.get_node(pos)
|
|
|
|
local def = minetest.registered_nodes[node.name]
|
|
|
|
local flam = def and def.groups and def.groups.flammable
|
|
|
|
if not flam then return end
|
2019-01-06 14:51:09 -05:00
|
|
|
if def.groups.visinv then
|
|
|
|
local stack = minetest.get_meta(pos)
|
|
|
|
:get_inventory():get_stack("solo", 1)
|
|
|
|
if stack and not stack:is_empty() then
|
|
|
|
local idef = minetest.registered_items[stack:get_name()]
|
|
|
|
flam = idef and idef.groups and idef.groups.flammable
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not flam then return end
|
2019-01-06 13:04:07 -05:00
|
|
|
if math_random(1, flam) ~= 1 then return end
|
2019-01-06 14:26:27 -05:00
|
|
|
minetest.set_node(pos, {name = def.groups.burn_away
|
|
|
|
and (modname .. ":fire")
|
|
|
|
or (modname .. ":fuel")})
|
2019-01-06 13:04:07 -05:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
local function mkfire(pos, dx, dy, dz)
|
|
|
|
pos = {x = pos.x + dx, y = pos.y + dy, z = pos.z + dz}
|
2019-01-06 14:51:09 -05:00
|
|
|
if nodecore.node_is(pos, modname .. ":fire") then return true end
|
|
|
|
if nodecore.node_is(pos, "air") then
|
|
|
|
return minetest.set_node(pos, {name = modname .. ":fire"})
|
|
|
|
end
|
|
|
|
if nodecore.node_is(pos, "ignore") then return true end
|
|
|
|
if nodecore.node_is(pos, {groups = {flammable = true, burn_away = true}}) then
|
|
|
|
return minetest.set_node(pos, {name = modname .. ":fire"})
|
|
|
|
end
|
2019-01-06 13:04:07 -05:00
|
|
|
end
|
|
|
|
nodecore.register_limited_abm({
|
|
|
|
label = "Fuel Burning/Snuffing",
|
|
|
|
interval = 1,
|
|
|
|
chance = 1,
|
|
|
|
nodenames = {modname .. ":fuel"},
|
|
|
|
neighbors = {"air"},
|
|
|
|
action = function(pos)
|
|
|
|
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 not f then
|
|
|
|
return minetest.set_node(pos, {name = modname .. ":ash"})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|