Furnace: Fix being able to cook items without enough fuel

This was triggered when too much time had elapsed when timer was called.
Also, fix timer resolution giving free fuel time.
This commit is contained in:
Ekdohibs 2017-12-21 10:28:06 +01:00 committed by paramat
parent d1ece74652
commit bd0c627a20

View File

@ -118,7 +118,7 @@ local function furnace_node_timer(pos, elapsed)
local fuel local fuel
local update = true local update = true
while update do while elapsed > 0 and update do
update = false update = false
srclist = inv:get_list("src") srclist = inv:get_list("src")
@ -133,13 +133,18 @@ local function furnace_node_timer(pos, elapsed)
cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
cookable = cooked.time ~= 0 cookable = cooked.time ~= 0
local el = math.min(elapsed, fuel_totaltime - fuel_time)
if cookable then -- fuel lasts long enough, adjust el to cooking duration
el = math.min(el, cooked.time - src_time)
end
-- Check if we have enough fuel to burn -- Check if we have enough fuel to burn
if fuel_time < fuel_totaltime then if fuel_time < fuel_totaltime then
-- The furnace is currently active and has enough fuel -- The furnace is currently active and has enough fuel
fuel_time = fuel_time + elapsed fuel_time = fuel_time + el
-- If there is a cookable item then check if it is ready yet -- If there is a cookable item then check if it is ready yet
if cookable then if cookable then
src_time = src_time + elapsed src_time = src_time + el
if src_time >= cooked.time then if src_time >= cooked.time then
-- Place result in dst list if possible -- Place result in dst list if possible
if inv:room_for_item("dst", cooked.item) then if inv:room_for_item("dst", cooked.item) then
@ -148,6 +153,9 @@ local function furnace_node_timer(pos, elapsed)
src_time = src_time - cooked.time src_time = src_time - cooked.time
update = true update = true
end end
else
-- Item could not be cooked: probably missing fuel
update = true
end end
end end
else else
@ -165,8 +173,7 @@ local function furnace_node_timer(pos, elapsed)
-- Take fuel from fuel list -- Take fuel from fuel list
inv:set_stack("fuel", 1, afterfuel.items[1]) inv:set_stack("fuel", 1, afterfuel.items[1])
update = true update = true
fuel_totaltime = fuel.time + (fuel_time - fuel_totaltime) fuel_totaltime = fuel.time + (fuel_totaltime - fuel_time)
src_time = src_time + elapsed
end end
else else
-- We don't need to get new fuel since there is no cookable item -- We don't need to get new fuel since there is no cookable item
@ -176,7 +183,7 @@ local function furnace_node_timer(pos, elapsed)
fuel_time = 0 fuel_time = 0
end end
elapsed = 0 elapsed = elapsed - el
end end
if fuel and fuel_totaltime > fuel.time then if fuel and fuel_totaltime > fuel.time then