Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.55 KB | None | 0 0
  1. ----------------------------------------------------------
  2. -- Active Cooling Big Reactor Monitor --
  3. -- --
  4. -- Minecraft HermitCraft FTB Infinity Episode 28 --
  5. -- https://www.youtube.com/watch?v=cIPxwZJWOiE --
  6. -- --
  7. -- YouTube Channel http://youtube.com/hypnotizd --
  8. ----------------------------------------------------------
  9.  
  10. local mon = {}
  11. local hasMon = false
  12. local hasRMon = false
  13. local rMonName = ""
  14. local cPort = {}
  15. local hasCPort = false
  16. local hasRCPort = false
  17. local rCPortName = ""
  18. local directions = {"top", "bottom", "front", "back", "left", "right"}
  19. local minX = 0
  20. local minY = 0
  21. local minZ = 0
  22. local maxX = 0
  23. local maxY = 0
  24. local maxZ = 0
  25. local crPrevCoreTemp = 0
  26. local crCoreTemp = 0
  27. local crCoreChangeWait = 0
  28.  
  29. local function findPeripherals()
  30. for k, v in pairs(peripheral.getNames()) do
  31. if string.find(v, "Reactor") then
  32. hasCPort = true
  33. hasRCPort = true
  34. rCPortName = v
  35. print("INFO: Found remote "..v)
  36. os.sleep(1)
  37. elseif string.find(v, "monitor") then
  38. hasMon = true
  39. hasRMon = true
  40. rMonName = v
  41. print("INFO: Found remote "..v)
  42. os.sleep(1)
  43. end
  44. end
  45. end
  46.  
  47. local function findCPort()
  48. if hasRCPort then return end
  49. for k, v in pairs(directions) do
  50. local p = peripheral.wrap(v)
  51. if p ~= nil then
  52. if string.find(peripheral.getType(v), "Reactor") then
  53. cPort = p
  54. hasCPort = true
  55. return
  56. end
  57. end
  58. end
  59. print("ERROR: No computer port detected!")
  60. end
  61.  
  62. local function findMon()
  63. if hasRMon then return end
  64. for k, v in pairs(directions) do
  65. local p = peripheral.wrap(v)
  66. if p ~= nil then
  67. if string.find(peripheral.getType(v), "monitor") then
  68. mon = p
  69. hasMon = true
  70. return
  71. end
  72. end
  73. end
  74. print("WARNING: No monitor detected!")
  75. os.sleep(5)
  76. end
  77.  
  78. local function monClear()
  79. if hasMon then
  80. if hasRMon then
  81. peripheral.call(rMonName, "setCursorPos", 1, 1)
  82. peripheral.call(rMonName, "clear")
  83. else
  84. mon.setCursorPos(1, 1)
  85. mon.clear()
  86. end
  87. else
  88. term.clear()
  89. term.setCursorPos(1, 1)
  90. end
  91. end
  92.  
  93. local function monWrite(x, y, text)
  94. if hasMon then
  95. if hasRMon then
  96. peripheral.call(rMonName, "setCursorPos", x, y)
  97. peripheral.call(rMonName, "write", text)
  98. else
  99. mon.setCursorPos(x, y)
  100. mon.write(text)
  101. end
  102. else
  103. term.setCursorPos(x, y)
  104. term.write(text)
  105. end
  106. end
  107.  
  108. local function getSize()
  109. if hasRCPort then
  110. minX, minY, minZ = peripheral.call(rCPortName, "getMinimumCoordinate")
  111. maxX, maxY, maxZ = peripheral.call(rCPortName, "getMaximumCoordinate")
  112. else
  113. minX, minY, minZ = cPort.getMinimumCoordinate()
  114. maxX, maxY, maxZ = cPort.getMaximumCoordinate()
  115. end
  116. end
  117.  
  118. local function setAllControlRodLevels(x)
  119. if hasRCPort then
  120. peripheral.call(rCPortName, "setAllControlRodLevels", x)
  121. else
  122. cPort.setAllControlRodLevels(x)
  123. end
  124. end
  125.  
  126. local function getActive()
  127. local ret = false
  128. if hasRCPort then
  129. ret = peripheral.call(rCPortName, "getActive")
  130. else
  131. ret = cPort.getActive()
  132. end
  133. return ret
  134. end
  135.  
  136. local function getControlRodLevel()
  137. local ret = 0
  138. if hasRCPort then
  139. ret = peripheral.call(rCPortName, "getControlRodLevel", 0)
  140. else
  141. ret = cPort.getControlRodLevel(0)
  142. end
  143. return ret
  144. end
  145.  
  146. local function getFuelTemperature()
  147. local ret
  148. if hasRCPort then
  149. ret = peripheral.call(rCPortName, "getFuelTemperature")
  150. else
  151. ret = cPort.getFuelTemperature()
  152. end
  153. return ret
  154. end
  155.  
  156. local function setControlRods()
  157. if getActive() then
  158. if crCoreTemp ~= 0 then
  159. crPrevCoreTemp = crCoreTemp
  160. crCoreTemp = getFuelTemperature()
  161. local ctrlRodLevel = getControlRodLevel()
  162. local tempDiff = crPrevCoreTemp - crCoreTemp
  163. if crCoreChangeWait > 0 then
  164. crCoreChangeWait = crCoreChangeWait - 1
  165. return
  166. end
  167. if crCoreTemp >= 1350 then
  168. setAllControlRodLevels(ctrlRodLevel+1)
  169. elseif crCoreTemp >= 1050 then
  170. setAllControlRodLevels(ctrlRodLevel+1)
  171. crCoreChangeWait = 1
  172. elseif crCoreTemp <= 600 then
  173. setAllControlRodLevels(ctrlRodLevel-1)
  174. elseif crCoreTemp <= 950 then
  175. setAllControlRodLevels(ctrlRodLevel-1)
  176. crCoreChangeWait = 1
  177. end
  178. else
  179. crCoreTemp = getFuelTemperature()
  180. if getControlRodLevel() == 100 then
  181. setAllControlRodLevels(99)
  182. end
  183. crCoreChangeWait = 1
  184. end
  185. end
  186. end
  187.  
  188. local function init()
  189. term.setCursorPos(1, 1)
  190. findPeripherals()
  191. findCPort()
  192. findMon()
  193. getSize()
  194. monClear()
  195. end
  196.  
  197. local function displayInfo()
  198. local rods = 0
  199. local casingTemp = 0
  200. local coreTemp = 0
  201. local rodLevel = 0
  202. local fuelReactivity = 0
  203. local fuelConsumed = 0
  204. local steamProduced = 0
  205.  
  206. if hasRCPort then
  207. rods = peripheral.call(rCPortName, "getNumberOfControlRods")
  208. casingTemp = peripheral.call(rCPortName, "getCasingTemperature")
  209. coreTemp = peripheral.call(rCPortName, "getFuelTemperature")
  210. rodLevel = peripheral.call(rCPortName, "getControlRodLevel", 0)
  211. fuelReactivity = peripheral.call(rCPortName, "getFuelReactivity")
  212. fuelConsumed = peripheral.call(rCPortName, "getFuelConsumedLastTick")
  213. steamProduced = peripheral.call(rCPortName, "getHotFluidProducedLastTick")
  214. else
  215. rods = cPort.getNumberOfControlRods()
  216. casingTemp = cPort.getCasingTemperature()
  217. coreTemp = cPort.getFuelTemperature()
  218. rodLevel = cPort.getControlRodLevel(0)
  219. fuelReactivity = cPort.getFuelReactivity()
  220. fuelConsumed = cPort.getFuelConsumedLastTick()
  221. steamProduced = cPort.getHotFluidProducedLastTick()
  222. end
  223.  
  224. local active = "Inactive"
  225. if getActive() then
  226. active = "Active"
  227. end
  228.  
  229. monClear()
  230. monWrite(1, 1, " Reactor Status: "..active)
  231. monWrite(1, 2, " Reactor Size: "..1+maxX-minX.."x"..1+maxY-minY.."x"..1+maxZ-minZ)
  232. monWrite(1, 3, " Num Control Rods: "..rods)
  233. monWrite(1, 4, " Casing Temp.: "..casingTemp)
  234. monWrite(1, 5, " Core Temp.: "..coreTemp)
  235. monWrite(1, 6, "Control Rod Level: "..rodLevel)
  236. monWrite(1, 7, " Fuel Reactivity: "..fuelReactivity)
  237. monWrite(1, 8, " Fuel Usage/tick: "..fuelConsumed)
  238. monWrite(1, 9, " Steam Produced: "..steamProduced)
  239. end
  240.  
  241. term.clear()
  242. init()
  243. if hasCPort == false then return end
  244.  
  245. while true do
  246. setControlRods()
  247. displayInfo()
  248. os.sleep(3)
  249. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement