Fix indentation in machines/induction_furnace.lua

This commit is contained in:
mrkubax10 2024-05-10 19:11:01 +02:00 committed by Handful of Frogs
parent 217805dce7
commit 804b40e2bd

View File

@ -38,7 +38,7 @@ local function calculateMaxSrcTime(pos)
end
inductionFurnace.getFormspec=function(pos)
local meta=minetest.get_meta(pos)
local meta=minetest.get_meta(pos)
local powerPercent=meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*100
local maxSrcTime=meta:get_float("maxSrcTime")
local srcPercent=maxSrcTime>0 and meta:get_float("srcTime")/maxSrcTime*100 or 0
@ -46,84 +46,84 @@ inductionFurnace.getFormspec=function(pos)
local formspec
if industrialtest.mtgAvailable then
formspec={
"list[context;src;3.7,1.8;2,1]",
(powerPercent>0 and "image[3.7,2.8;1,1;industrialtest_gui_electricity_bg.png^[lowpart:"..powerPercent..":industrialtest_gui_electricity_fg.png]"
or "image[3.7,2.8;1,1;industrialtest_gui_electricity_bg.png]"),
"list[context;powerStorage;3.7,3.9;1,1]",
(srcPercent>0 and "image[4.9,2.8;1,1;gui_furnace_arrow_bg.png^[lowpart:"..srcPercent..":gui_furnace_arrow_fg.png^[transformR270]"
or "image[4.9,2.8;1,1;gui_furnace_arrow_bg.png^[transformR270]"),
"list[context;dst;6,2.8;2,1;]",
"list[context;upgrades;9,0.9;1,4]",
"label[0.5,2.8;"..minetest.formspec_escape(S("Heat: @1 %",heat)).."]",
"listring[context;src]",
"listring[context;powerStorage]",
"listring[context;dst]",
"listring[context;upgrades]"
"list[context;src;3.7,1.8;2,1]",
(powerPercent>0 and "image[3.7,2.8;1,1;industrialtest_gui_electricity_bg.png^[lowpart:"..powerPercent..":industrialtest_gui_electricity_fg.png]"
or "image[3.7,2.8;1,1;industrialtest_gui_electricity_bg.png]"),
"list[context;powerStorage;3.7,3.9;1,1]",
(srcPercent>0 and "image[4.9,2.8;1,1;gui_furnace_arrow_bg.png^[lowpart:"..srcPercent..":gui_furnace_arrow_fg.png^[transformR270]"
or "image[4.9,2.8;1,1;gui_furnace_arrow_bg.png^[transformR270]"),
"list[context;dst;6,2.8;2,1;]",
"list[context;upgrades;9,0.9;1,4]",
"label[0.5,2.8;"..minetest.formspec_escape(S("Heat: @1 %",heat)).."]",
"listring[context;src]",
"listring[context;powerStorage]",
"listring[context;dst]",
"listring[context;upgrades]"
}
elseif industrialtest.mclAvailable then
formspec={
"list[context;src;3.7,1.8;2,1]",
mcl_formspec.get_itemslot_bg(3.7,1.8,2,1),
(powerPercent>0 and "image[3.7,2.8;1,1;industrialtest_gui_electricity_bg.png^[lowpart:"..powerPercent..":industrialtest_gui_electricity_fg.png]"
or "image[3.7,2.8;1,1;industrialtest_gui_electricity_bg.png]"),
"list[context;powerStorage;3.7,3.9;1,1]",
mcl_formspec.get_itemslot_bg(3.7,3.9,1,1),
(srcPercent>0 and "image[4.9,2.8;1,1;gui_furnace_arrow_bg.png^[lowpart:"..srcPercent..":gui_furnace_arrow_fg.png^[transformR270]"
or "image[4.9,2.8;1,1;gui_furnace_arrow_bg.png^[transformR270]"),
"list[context;dst;6,2.8;2,1;]",
mcl_formspec.get_itemslot_bg(6,2.8,2,1),
"list[context;upgrades;9,0.9;1,4]",
mcl_formspec.get_itemslot_bg(9,0.9,1,4),
"label[0.5,2.8;"..minetest.formspec_escape(S("Heat: @1 %",heat)).."]",
"listring[context;src]",
"listring[context;powerStorage]",
"listring[context;dst]",
"listring[context;upgrades]"
"list[context;src;3.7,1.8;2,1]",
mcl_formspec.get_itemslot_bg(3.7,1.8,2,1),
(powerPercent>0 and "image[3.7,2.8;1,1;industrialtest_gui_electricity_bg.png^[lowpart:"..powerPercent..":industrialtest_gui_electricity_fg.png]"
or "image[3.7,2.8;1,1;industrialtest_gui_electricity_bg.png]"),
"list[context;powerStorage;3.7,3.9;1,1]",
mcl_formspec.get_itemslot_bg(3.7,3.9,1,1),
(srcPercent>0 and "image[4.9,2.8;1,1;gui_furnace_arrow_bg.png^[lowpart:"..srcPercent..":gui_furnace_arrow_fg.png^[transformR270]"
or "image[4.9,2.8;1,1;gui_furnace_arrow_bg.png^[transformR270]"),
"list[context;dst;6,2.8;2,1;]",
mcl_formspec.get_itemslot_bg(6,2.8,2,1),
"list[context;upgrades;9,0.9;1,4]",
mcl_formspec.get_itemslot_bg(9,0.9,1,4),
"label[0.5,2.8;"..minetest.formspec_escape(S("Heat: @1 %",heat)).."]",
"listring[context;src]",
"listring[context;powerStorage]",
"listring[context;dst]",
"listring[context;upgrades]"
}
end
return table.concat(formspec,"")
end
inductionFurnace.onConstruct=function(pos,meta,inv)
inv:set_size("src",2)
inv:set_size("dst",2)
inv:set_size("powerStorage",1)
inv:set_size("upgrades",4)
meta:set_int("heat",0)
meta:set_float("srcTime",0)
inv:set_size("src",2)
inv:set_size("dst",2)
inv:set_size("powerStorage",1)
inv:set_size("upgrades",4)
meta:set_int("heat",0)
meta:set_float("srcTime",0)
end
inductionFurnace.onTimer=function(pos,elapsed,meta,inv)
local shouldRerunTimer=false
local shouldUpdateFormspec=false
local srcList=inv:get_list("src")
local heat=meta:get_int("heat")
local shouldRerunTimer=false
local shouldUpdateFormspec=false
local srcList=inv:get_list("src")
local heat=meta:get_int("heat")
shouldRerunTimer,shouldUpdateFormspec=industrialtest.internal.chargeFromPowerStorageItem(meta,inv)
shouldRerunTimer,shouldUpdateFormspec=industrialtest.internal.chargeFromPowerStorageItem(meta,inv)
if heat>0 then
if heat>0 then
meta:set_int("heat",math.max(heat-math.max(2*elapsed,1),0))
shouldRerunTimer=shouldRerunTimer or heat>0
shouldUpdateFormspec=true
end
for _,slot in ipairs(srcList) do
if not slot:is_empty() then
local result,after=minetest.get_craft_result({
method="cooking",
width=1,
items={slot}
})
if result.time>0 and inv:room_for_item("dst",result.item) then
minetest.swap_node(pos,{
name="industrialtest:induction_furnace_active",
param2=minetest.get_node(pos).param2
})
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
return false,shouldUpdateFormspec
end
end
end
for _,slot in ipairs(srcList) do
if not slot:is_empty() then
local result,after=minetest.get_craft_result({
method="cooking",
width=1,
items={slot}
})
if result.time>0 and inv:room_for_item("dst",result.item) then
minetest.swap_node(pos,{
name="industrialtest:induction_furnace_active",
param2=minetest.get_node(pos).param2
})
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
return false,shouldUpdateFormspec
end
end
end
return shouldRerunTimer,shouldUpdateFormspec
end
@ -174,28 +174,28 @@ inductionFurnace.activeOnTimer=function(pos,elapsed,meta,inv)
local speed=industrialtest.api.getMachineSpeed(meta)
local requiredPower=elapsed*inductionFurnace.opPower*speed
industrialtest.internal.chargeFromPowerStorageItem(meta,inv)
industrialtest.internal.chargeFromPowerStorageItem(meta,inv)
local shouldContinue=false
local results={}
for _,slot in ipairs(srcList) do
if slot:is_empty() then
for _,slot in ipairs(srcList) do
if slot:is_empty() then
table.insert(results,false)
else
local result,after=minetest.get_craft_result({
method="cooking",
width=1,
items={slot}
})
if result.time>0 and inv:room_for_item("dst",result.item) then
local result,after=minetest.get_craft_result({
method="cooking",
width=1,
items={slot}
})
if result.time>0 and inv:room_for_item("dst",result.item) then
table.insert(results,result.item)
shouldContinue=true
else
table.insert(results,false)
end
end
end
if not shouldContinue or powerAmount<requiredPower then
end
end
end
if not shouldContinue or powerAmount<requiredPower then
meta:set_float("srcTime",0)
minetest.swap_node(pos,{
name="industrialtest:induction_furnace",
@ -203,10 +203,10 @@ inductionFurnace.activeOnTimer=function(pos,elapsed,meta,inv)
})
minetest.get_node_timer(pos):start(industrialtest.updateDelay)
return false,true
end
end
srcTime=srcTime+elapsed*(1+heat/100)
if srcTime>=maxSrcTime then
if srcTime>=maxSrcTime then
for i,result in ipairs(results) do
if result then
local multiplier=math.min(srcList[i]:get_count(),speed)
@ -218,8 +218,8 @@ inductionFurnace.activeOnTimer=function(pos,elapsed,meta,inv)
end
end
srcTime=0
end
meta:set_float("srcTime",srcTime)
end
meta:set_float("srcTime",srcTime)
if heat<100 then
meta:set_int("heat",math.min(100,heat+speed))
@ -227,16 +227,16 @@ inductionFurnace.activeOnTimer=function(pos,elapsed,meta,inv)
industrialtest.api.addPower(meta,-requiredPower)
return true,true
return true,true
end
industrialtest.internal.registerMachine({
name="induction_furnace",
displayName=S("Induction Furnace"),
capacity=industrialtest.api.mvPowerFlow*2,
getFormspec=inductionFurnace.getFormspec,
flow=industrialtest.api.mvPowerFlow,
ioConfig="iiiiii",
name="induction_furnace",
displayName=S("Induction Furnace"),
capacity=industrialtest.api.mvPowerFlow*2,
getFormspec=inductionFurnace.getFormspec,
flow=industrialtest.api.mvPowerFlow,
ioConfig="iiiiii",
requiresWrench=true,
registerActiveVariant=true,
sounds="metal",
@ -267,9 +267,9 @@ industrialtest.internal.registerMachine({
"industrialtest_advanced_machine_block.png^industrialtest_electric_furnace_front_active.png"
}
},
onConstruct=inductionFurnace.onConstruct,
onTimer=inductionFurnace.onTimer,
allowMetadataInventoryMove=inductionFurnace.allowMetadataInventoryMove,
onConstruct=inductionFurnace.onConstruct,
onTimer=inductionFurnace.onTimer,
allowMetadataInventoryMove=inductionFurnace.allowMetadataInventoryMove,
allowMetadataInventoryPut=inductionFurnace.allowMetadataInventoryPut,
onMetadataInventoryPut=inductionFurnace.onMetadataInventoryPut,
onMetadataInventoryMove=inductionFurnace.onMetadataInventoryMove,