Implement RE-Battery, generator fixes
This commit is contained in:
64
machines.lua
64
machines.lua
@@ -24,7 +24,8 @@ local function generatorFormspec(fuelPercent,charged)
|
||||
"label[0.5,0.5;"..S("Generator").."]",
|
||||
industrialtest.formspecList("context","charged",4.9,1.8,1,1),
|
||||
"listring[context;charged]",
|
||||
"image[4.9,2.8;1,1;default_furnace_fire_bg.png^[lowpart:"..fuelPercent..":default_furnace_fire_fg.png]",
|
||||
(fuelPercent>0 and "image[4.9,2.8;1,1;default_furnace_fire_bg.png^[lowpart:"..fuelPercent..":default_furnace_fire_fg.png]"
|
||||
or "image[4.9,2.8;1,1;default_furnace_fire_bg.png]"),
|
||||
industrialtest.formspecList("context","fuel",4.9,3.9,1,1),
|
||||
"listring[context;fuel]",
|
||||
"box[9,1;0.3,4.8;#202020]",
|
||||
@@ -59,40 +60,57 @@ local definition={
|
||||
inv:set_size("fuel",1)
|
||||
meta:set_string("formspec",generatorFormspec(0,0))
|
||||
meta:set_int("fuelTime",0)
|
||||
industrialtest.api.addPowerStorage(meta,5000,10,"oooooo")
|
||||
meta:set_int("maxFuelTime",1)
|
||||
industrialtest.api.addPowerStorage(meta,7000,100,"oooooo")
|
||||
end,
|
||||
on_timer=function(pos,elapsed)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local powerFlow=meta:get_int("industrialtest.powerFlow")
|
||||
local inv=meta:get_inventory()
|
||||
local fuelTime=meta:get_int("fuelTime")
|
||||
local fuelList=inv:get_list("fuel")
|
||||
local chargedList=inv:get_list("charged")
|
||||
if fuelTime==0 and not industrialtest.api.isFullyCharged(meta) then
|
||||
local fuel,after=minetest.get_craft_result({
|
||||
local chargedSlot=inv:get_stack("charged",1)
|
||||
local fuelSlot=inv:get_stack("fuel",1)
|
||||
local shouldUpdateFormspec=false
|
||||
local shouldRerunTimer=false
|
||||
|
||||
if chargedSlot:get_count()>0 and not industrialtest.api.isFullyCharged(chargedSlot:get_meta()) and meta:get_int("industrialtest.powerAmount")>0 then
|
||||
industrialtest.api.transferPowerToItem(meta,chargedSlot,powerFlow)
|
||||
inv:set_stack("charged",1,chargedSlot)
|
||||
shouldUpdateFormspec=true
|
||||
shouldRerunTimer=true
|
||||
end
|
||||
if fuelSlot:get_count()>0 and meta:get_int("fuelTime")<=0 and not industrialtest.api.isFullyCharged(meta) then
|
||||
local output,after=minetest.get_craft_result({
|
||||
method="fuel",
|
||||
width=1,
|
||||
items=fuelList
|
||||
items={fuelSlot}
|
||||
})
|
||||
if fuel.time>0 then
|
||||
if output.time>0 then
|
||||
meta:set_int("fuelTime",output.time)
|
||||
meta:set_int("maxFuelTime",output.time)
|
||||
inv:set_stack("fuel",1,after.items[1])
|
||||
fuelTime=fuel.time
|
||||
meta:set_int("maxFuelTime",fuelTime)
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
fuelTime=fuelTime-elapsed
|
||||
if fuelTime<0 then
|
||||
fuelTime=0
|
||||
if meta:get_int("fuelTime")>0 then
|
||||
meta:set_int("fuelTime",meta:get_int("fuelTime")-elapsed)
|
||||
industrialtest.api.addPower(meta,200)
|
||||
shouldUpdateFormspec=true
|
||||
shouldRerunTimer=true
|
||||
end
|
||||
meta:set_int("fuelTime",fuelTime)
|
||||
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")))
|
||||
industrialtest.api.powerFlow(pos)
|
||||
if fuelTime>0 or fuelList[1]:get_count()>0 then
|
||||
return true
|
||||
|
||||
if shouldUpdateFormspec then
|
||||
meta:set_string("formspec",generatorFormspec(meta:get_int("fuelTime")/meta:get_int("maxFuelTime")*100,meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")))
|
||||
end
|
||||
return false
|
||||
|
||||
return shouldRerunTimer
|
||||
end,
|
||||
allow_metadata_inventory_move=function(pos,fromList,fromIndex,toList,toIndex,count,player)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
local movedItemStack=inv:get_list(fromList)[1]
|
||||
if toList=="charged" and not industrialtest.api.hasPowerStorage(movedItemStack:get_meta()) then
|
||||
return 0
|
||||
end
|
||||
return count
|
||||
end,
|
||||
allow_metadata_inventory_put=function(pos,listname,index,stack,player)
|
||||
if listname=="charged" and not industrialtest.api.hasPowerStorage(stack:get_meta()) then
|
||||
|
||||
Reference in New Issue
Block a user