Subtract fuel time after adding source time in Iron Furnace

Fixes #17
This commit is contained in:
mrkubax10 2024-05-10 17:05:31 +02:00 committed by Handful of Frogs
parent b3f890e339
commit 8fe44e76ae

View File

@ -155,11 +155,6 @@ ironFurnace.activeOnTimer=function(pos,elapsed)
meta:set_float("maxSrcTime",output.time*0.7)
end
end
if meta:get_float("fuelTime")>0 then
meta:set_float("fuelTime",meta:get_float("fuelTime")-elapsed)
shouldUpdateFormspec=true
shouldRerunTimer=true
end
if meta:get_float("maxSrcTime")>0 then
if meta:get_float("fuelTime")>0 then
meta:set_float("srcTime",meta:get_float("srcTime")+elapsed)
@ -180,6 +175,11 @@ ironFurnace.activeOnTimer=function(pos,elapsed)
})
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
end
if meta:get_float("fuelTime")>0 then
meta:set_float("fuelTime",meta:get_float("fuelTime")-elapsed)
shouldUpdateFormspec=true
shouldRerunTimer=true
end
if meta:get_float("srcTime")>=meta:get_float("maxSrcTime") then
local output,after=minetest.get_craft_result({
method="cooking",
@ -223,6 +223,23 @@ ironFurnace.allowMetadataInventoryPut=function(pos,listname,index,stack)
return stack:get_count()
end
ironFurnace.allowMetadataInventoryTake=function(pos,listname,index,stack)
local meta=minetest.get_meta(pos)
local inv=meta:get_inventory()
local srcSlot=inv:get_stack("src",1)
local dstSlot=inv:get_stack("dst",1)
if listname=="src" and stack:get_count()==srcSlot:get_count() then
meta:set_float("srcTime",-1)
meta:set_float("maxSrcTime",0)
if meta:get_float("maxFuelTime")>0 then
meta:set_string("formspec",ironFurnace.getFormspec(meta:get_float("fuelTime")/meta:get_float("maxFuelTime")*100,0))
end
elseif listname=="dst" and dstSlot:get_free_space()==0 then
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
end
return stack:get_count()
end
ironFurnace.onMetadataInventoryMove=function(pos,fromList,fromIndex,toList,toIndex,count)
local meta=minetest.get_meta(pos)
local inv=meta:get_inventory()
@ -243,22 +260,6 @@ ironFurnace.onMetadataInventoryPut=function(pos,listname,index,stack)
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
end
ironFurnace.onMetadataInventoryTake=function(pos,listname,index,stack)
local meta=minetest.get_meta(pos)
local inv=meta:get_inventory()
local srcSlot=inv:get_stack("src",1)
local dstSlot=inv:get_stack("dst",1)
if listname=="src" and stack:get_count()==srcSlot:get_count() then
meta:set_float("srcTime",-1)
meta:set_float("maxSrcTime",0)
if meta:get_float("maxFuelTime")>0 then
meta:set_string("formspec",ironFurnace.getFormspec(meta:get_float("fuelTime")/meta:get_float("maxFuelTime")*100,0))
end
elseif listname=="dst" and dstSlot:get_free_space()==0 then
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
end
end
local definition={
description=S("Iron Furnace"),
tiles={
@ -276,9 +277,9 @@ local definition={
on_timer=ironFurnace.onTimer,
allow_metadata_inventory_move=ironFurnace.allowMetadataInventoryMove,
allow_metadata_inventory_put=ironFurnace.allowMetadataInventoryPut,
allow_metadata_inventory_take=ironFurnace.allowMetadataInventoryTake,
on_metadata_inventory_move=ironFurnace.onMetadataInventoryMove,
on_metadata_inventory_put=ironFurnace.onMetadataInventoryPut,
on_metadata_inventory_take=ironFurnace.onMetadataInventoryTake
on_metadata_inventory_put=ironFurnace.onMetadataInventoryPut
}
if industrialtest.mtgAvailable then
definition.groups={