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") local S=minetest.get_translator("industrialtest")
-- Generators -- Generators
local function generatorFormspec(fuelPercent) local function generatorFormspec(fuelPercent,charged)
minetest.chat_send_all(charged)
local formspec={ local formspec={
industrialtest.formspecVersion(), industrialtest.formspecVersion(),
"size[10.8,12]", "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]", "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), industrialtest.formspecList("context","fuel",4.9,3.9,1,1),
"listring[context;fuel]", "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() industrialtest.formspecPlayerInv()
} }
return table.concat(formspec,"") return table.concat(formspec,"")
@ -55,7 +58,7 @@ local definition={
local inv=meta:get_inventory() local inv=meta:get_inventory()
inv:set_size("charged",1) inv:set_size("charged",1)
inv:set_size("fuel",1) inv:set_size("fuel",1)
meta:set_string("formspec",generatorFormspec(0)) meta:set_string("formspec",generatorFormspec(0,0))
meta:set_int("fuelTime",0) meta:set_int("fuelTime",0)
industrialtest.api.addPowerStorage(meta,5000,10,"oooooo") industrialtest.api.addPowerStorage(meta,5000,10,"oooooo")
end, end,
@ -65,22 +68,18 @@ local definition={
local fuelTime=meta:get_int("fuelTime") local fuelTime=meta:get_int("fuelTime")
local fuelList=inv:get_list("fuel") local fuelList=inv:get_list("fuel")
local chargedList=inv:get_list("charged") local chargedList=inv:get_list("charged")
if industrialtest.api.isFullyCharged(meta) then if fuelTime==0 and not industrialtest.api.isFullyCharged(meta) then
return false local fuel,after=minetest.get_craft_result({
else method="fuel",
if fuelTime==0 then width=1,
local fuel,after=minetest.get_craft_result({ items=fuelList
method="fuel", })
width=1, if fuel.time>0 then
items=fuelList inv:set_stack("fuel",1,after.items[1])
}) fuelTime=fuel.time
if fuel.time>0 then meta:set_int("maxFuelTime",fuelTime)
inv:set_stack("fuel",1,after.items[1]) else
fuelTime=fuel.time return false
meta:set_int("maxFuelTime",fuelTime)
else
return false
end
end end
end end
fuelTime=fuelTime-elapsed fuelTime=fuelTime-elapsed
@ -88,8 +87,8 @@ local definition={
fuelTime=0 fuelTime=0
end end
meta:set_int("fuelTime",fuelTime) meta:set_int("fuelTime",fuelTime)
meta:set_string("formspec",generatorFormspec(fuelTime/meta:get_int("maxFuelTime")*100))
industrialtest.api.addPower(meta,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 if fuelTime>0 or fuelList[1]:get_count()>0 then
return true return true
end end