local basinpath = "right" local tablepath = "bottom" local drainpath = "tconstruct_smelterydrain_2" local monitorpath = "monitor_3" local basintime = 10 local basindelay = 5 local tabletime = 2 local tabledelay = 3 local drain = peripheral.wrap(drainpath) or error("Unable to wrap drain!",0) os.loadAPI("display") local mon = display.load(monitorpath) local savefile = "activestate.sav" local active = false local updaterate = .1 local drawrate = .2 local mbtoingot = 144 -- millibucket to ingot ratio 144/1 local function getingots() local tank = drain.getTankInfo("back") if not tank[1].amount then return 0 end return tank[1].amount/mbtoingot end local function activatebasin() rs.setOutput(basinpath,true) sleep(10) rs.setOutput(basinpath,false) sleep(4) end local function activatetable() rs.setOutput(tablepath,true) sleep(2) rs.setOutput(tablepath,false) sleep(3) end local function draw() local w,h = mon.obj.getSize() local ingots = getingots() mon:setbgcolor(colors.black) mon:clear() -- ON/OFF local txt = "" if active then txt = "ON" mon:setbgcolor(colors.lime) mon:setfgcolor(colors.green) else txt = "OFF" mon:setbgcolor(colors.red) mon:setfgcolor(colors.brown) end mon:write(txt,3,2) mon:rect("fill",1,2,w,6,true) if active then mon:setbgcolor(colors.green) mon:line(2,4,4,6) mon:line(4,6,6,2) else mon:setbgcolor(colors.brown) mon:line(1,2,7,6) mon:line(7,2,1,6) end -- ingots mon:setfgcolor(colors.blue) mon:setbgcolor(colors.lightBlue) local txt = "storage" mon:write(txt,w/2-#txt/2+1,8) local txt = tostring(ingots) mon:write(txt,w/2-#txt/2+1,9) mon:rect("fill",1,7,w,10,true) mon:update() mon:draw() end local function save() local file = fs.open(savefile,"w") file.write(tostring(active)) file.close() end local function load() if fs.exists(savefile) then local file = fs.open(savefile,"r") local state = file.readLine() if state == "true" then active = true end if state == "false" then active = false end file.close() end end local updatetimer = os.startTimer(updaterate) local drawtimer = os.startTimer(drawrate) local basintimer, tabletimer, basindelaytimer, tabledelaytimer local drainready = true load() while true do local ev,p1,p2,p3 = os.pullEvent() if ev == "timer" then if p1 == updatetimer then updatetimer = os.startTimer(updaterate) if active then local ingots = getingots() if ingots < 9 and ingots > 0 and drainready then -- smelt seperate ingot with table rs.setOutput(tablepath,true) tabletimer = os.startTimer(tabletime) drainready = false end local ingots = getingots() if ingots >= 9 and drainready then -- smelt block with basin rs.setOutput(basinpath,true) basintimer = os.startTimer(basintime) drainready = false end end elseif p1 == drawtimer then drawtimer = os.startTimer(drawrate) draw() elseif p1 == tabletimer then rs.setOutput(tablepath,false) tabledelaytimer = os.startTimer(tabledelay) elseif p1 == basintimer then rs.setOutput(basinpath,false) basindelaytimer = os.startTimer(basindelay) elseif p1 == tabledelaytimer then drainready = true elseif p1 == basindelaytimer then drainready = true end elseif ev == "monitor_touch" then if p2 >= 1 and p2 <= 7 and p3 >=2 and p3 <= 6 then active = not active save() end end end