Make furnaces burn items even when they are unloaded

This commit is contained in:
Novatux 2013-09-29 12:36:51 +02:00
parent a4823a4261
commit 453449742e

View file

@ -918,25 +918,8 @@ function hacky_swap_node(pos,name)
meta:from_table(meta0) meta:from_table(meta0)
end end
minetest.register_abm({ function default.furnace_step(pos, node, meta)
nodenames = {"default:furnace","default:furnace_active"},
interval = 1.0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
for i, name in ipairs({
"fuel_totaltime",
"fuel_time",
"src_totaltime",
"src_time"
}) do
if meta:get_string(name) == "" then
meta:set_float(name, 0.0)
end
end
local inv = meta:get_inventory() local inv = meta:get_inventory()
local srclist = inv:get_list("src") local srclist = inv:get_list("src")
local cooked = nil local cooked = nil
local aftercooked local aftercooked
@ -969,11 +952,10 @@ minetest.register_abm({
local percent = math.floor(meta:get_float("fuel_time") / local percent = math.floor(meta:get_float("fuel_time") /
meta:get_float("fuel_totaltime") * 100) meta:get_float("fuel_totaltime") * 100)
meta:set_string("infotext","Furnace active: "..percent.."%") meta:set_string("infotext","Furnace active: "..percent.."%")
hacky_swap_node(pos,"default:furnace_active") node.name = "default:furnace_active"
meta:set_string("formspec",default.get_furnace_active_formspec(pos, percent)) meta:set_string("formspec",default.get_furnace_active_formspec(pos, percent))
return return
end end
local fuel = nil local fuel = nil
local afterfuel local afterfuel
local cooked = nil local cooked = nil
@ -986,27 +968,51 @@ minetest.register_abm({
if fuellist then if fuellist then
fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist}) fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
end end
if fuel.time <= 0 then if fuel.time <= 0 then
meta:set_string("infotext","Furnace out of fuel") meta:set_string("infotext","Furnace out of fuel")
hacky_swap_node(pos,"default:furnace") node.name = "default:furnace"
meta:set_string("formspec", default.furnace_inactive_formspec) meta:set_string("formspec", default.furnace_inactive_formspec)
return return
end end
if cooked.item:is_empty() then if cooked.item:is_empty() then
if was_active then if was_active then
meta:set_string("infotext","Furnace is empty") meta:set_string("infotext","Furnace is empty")
hacky_swap_node(pos,"default:furnace") node.name = "default:furnace"
meta:set_string("formspec", default.furnace_inactive_formspec) meta:set_string("formspec", default.furnace_inactive_formspec)
end end
return return
end end
meta:set_string("fuel_totaltime", fuel.time) meta:set_string("fuel_totaltime", fuel.time)
meta:set_string("fuel_time", 0) meta:set_string("fuel_time", 0)
inv:set_stack("fuel", 1, afterfuel.items[1]) inv:set_stack("fuel", 1, afterfuel.items[1])
end
minetest.register_abm({
nodenames = {"default:furnace","default:furnace_active"},
interval = 1.0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
for i, name in ipairs({
"fuel_totaltime",
"fuel_time",
"src_totaltime",
"src_time"
}) do
if meta:get_string(name) == "" then
meta:set_float(name, 0.0)
end
end
local gt = minetest.get_gametime()
if meta:get_string("game_time") == "" then
meta:set_int("game_time", gt-1)
end
for i = 1, math.min(1200, gt-meta:get_int("game_time")) do
default.furnace_step(pos, node, meta)
end
hacky_swap_node(pos, node.name)
meta:set_int("game_time", gt)
end, end,
}) })