Machine softlocks fixes

This commit is contained in:
mrkubax10 2023-03-26 18:41:14 +02:00
parent 6fbaaa68e4
commit 9db6ea9ced

View File

@ -490,12 +490,15 @@ local function registerSimpleElectricItemProcessor(config)
local meta=minetest.get_meta(pos) local meta=minetest.get_meta(pos)
local inv=meta:get_inventory() local inv=meta:get_inventory()
local srcSlot=inv:get_stack("src",1) local srcSlot=inv:get_stack("src",1)
local dstSlot=inv:get_stack("dst",1)
if fromList=="src" and count==srcSlot:get_count() then if fromList=="src" and count==srcSlot:get_count() then
meta:set_float("srcTime",-1) meta:set_float("srcTime",-1)
meta:set_float("maxSrcTime",0) meta:set_float("maxSrcTime",0)
if meta:get_int("industrialtest.powerAmount")>0 then if meta:get_int("industrialtest.powerAmount")>0 then
meta:set_string("formspec",getFormspec(meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*100,meta:get_float("srcTime")/meta:get_float("maxSrcTime")*100)) meta:set_string("formspec",getFormspec(meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*100,meta:get_float("srcTime")/meta:get_float("maxSrcTime")*100))
end end
elseif fromList=="dst" and dstSlot:get_free_space()==0 then
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
end end
end, end,
on_metadata_inventory_put=function(pos,listname) on_metadata_inventory_put=function(pos,listname)
@ -507,16 +510,24 @@ local function registerSimpleElectricItemProcessor(config)
local meta=minetest.get_meta(pos) local meta=minetest.get_meta(pos)
local inv=meta:get_inventory() local inv=meta:get_inventory()
local srcSlot=inv:get_stack("src",1) 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 if listname=="src" and stack:get_count()==srcSlot:get_count() then
meta:set_float("srcTime",-1) meta:set_float("srcTime",-1)
meta:set_float("maxSrcTime",0) meta:set_float("maxSrcTime",0)
if meta:get_int("industrialtest.powerAmount")>0 then if meta:get_int("industrialtest.powerAmount")>0 then
meta:set_string("formspec",getFormspec(meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*100,meta:get_float("srcTime")/meta:get_float("maxSrcTime")*100)) meta:set_string("formspec",getFormspec(meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*100,meta:get_float("srcTime")/meta:get_float("maxSrcTime")*100))
end end
elseif listname=="dst" and dstSlot:get_free_space()==0 then
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
end end
end, end,
_industrialtest_updateFormspec=function(meta) _industrialtest_updateFormspec=function(meta)
meta:set_string("formspec",getFormspec(meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*100,meta:get_float("srcTime")/meta:get_float("maxSrcTime")*100)) meta:set_string("formspec",getFormspec(meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*100,meta:get_float("srcTime")/meta:get_float("maxSrcTime")*100))
end,
_industrialtest_onPowerFlow=function(pos)
-- FIXME: this probably will require refactor so node timer won't be started
-- just to test if machine can process item
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
end end
} }
if industrialtest.mtgAvailable then if industrialtest.mtgAvailable then
@ -757,12 +768,15 @@ definition={
local meta=minetest.get_meta(pos) local meta=minetest.get_meta(pos)
local inv=meta:get_inventory() local inv=meta:get_inventory()
local srcSlot=inv:get_stack("src",1) local srcSlot=inv:get_stack("src",1)
local dstSlot=inv:get_stack("dst",1)
if fromList=="src" and count==srcSlot:get_count() then if fromList=="src" and count==srcSlot:get_count() then
meta:set_float("srcTime",-1) meta:set_float("srcTime",-1)
meta:set_float("maxSrcTime",0) meta:set_float("maxSrcTime",0)
if meta:get_float("maxFuelTime")>0 then if meta:get_float("maxFuelTime")>0 then
meta:set_string("formspec",ironFurnaceFormspec(meta:get_float("fuelTime")/meta:get_float("maxFuelTime")*100,0)) meta:set_string("formspec",ironFurnaceFormspec(meta:get_float("fuelTime")/meta:get_float("maxFuelTime")*100,0))
end end
elseif fromList=="dst" and dstSlot:get_free_space()==0 then
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
end end
end, end,
on_metadata_inventory_put=function(pos,listname,index,stack) on_metadata_inventory_put=function(pos,listname,index,stack)
@ -772,12 +786,15 @@ definition={
local meta=minetest.get_meta(pos) local meta=minetest.get_meta(pos)
local inv=meta:get_inventory() local inv=meta:get_inventory()
local srcSlot=inv:get_stack("src",1) 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 if listname=="src" and stack:get_count()==srcSlot:get_count() then
meta:set_float("srcTime",-1) meta:set_float("srcTime",-1)
meta:set_float("maxSrcTime",0) meta:set_float("maxSrcTime",0)
if meta:get_float("maxFuelTime")>0 then if meta:get_float("maxFuelTime")>0 then
meta:set_string("formspec",ironFurnaceFormspec(meta:get_float("fuelTime")/meta:get_float("maxFuelTime")*100,0)) meta:set_string("formspec",ironFurnaceFormspec(meta:get_float("fuelTime")/meta:get_float("maxFuelTime")*100,0))
end end
elseif listname=="dst" and dstSlot:get_free_space()==0 then
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
end end
end end
} }