Advertisement
NanoBob

MFR spawner system

Jul 20th, 2015
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. if fs.exists("events")==false then
  2.     shell.run("pastebin get bmKBU4Rv events")
  3. end
  4. os.loadAPI("events")
  5.  
  6. if fs.exists("button")==false then
  7.     shell.run("pastebin get hbeLn1ni button")
  8. end
  9. os.loadAPI("button")
  10.  
  11. --button.setDebugMode(true)
  12. local timer=os.startTimer(1)
  13. button.setMonitorSide("monitor_0")
  14. button.setBackgroundColor(32768)
  15. local monitor=peripheral.wrap("monitor_0")
  16. local spawner=peripheral.wrap("top")
  17. local essenceTank=peripheral.wrap("rcirontankvalvetile_0")
  18.  
  19. redstone.setOutput("top",true)
  20. function toggleSpawner(bool)
  21.     redstone.setOutput("top",not bool)
  22.     drawDisplay()
  23. end
  24.  
  25. function setupDisplay()
  26.     local screenx,screeny=monitor.getSize()
  27.     button.removeAllButtons()
  28.     button.addButton(1,screeny-2,screenx,3,"Toggle spawner",toggleSpawner,true,false,128,256)  
  29. end
  30. setupDisplay()
  31.  
  32. function clearLines(start,stop)
  33.     local screenx,screeny=monitor.getSize()
  34.     monitor.setBackgroundColor(128)
  35.     local clearString=""
  36.     for i=1,screenx do
  37.         clearString=clearString.." "
  38.     end
  39.     for i=start,stop do
  40.         monitor.setCursorPos(1,i)
  41.         monitor.write(clearString)
  42.     end
  43. end
  44.  
  45. function drawDisplay(timer)
  46.     local energy=spawner.getEnergyStored()
  47.     local internalTank=spawner.getTankInfo()
  48.     local exact=spawner.getSpawnExact()
  49.     local fluidAmmount=0
  50.     if internalTank[1]~=nil then
  51.         fluidAmmount=fluidAmmount+internalTank[1].contents.amount
  52.     end
  53.     local essence=essenceTank.getTankInfo()
  54.     if essence[1]~=nil then
  55.         fluidAmmount=fluidAmmount+essence[1].contents.amount
  56.     end
  57.     clearLines(1,7)
  58.     monitor.setCursorPos(5,2)
  59.     monitor.write("Energy : "..energy.." RF")
  60.     monitor.setCursorPos(5,3)
  61.     monitor.write("Essence : "..math.floor(fluidAmmount/100+0.5)*0.1 .." Buckets")
  62.     monitor.setCursorPos(5,5)
  63.     monitor.write("Exact copy : "..tostring(exact))
  64.     monitor.setCursorPos(5,6)
  65.     monitor.write("Active : "..tostring(not redstone.getOutput("top")))
  66.     timer=os.startTimer(1)
  67. end
  68. events.addEventHandler("timer",drawDisplay)
  69. drawDisplay()
  70.  
  71. while true do
  72.     events.handleCCEvents()
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement