Generator formspec improvements
This commit is contained in:
parent
71618b2f3f
commit
cb7fba8692
15
machines.lua
15
machines.lua
|
@ -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,10 +68,7 @@ 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
|
||||
if fuelTime==0 and not industrialtest.api.isFullyCharged(meta) then
|
||||
local fuel,after=minetest.get_craft_result({
|
||||
method="fuel",
|
||||
width=1,
|
||||
|
@ -82,14 +82,13 @@ local definition={
|
|||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
fuelTime=fuelTime-elapsed
|
||||
if fuelTime<0 then
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue