Advertisement
MrQuentinet

Untitled

Jul 29th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.27 KB | None | 0 0
  1. -- Monitors TE3 Energy cells and EnderIO capacitor banks and output redstone signals once energy storage drops below set limits.
  2. -- Will automatically detect direction of adjacent storage device and (optional) Advanced Monitors. If chosen, monitor format should be 1 high and 2 wide. Now also with wired modem support for both storage and monitors. Directly adjacent devices will take priority over any wired devices.
  3. -- Redstone signal for the engines will be output out the back of the computer.
  4. --More details: http://forum.feed-the-beast.com/threads/rhns-1-6-monster-build-journal-and-guide-collection.42664/page-15#post-718973
  5.  
  6.  
  7. local upper = 0.90 --Upper limit for computer to stop transmitting redstone signal. 0.90=90% full.
  8. local lower = 0.10 --Lower limit for computer to start transmitting redstone signal.
  9.  
  10.  
  11. --Device detection
  12. isError=0
  13.  
  14. function detectDevice(DeviceName)
  15. DeviceSide="none"
  16. for k,v in pairs(redstone.getSides()) do
  17. if peripheral.getType(v)==DeviceName then
  18. DeviceSide = v
  19. break
  20. end
  21. end
  22. return(DeviceSide)
  23. end
  24.  
  25.  
  26. cell="none"
  27. monitor="none"
  28. local peripheralList = peripheral.getNames()
  29.  
  30. CellSide=detectDevice("cofh_thermalexpansion_energycell")
  31.  
  32. if CellSide~="none" then
  33. cell=peripheral.wrap(CellSide)
  34. print ("TE Energy cell on the " .. CellSide .. " connected.")
  35. else
  36. CellSide=detectDevice("tile_blockcapacitorbank_name")
  37. if CellSide~="none" then
  38. cell=peripheral.wrap(CellSide)
  39. print ("EnderIO capacitorbank on the " .. CellSide .. " connected.")
  40. else
  41. for Index = 1, #peripheralList do
  42. if string.find(peripheralList[Index], "cofh_thermalexpansion_energycell") then
  43. cell=peripheral.wrap(peripheralList[Index])
  44. print ("TE Energy cell on wired modem: "..peripheralList[Index].." connected.")
  45. elseif string.find(peripheralList[Index], "tile_blockcapacitorbank_name") then
  46. cell=peripheral.wrap(peripheralList[Index])
  47. print ("EnderIO capacitorbank on wired modem: "..peripheralList[Index].." connected.")
  48. end
  49. end --for
  50. if cell == "none" then
  51. print("No Energy storage found. Halting script!")
  52. return
  53. end
  54.  
  55. end
  56. end
  57.  
  58.  
  59. MonitorSide=detectDevice("monitor")
  60.  
  61. if MonitorSide~="none" then
  62. monitor=peripheral.wrap(MonitorSide)
  63. print ("Monitor on the " .. MonitorSide .. " connected.")
  64. else
  65. for Index = 1, #peripheralList do
  66. if string.find(peripheralList[Index], "monitor") then
  67. monitor=peripheral.wrap(peripheralList[Index])
  68. print ("Monitor on wired modem: "..peripheralList[Index].." connected.")
  69. end
  70. end --for
  71. if monitor == "none" then
  72. print ("Warning - No Monitor attached, continuing without.")
  73. end
  74. end
  75.  
  76. --Main code
  77. redstone.setOutput("back", false) --Defaulting to off
  78.  
  79. --If monitor is attached, write data on monitor
  80. if monitor ~= "none" then
  81. monitor.clear()
  82. monitor.setBackgroundColour((colours.grey))
  83. monitor.setCursorPos(1,4)
  84. monitor.write(" ON ")
  85. monitor.setBackgroundColour((colours.green))
  86. monitor.setCursorPos(5,4)
  87. monitor.write(" OFF ")
  88. monitor.setBackgroundColour((colours.black))
  89. end
  90.  
  91. --Main loop
  92. while true do
  93. --Get storage values
  94. eNow = cell.getEnergyStored("unknown")
  95. eMax = cell.getMaxEnergyStored("unknown")
  96.  
  97. --Compute ratio
  98. fill = (eNow / eMax)
  99.  
  100. --If monitor is attached, write data on monitor
  101. if monitor ~= "none" then
  102. if eMax >= 100000 and eMax<10000000 then
  103. monitor.setCursorPos(11,2)
  104. monitor.write("Storage:")
  105. monitor.setCursorPos(11,3)
  106. monitor.write(math.ceil(eNow/1000).."kRF")
  107. monitor.setCursorPos(11,4)
  108. monitor.write("Of:")
  109. monitor.setCursorPos(11,5)
  110. monitor.write(math.ceil(eMax/1000).."kRF")
  111. end
  112. if eMax>= 10000000 then
  113. monitor.setCursorPos(11,2)
  114. monitor.write("Storage:")
  115. monitor.setCursorPos(11,3)
  116. monitor.write(math.ceil(eNow/1000000).."MRF")
  117. monitor.setCursorPos(11,4)
  118. monitor.write("Of:")
  119. monitor.setCursorPos(11,5)
  120. monitor.write(math.ceil(eMax/1000000).."MRF")
  121. end
  122. if eMax<100000 then
  123. monitor.setCursorPos(11,2)
  124. monitor.write("Storage:")
  125. monitor.setCursorPos(11,3)
  126. monitor.write(math.ceil(eNow))
  127. monitor.setCursorPos(11,4)
  128. monitor.write("Of:")
  129. monitor.setCursorPos(11,5)
  130. monitor.write(math.ceil(eMax))
  131. end
  132.  
  133. monitor.setCursorPos(1,2)
  134. monitor.write("Engines:")
  135. end
  136.  
  137. if fill > upper then
  138. --energylevel is over upper level, turning redstone signal off
  139. redstone.setOutput("back", false)
  140.  
  141. if monitor ~= "none" then
  142. monitor.setBackgroundColour((colours.grey))
  143. monitor.setCursorPos(1,4)
  144. monitor.write(" ON ")
  145. monitor.setBackgroundColour((colours.green))
  146. monitor.setCursorPos(5,4)
  147. monitor.write(" OFF ")
  148. monitor.setBackgroundColour((colours.black))
  149. end
  150.  
  151. elseif fill < lower then
  152. --energy level is below lower limit, turning redstone signal on
  153. redstone.setOutput("back", true)
  154.  
  155. if monitor ~= "none" then
  156. monitor.setBackgroundColour((colours.green))
  157. monitor.setCursorPos(1,4)
  158. monitor.write(" ON ")
  159. monitor.setBackgroundColour((colours.grey))
  160. monitor.setCursorPos(5,4)
  161. monitor.write(" OFF ")
  162. monitor.setBackgroundColour((colours.black))
  163. end
  164. end
  165.  
  166.  
  167. sleep(1)
  168. end --while
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement