From 868d01b00827a27ab79671c77eb851863081ad2b Mon Sep 17 00:00:00 2001 From: mrkubax10 Date: Fri, 10 May 2024 17:05:31 +0200 Subject: [PATCH] Subtract fuel time after adding source time in Iron Furnace Fixes #17 --- machines/iron_furnace.lua | 47 ++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/machines/iron_furnace.lua b/machines/iron_furnace.lua index f21a7dc..1acdd17 100644 --- a/machines/iron_furnace.lua +++ b/machines/iron_furnace.lua @@ -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={