Generator formspec improvements

This commit is contained in:
mrkubax10 2023-03-01 19:29:20 +01:00
parent 71618b2f3f
commit cb7fba8692

View File

@ -17,7 +17,8 @@
local S=minetest.get_translator("industrialtest")
-- Generators
local function generatorFormspec(fuelPercent)
local function generatorFormspec(fuelPercent,charged)
minetest.chat_send_all(charged)
local formspec={
industrialtest.formspecVersion(),
"size[10.8,12]",
@ -27,6 +28,8 @@ local function generatorFormspec(fuelPercent)
"image[4.9,2.8;1,1;default_furnace_fire_bg.png^[lowpart:"..fuelPercent..":default_furnace_fire_fg.png]",
industrialtest.formspecList("context","fuel",4.9,3.9,1,1),
"listring[context;fuel]",
"box[9,1;0.3,4.8;#202020]",
(charged>0 and "box[9,"..(1+4.8-(charged*4.8))..";0.3,"..(charged*4.8)..";#FF1010]" or ""),
industrialtest.formspecPlayerInv()
}
return table.concat(formspec,"")
@ -55,7 +58,7 @@ local definition={
local inv=meta:get_inventory()
inv:set_size("charged",1)
inv:set_size("fuel",1)
meta:set_string("formspec",generatorFormspec(0))
meta:set_string("formspec",generatorFormspec(0,0))
meta:set_int("fuelTime",0)
industrialtest.api.addPowerStorage(meta,5000,10,"oooooo")
end,
@ -65,22 +68,18 @@ local definition={
local fuelTime=meta:get_int("fuelTime")
local fuelList=inv:get_list("fuel")
local chargedList=inv:get_list("charged")
if industrialtest.api.isFullyCharged(meta) then
return false
else
if fuelTime==0 then
local fuel,after=minetest.get_craft_result({
method="fuel",
width=1,
items=fuelList
})
if fuel.time>0 then
inv:set_stack("fuel",1,after.items[1])
fuelTime=fuel.time
meta:set_int("maxFuelTime",fuelTime)
else
return false
end
if fuelTime==0 and not industrialtest.api.isFullyCharged(meta) then
local fuel,after=minetest.get_craft_result({
method="fuel",
width=1,
items=fuelList
})
if fuel.time>0 then
inv:set_stack("fuel",1,after.items[1])
fuelTime=fuel.time
meta:set_int("maxFuelTime",fuelTime)
else
return false
end
end
fuelTime=fuelTime-elapsed
@ -88,8 +87,8 @@ local definition={
fuelTime=0
end
meta:set_int("fuelTime",fuelTime)
meta:set_string("formspec",generatorFormspec(fuelTime/meta:get_int("maxFuelTime")*100))
industrialtest.api.addPower(meta,100)
meta:set_string("formspec",generatorFormspec(fuelTime/meta:get_int("maxFuelTime")*100,meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")))
if fuelTime>0 or fuelList[1]:get_count()>0 then
return true
end