mirror of
https://github.com/minetest/minetest_game.git
synced 2024-12-23 07:10:19 +01:00
Furnace: Make furnaces work when unloaded
This is slightly modified after #1279 - the setting for furnace timer was removed and hardcoded to 1.0s, which is the old furnace timer interval.
This commit is contained in:
parent
fed2151d70
commit
4a5206e3a7
@ -113,62 +113,70 @@ local function furnace_node_timer(pos, elapsed)
|
|||||||
local fuel_totaltime = meta:get_float("fuel_totaltime") or 0
|
local fuel_totaltime = meta:get_float("fuel_totaltime") or 0
|
||||||
|
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local srclist = inv:get_list("src")
|
local srclist, fuellist
|
||||||
local fuellist = inv:get_list("fuel")
|
|
||||||
|
|
||||||
--
|
local cookable, cooked
|
||||||
-- Cooking
|
|
||||||
--
|
|
||||||
|
|
||||||
-- Check if we have cookable content
|
local update = true
|
||||||
local cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
while update do
|
||||||
local cookable = true
|
update = false
|
||||||
|
|
||||||
if cooked.time == 0 then
|
srclist = inv:get_list("src")
|
||||||
cookable = false
|
fuellist = inv:get_list("fuel")
|
||||||
end
|
|
||||||
|
|
||||||
-- Check if we have enough fuel to burn
|
--
|
||||||
if fuel_time < fuel_totaltime then
|
-- Cooking
|
||||||
-- The furnace is currently active and has enough fuel
|
--
|
||||||
fuel_time = fuel_time + 1
|
|
||||||
|
|
||||||
-- If there is a cookable item then check if it is ready yet
|
-- Check if we have cookable content
|
||||||
if cookable then
|
local aftercooked
|
||||||
src_time = src_time + 1
|
cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
||||||
if src_time >= cooked.time then
|
cookable = cooked.time ~= 0
|
||||||
-- Place result in dst list if possible
|
|
||||||
if inv:room_for_item("dst", cooked.item) then
|
-- Check if we have enough fuel to burn
|
||||||
inv:add_item("dst", cooked.item)
|
if fuel_time < fuel_totaltime then
|
||||||
inv:set_stack("src", 1, aftercooked.items[1])
|
-- The furnace is currently active and has enough fuel
|
||||||
src_time = 0
|
fuel_time = fuel_time + elapsed
|
||||||
|
-- If there is a cookable item then check if it is ready yet
|
||||||
|
if cookable then
|
||||||
|
src_time = src_time + elapsed
|
||||||
|
if src_time >= cooked.time then
|
||||||
|
-- Place result in dst list if possible
|
||||||
|
if inv:room_for_item("dst", cooked.item) then
|
||||||
|
inv:add_item("dst", cooked.item)
|
||||||
|
inv:set_stack("src", 1, aftercooked.items[1])
|
||||||
|
src_time = src_time - cooked.time
|
||||||
|
update = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
else
|
|
||||||
-- Furnace ran out of fuel
|
|
||||||
if cookable then
|
|
||||||
-- We need to get new fuel
|
|
||||||
local fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
|
|
||||||
|
|
||||||
if fuel.time == 0 then
|
|
||||||
-- No valid fuel in fuel list
|
|
||||||
fuel_totaltime = 0
|
|
||||||
fuel_time = 0
|
|
||||||
src_time = 0
|
|
||||||
else
|
|
||||||
-- Take fuel from fuel list
|
|
||||||
inv:set_stack("fuel", 1, afterfuel.items[1])
|
|
||||||
|
|
||||||
fuel_totaltime = fuel.time
|
|
||||||
fuel_time = 0
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
-- We don't need to get new fuel since there is no cookable item
|
-- Furnace ran out of fuel
|
||||||
fuel_totaltime = 0
|
if cookable then
|
||||||
|
-- We need to get new fuel
|
||||||
|
local fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
|
||||||
|
|
||||||
|
if fuel.time == 0 then
|
||||||
|
-- No valid fuel in fuel list
|
||||||
|
fuel_totaltime = 0
|
||||||
|
src_time = 0
|
||||||
|
else
|
||||||
|
-- Take fuel from fuel list
|
||||||
|
inv:set_stack("fuel", 1, afterfuel.items[1])
|
||||||
|
update = true
|
||||||
|
|
||||||
|
fuel_totaltime = fuel.time + (fuel_time - fuel_totaltime)
|
||||||
|
src_time = src_time + elapsed
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- We don't need to get new fuel since there is no cookable item
|
||||||
|
fuel_totaltime = 0
|
||||||
|
src_time = 0
|
||||||
|
end
|
||||||
fuel_time = 0
|
fuel_time = 0
|
||||||
src_time = 0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
elapsed = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
@ -196,7 +204,7 @@ local function furnace_node_timer(pos, elapsed)
|
|||||||
local active = "inactive "
|
local active = "inactive "
|
||||||
local result = false
|
local result = false
|
||||||
|
|
||||||
if fuel_time <= fuel_totaltime and fuel_totaltime ~= 0 then
|
if fuel_totaltime ~= 0 then
|
||||||
active = "active "
|
active = "active "
|
||||||
local fuel_percent = math.floor(fuel_time / fuel_totaltime * 100)
|
local fuel_percent = math.floor(fuel_time / fuel_totaltime * 100)
|
||||||
fuel_state = fuel_percent .. "%"
|
fuel_state = fuel_percent .. "%"
|
||||||
@ -210,8 +218,7 @@ local function furnace_node_timer(pos, elapsed)
|
|||||||
end
|
end
|
||||||
swap_node(pos, "default:furnace")
|
swap_node(pos, "default:furnace")
|
||||||
-- stop timer on the inactive furnace
|
-- stop timer on the inactive furnace
|
||||||
local timer = minetest.get_node_timer(pos)
|
minetest.get_node_timer(pos):stop()
|
||||||
timer:stop()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local infotext = "Furnace " .. active .. "(Item: " .. item_state .. "; Fuel: " .. fuel_state .. ")"
|
local infotext = "Furnace " .. active .. "(Item: " .. item_state .. "; Fuel: " .. fuel_state .. ")"
|
||||||
@ -259,13 +266,11 @@ minetest.register_node("default:furnace", {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
on_metadata_inventory_move = function(pos)
|
on_metadata_inventory_move = function(pos)
|
||||||
local timer = minetest.get_node_timer(pos)
|
minetest.get_node_timer(pos):start(1.0)
|
||||||
timer:start(1.0)
|
|
||||||
end,
|
end,
|
||||||
on_metadata_inventory_put = function(pos)
|
on_metadata_inventory_put = function(pos)
|
||||||
-- start timer function, it will sort out whether furnace can burn or not.
|
-- start timer function, it will sort out whether furnace can burn or not.
|
||||||
local timer = minetest.get_node_timer(pos)
|
minetest.get_node_timer(pos):start(1.0)
|
||||||
timer:start(1.0)
|
|
||||||
end,
|
end,
|
||||||
on_blast = function(pos)
|
on_blast = function(pos)
|
||||||
local drops = {}
|
local drops = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user