Skip to content

Commit bd0c627

Browse files
Ekdohibsparamat
authored andcommittedJan 2, 2018
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.
1 parent d1ece74 commit bd0c627

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed
 

‎mods/default/furnace.lua

+13-6
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ local function furnace_node_timer(pos, elapsed)
118118
local fuel
119119

120120
local update = true
121-
while update do
121+
while elapsed > 0 and update do
122122
update = false
123123

124124
srclist = inv:get_list("src")
@@ -133,13 +133,18 @@ local function furnace_node_timer(pos, elapsed)
133133
cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
134134
cookable = cooked.time ~= 0
135135

136+
local el = math.min(elapsed, fuel_totaltime - fuel_time)
137+
if cookable then -- fuel lasts long enough, adjust el to cooking duration
138+
el = math.min(el, cooked.time - src_time)
139+
end
140+
136141
-- Check if we have enough fuel to burn
137142
if fuel_time < fuel_totaltime then
138143
-- The furnace is currently active and has enough fuel
139-
fuel_time = fuel_time + elapsed
144+
fuel_time = fuel_time + el
140145
-- If there is a cookable item then check if it is ready yet
141146
if cookable then
142-
src_time = src_time + elapsed
147+
src_time = src_time + el
143148
if src_time >= cooked.time then
144149
-- Place result in dst list if possible
145150
if inv:room_for_item("dst", cooked.item) then
@@ -148,6 +153,9 @@ local function furnace_node_timer(pos, elapsed)
148153
src_time = src_time - cooked.time
149154
update = true
150155
end
156+
else
157+
-- Item could not be cooked: probably missing fuel
158+
update = true
151159
end
152160
end
153161
else
@@ -165,8 +173,7 @@ local function furnace_node_timer(pos, elapsed)
165173
-- Take fuel from fuel list
166174
inv:set_stack("fuel", 1, afterfuel.items[1])
167175
update = true
168-
fuel_totaltime = fuel.time + (fuel_time - fuel_totaltime)
169-
src_time = src_time + elapsed
176+
fuel_totaltime = fuel.time + (fuel_totaltime - fuel_time)
170177
end
171178
else
172179
-- 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)
176183
fuel_time = 0
177184
end
178185

179-
elapsed = 0
186+
elapsed = elapsed - el
180187
end
181188

182189
if fuel and fuel_totaltime > fuel.time then

0 commit comments

Comments
 (0)
Please sign in to comment.