Fix some machines locking sometimes

This commit is contained in:
2023-11-15 21:44:02 +01:00
parent 659e8ad5ed
commit 8724b563c4
7 changed files with 46 additions and 56 deletions

View File

@@ -17,13 +17,13 @@
local S=minetest.get_translator("industrialtest")
local fluidGenerator={}
fluidGenerator.getFormspec=function(pos,getFuel)
fluidGenerator.getFormspec=function(pos,config)
local meta=minetest.get_meta(pos)
local fluidPercent=meta:get_float("fluidAmount")/100
local powerPercent=meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")
local fluid=meta:get_string("fluid")
local formspec
local fuel=getFuel(fluid)
local fuel=config.getFuel(fluid)
local tile=(fuel and fuel.texture or "industrialtest_gui_fluid_bg.png")
if industrialtest.mtgAvailable then
formspec={
@@ -64,14 +64,14 @@ fluidGenerator.onConstruct=function(pos,meta,inv)
meta:set_string("fluid","")
end
fluidGenerator.onTimer=function(pos,elapsed,meta,inv,getFuel,getFuelByItem)
fluidGenerator.onTimer=function(pos,elapsed,meta,inv,config)
local fluidSlot=inv:get_stack("fluid",1)
local chargedSlot=inv:get_stack("charged",1)
local afterFlow,flowTransferred=industrialtest.api.powerFlow(pos)
local shouldUpdateFormspec=false
local shouldRerunTimer=(afterFlow and meta:get_int("industrialtest.powerAmount")>0)
if fluidSlot:get_count()>0 and meta:get_float("fluidAmount")<=9000 then
local fuel=getFuelByItem(fluidSlot:get_name())
local fuel=config.getFuelByItem(fluidSlot:get_name())
if fuel and (fuel.name==meta:get_string("fluid") or meta:get_string("fluid")=="") then
local leftover=false
local leftoverAddingSucceeded=false
@@ -96,7 +96,7 @@ fluidGenerator.onTimer=function(pos,elapsed,meta,inv,getFuel,getFuelByItem)
end
if meta:get_float("fluidAmount")>=50 and not industrialtest.api.isFullyCharged(meta) then
meta:set_float("fluidAmount",meta:get_int("fluidAmount")-50*elapsed)
local toAdd=math.ceil(getFuel(meta:get_string("fluid")).calorificValue*elapsed)
local toAdd=math.ceil(config.getFuel(meta:get_string("fluid")).calorificValue*elapsed)
industrialtest.api.addPower(meta,toAdd)
shouldUpdateFormspec=true
if config.registerActiveVariant then
@@ -126,7 +126,7 @@ fluidGenerator.metadataChange=function(pos)
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
end
fluidGenerator.activeOnTimer=function(pos,elapsed,meta,inv,getFuelByItem)
fluidGenerator.activeOnTimer=function(pos,elapsed,meta,inv,config)
local fluidSlot=inv:get_stack("fluid",1)
local chargedSlot=inv:get_stack("charged",1)
local afterFlow,flowTransferred=industrialtest.api.powerFlow(pos)
@@ -134,7 +134,7 @@ fluidGenerator.activeOnTimer=function(pos,elapsed,meta,inv,getFuelByItem)
local shouldRerunTimer=(afterFlow and meta:get_int("industrialtest.powerAmount")>0)
if fluidSlot:get_count()>0 and meta:get_float("fluidAmount")<=9000 then
local fuel=getFuelByItem(fluidSlot:get_name())
local fuel=config.getFuelByItem(fluidSlot:get_name())
if fuel and (fuel.name==meta:get_string("fluid") or meta:get_string("fluid")=="") then
local leftover=false
local leftoverAddingSucceeded=false
@@ -152,7 +152,6 @@ fluidGenerator.activeOnTimer=function(pos,elapsed,meta,inv,getFuelByItem)
inv:set_stack("fluid",1,fluidSlot)
meta:set_string("fluid",fuel.name)
meta:set_float("fluidAmount",meta:get_float("fluidAmount")+1000)
minetest.chat_send_all(meta:get_float("fluidAmount"))
shouldUpdateFormspec=true
shouldRerunTimer=false
end
@@ -166,8 +165,8 @@ fluidGenerator.activeOnTimer=function(pos,elapsed,meta,inv,getFuelByItem)
shouldRerunTimer=true
else
minetest.swap_node(pos,{
name="industrialtest:"..config.name,
param2=minetest.get_node(pos).param2
name="industrialtest:"..config.name,
param2=minetest.get_node(pos).param2
})
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
end
@@ -189,7 +188,7 @@ local function registerFluidGenerator(config)
name=config.name,
displayName=config.displayName,
getFormspec=function(pos)
return fluidGenerator.getFormspec(pos,config.getFuel)
return fluidGenerator.getFormspec(pos,config)
end,
capacity=7000,
flow=industrialtest.api.lvPowerFlow,
@@ -216,7 +215,7 @@ local function registerFluidGenerator(config)
},
onConstruct=fluidGenerator.onConstruct,
onTimer=function(pos,elapsed,meta,inv)
return fluidGenerator.onTimer(pos,elapsed,meta,inv,config.getFuel,config.getFuelByItem)
return fluidGenerator.onTimer(pos,elapsed,meta,inv,config)
end,
onMetadataInventoryPut=fluidGenerator.metadataChange,
onMetadataInventoryMove=fluidGenerator.metadataChange
@@ -233,7 +232,9 @@ local function registerFluidGenerator(config)
},
light_source=8
}
definition.activeOnTimer=fluidGenerator.activeOnTimer
definition.activeOnTimer=function(pos,elapsed,meta,inv)
return fluidGenerator.activeOnTimer(pos,elapsed,meta,inv,config)
end
end
industrialtest.internal.registerMachine(definition)
end