Advertisement
Guest User

ignore

a guest
Nov 17th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 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("nuclearcraft:fission_port")
  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_enderio_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], "nuclearcraft:fission_port") 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_enderio_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.  
  103. if eMax >= 10000000 then
  104. monitor.setCursorPos(11,2)
  105. monitor.write("Storage:")
  106. monitor.setCursorPos(11,3)
  107. monitor.write(math.ceil(eNow/1000).."kRF")
  108. monitor.setCursorPos(11,4)
  109. monitor.write("Of:")
  110. monitor.setCursorPos(11,5)
  111. monitor.write(math.ceil(eMax/1000).."kRF")
  112. else
  113. monitor.setCursorPos(11,2)
  114. monitor.write("Storage:")
  115. monitor.setCursorPos(11,3)
  116. monitor.write(math.ceil(eNow))
  117. monitor.setCursorPos(11,4)
  118. monitor.write("Of:")
  119. monitor.setCursorPos(11,5)
  120. monitor.write(math.ceil(eMax))
  121. end
  122.  
  123. monitor.setCursorPos(1,2)
  124. monitor.write("Engines:")
  125. end
  126.  
  127. if fill > upper then
  128. --energylevel is over upper level, turning redstone signal off
  129. redstone.setOutput("back", false)
  130.  
  131. if monitor ~= "none" then
  132. monitor.setBackgroundColour((colours.grey))
  133. monitor.setCursorPos(1,4)
  134. monitor.write(" ON ")
  135. monitor.setBackgroundColour((colours.green))
  136. monitor.setCursorPos(5,4)
  137. monitor.write(" OFF ")
  138. monitor.setBackgroundColour((colours.black))
  139. end
  140.  
  141. elseif fill < lower then
  142. --energy level is below lower limit, turning redstone signal on
  143. redstone.setOutput("back", true)
  144.  
  145. if monitor ~= "none" then
  146. monitor.setBackgroundColour((colours.green))
  147. monitor.setCursorPos(1,4)
  148. monitor.write(" ON ")
  149. monitor.setBackgroundColour((colours.grey))
  150. monitor.setCursorPos(5,4)
  151. monitor.write(" OFF ")
  152. monitor.setBackgroundColour((colours.black))
  153. end
  154. end
  155.  
  156.  
  157. sleep(1)
  158. end --while
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement