Compare commits

...

2 Commits

Author SHA1 Message Date
Valentin Anger 7fcf0a6feb Keep updating while the furnace is low on energy and has educts 2018-09-21 00:44:47 +02:00
Valentin Anger 0a229de58e Correctly verify the availability of energy in furnaces
The check previously checked for a non zero energy value.
This works when the value only ever decreases by one,
which forces the value to reach zero via reduction.
With the addition of a modifier for cooking cost this breaks down.

This bug was introduced due to the addition of a modifier which
controls the running cost.
2018-09-21 00:39:48 +02:00
1 changed files with 24 additions and 25 deletions

View File

@ -37,7 +37,7 @@ end
local function ongetitem(pos)
local meta = minetest.get_meta(pos)
if meta:get_int("energy") == 0 then return end
if meta:get_int("energy") < modifier then return end
local timer = minetest.get_node_timer(pos)
timer:start(1.0)
end
@ -74,39 +74,38 @@ local function mytime(pos, elapsed)
local inventory = meta:get_inventory()
local source = inventory:get_list("source")
local product = inventory:get_list("product")
local counter = 0
local newcycle = true -- set to false if not new cycle is required
for item=1,2 do
if energy == 0 then return end --if no energy is available return, rest of the function doesnt matter
local cooked
local aftercooked
local progress = meta:get_int("progress_" .. item)
cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = {inventory:get_stack("source", item)}})
--source and product assigned
if progress >= math.ceil(cooked.time * time_modifier) then
if inventory:room_for_item("product", cooked.item) then
inventory:add_item("product", cooked.item)
inventory:set_stack("source", item, aftercooked.items[1])
meta:set_int("progress_" .. item, 0)
if energy >= modifier then
local cooked
local aftercooked
local progress = meta:get_int("progress_" .. item)
cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = {inventory:get_stack("source", item)}})
--source and product assigned
if progress >= math.ceil(cooked.time * time_modifier) then
if inventory:room_for_item("product", cooked.item) then
inventory:add_item("product", cooked.item)
inventory:set_stack("source", item, aftercooked.items[1])
meta:set_int("progress_" .. item, 0)
end
else
counter = counter +1
meta:set_int("progress_" .. item, progress + 1)
energy = energy - modifier
end
else
meta:set_int("progress_" .. item, progress + 1)
energy = energy - 1 * modifier
meta:set_int("energy", energy)
-- minetest.debug(dump(pos) .. " : " .. dump(item))
end
-- minetest.debug(dump(pos) .. " : " .. dump(item))
end
meta:set_int("energy", energy)
update_formspec(pos) -- Later this should only be done when a player looks into the block
if counter == 2 then
newcycle = false -- this meens that both finished cooking and the other inventory is full
end
--TODO: for the formspec code, if it is marked as active update it here
if (newcycle) then
local has_items = false -- Keep updating if there are still items
for _, e in pairs(meta:get_inventory():get_list("source")) do
has_items = has_items or not e:is_empty()
end
if has_items then
minetest.get_node_timer(pos):start(1.0) -- it was determined that a new cycle is required, this is the case if energy and material to cook is available
end
return