Advertisement
cyber_Ahn

Mekanism Reactor / Energy Storage Info and Control

Sep 17th, 2016
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.46 KB | None | 0 0
  1. --Mekanism Reactor / Energy Storage Info and Control (New Cytek Map)
  2. --automatic search in network
  3.  
  4. local hw = {}
  5. local reactor
  6. local storage
  7. local B_reactor = 0
  8. local B_production = 0
  9. local B_load = 0
  10. local B_chest = 0
  11. local cable_side = "X"
  12. --load API
  13. shell.run("delete caAPI")
  14. shell.run("pastebin get EDLdR1nF caAPI")
  15. os.loadAPI("caAPI")
  16.  
  17. --set monitor
  18. function set_monitor()
  19. local monitor_number = caAPI.get_hardware("monitor")
  20. local found = fs.exists("config/monitor.cfg")
  21. if found == true then
  22. file = fs.open("config/monitor.cfg","r")
  23. local fileData = {}
  24. local line = file.readLine()
  25. repeat
  26. table.insert(fileData,line)
  27. line = file.readLine()
  28. until line == nil
  29. file.close()
  30. monitor_number = fileData[1]
  31. end
  32. mon = peripheral.wrap(monitor_number)
  33. end
  34.  
  35. --search mekanism maschine
  36. function search()
  37. local periList = peripheral.getNames()
  38. for i = 1, #periList do
  39. if peripheral.getType(periList[i]) == "mekanism_machine" then
  40. table.insert(hw,periList[i])
  41. end
  42. end
  43. end
  44.  
  45. -- format number for print
  46. function format(num)
  47. out = tostring(math.floor(num)).." J"
  48. if num > 1000000000000 then
  49. num = num / 1000000000000
  50. out = tostring(math.floor(num)).." TJ"
  51. end
  52. if num > 1000000000 then
  53. num = num / 1000000000
  54. out = tostring(math.floor(num)).." GJ"
  55. end
  56. if num > 1000000 then
  57. num = num / 1000000
  58. out = tostring(math.floor(num)).." MJ"
  59. end
  60. if num > 1000 then
  61. num = num / 1000
  62. out = tostring(math.floor(num)).." KJ"
  63. end
  64. return out
  65. end
  66.  
  67. -- search cable()
  68. function input_cable_side()
  69. local found = fs.exists("config.cfg")
  70. if found == false then
  71. mon.setTextColor(colors.white)
  72. mon.setBackgroundColor(colors.black)
  73. mon.clear()
  74. mon.setCursorPos(1,1)
  75. mon.write("Input side of BundledCable")
  76. input = read()
  77. cable_side = input
  78. local file = fs.open("config.cfg","w")
  79. file.writeLine(cable_side)
  80. file.close()
  81. else
  82. file = fs.open("config.cfg","r")
  83. local fileData = {}
  84. local line = file.readLine()
  85. repeat
  86. table.insert(fileData,line)
  87. line = file.readLine()
  88. until line == nil
  89. file.close()
  90. cable_side = fileData[1]
  91. end
  92. end
  93.  
  94. -- set cable
  95. function set_cable()
  96. color_set_1 = colors.black
  97. if B_reactor == 1 then
  98. color_set_1 = color_set_1 + colors.white
  99. end
  100. if B_production == 1 then
  101. color_set_1 = color_set_1 + colors.orange
  102. end
  103. if B_load == 1 then
  104. color_set_1 = color_set_1 + colors.magenta
  105. end
  106. if B_chest == 1 then
  107. color_set_1 = color_set_1 + colors.yellow
  108. end
  109. shell.run("delete backup.db")
  110. local file = fs.open("backup.db","w")
  111. file.writeLine(tostring(B_reactor))
  112. file.writeLine(tostring(B_production))
  113. file.writeLine(tostring(B_load))
  114. file.close()
  115. sleep(1)
  116. rs.setBundledOutput(cable_side,color_set_1)
  117. end
  118.  
  119. --draw screen
  120. function draw_screen()
  121. mon.setTextColor(colors.black)
  122. mon.setBackgroundColor(colors.white)
  123. mon.clear()
  124. mon.setCursorPos(1,1)
  125. mon.setTextColor(colors.white)
  126. mon.setBackgroundColor(colors.blue)
  127. mon.write("Mekanism Maschines Found "..tostring(#hw).." Maschines             ")
  128. mon.setCursorPos(50,1)
  129. mon.setTextColor(colors.black)
  130. mon.setBackgroundColor(colors.red)
  131. mon.write("X")
  132. mon.setBackgroundColor(colors.white)
  133. mon.setCursorPos(35,3)
  134. mon.write("CableSide: "..cable_side)
  135. for i = 1, #hw do
  136. hwC = peripheral.wrap(hw[i])
  137. nameC = hwC.getInventoryName()
  138. if nameC == "Induction Matrix" then
  139. storage = peripheral.wrap(hw[i])
  140. end
  141. if nameC == "tile.Reactor.name.name" then
  142. reactor = peripheral.wrap(hw[i])
  143. end
  144. end
  145. storageN =  storage.getInventoryName()
  146. reactorN = "Reactor"
  147. mon.setTextColor(colors.black)
  148. mon.setBackgroundColor(colors.white)
  149. mon.setCursorPos(2,2)
  150. mon.write(storageN)
  151. maxE = storage.getMaxEnergyStored()
  152. isE = storage.getEnergyStored()
  153. input = storage.getInput()
  154. output = storage.getOutput()
  155. precent = math.floor(100 * isE / maxE)
  156. maxF = format(maxE)
  157. isF = format(isE)
  158. inF = format(input)
  159. outF = format(output)
  160. mon.setCursorPos(2,4)
  161. mon.write("Max:"..maxF)
  162. mon.setCursorPos(2,5)
  163. mon.write("Is: "..isF.." "..tostring(precent).."%")
  164. mon.setCursorPos(2,6)
  165. mon.write("In: "..inF)
  166. mon.setCursorPos(2,7)
  167. mon.write("Out:"..outF)
  168. start_x = 4
  169. max_lines = 19
  170. lines = math.floor(precent * max_lines / 100)
  171. yx = 28
  172. for lix = 1, lines do
  173. if lix > 6 then
  174. mon.setBackgroundColor(colors.green)
  175. elseif lix > 3 then
  176. mon.setBackgroundColor(colors.yellow)
  177. else
  178. mon.setBackgroundColor(colors.red)
  179. end
  180. mon.setCursorPos(start_x,(yx-lix))
  181. mon.write("      ")
  182. end
  183. mon.setBackgroundColor(colors.white)
  184. yy = 8
  185. start_x = 3
  186. for li = 1, 19 do
  187. mon.setCursorPos(start_x,(yy+li))
  188. mon.write("|")
  189. mon.setCursorPos((start_x+7),(yy+li))
  190. mon.write("|")
  191. end
  192. mon.setCursorPos(25,2)
  193. mon.write(reactorN)
  194. maxR = reactor.getMaxEnergyStored()
  195. isR = reactor.getEnergyStored()
  196. precentR = math.floor(100 * isR / maxR)
  197. maxFR = format(maxR)
  198. isFR = format(isR)
  199. mon.setCursorPos(25,4)
  200. mon.write("Max:"..maxFR)
  201. mon.setCursorPos(25,5)
  202. mon.write("Is: "..isFR.." "..tostring(precentR).."%")
  203. start_x = 27
  204. max_lines = 19
  205. lines = math.floor(precentR * max_lines / 100)
  206. yx = 28
  207. for lix = 1, lines do
  208. if lix > 6 then
  209. mon.setBackgroundColor(colors.green)
  210. elseif lix > 3 then
  211. mon.setBackgroundColor(colors.yellow)
  212. else
  213. mon.setBackgroundColor(colors.red)
  214. end
  215. mon.setCursorPos(start_x,(yx-lix))
  216. mon.write("      ")
  217. end
  218. mon.setBackgroundColor(colors.white)
  219. yy = 8
  220. start_x = 26
  221. for li = 1, 19 do
  222. mon.setCursorPos(start_x,(yy+li))
  223. mon.write("|")
  224. mon.setCursorPos((start_x+7),(yy+li))
  225. mon.write("|")
  226. end
  227. color = colors.red
  228. if B_reactor == 0 then
  229. color = colors.green
  230. end
  231. mon.setBackgroundColor(color)
  232. mon.setCursorPos(35,9)
  233. mon.write("               ")
  234. mon.setCursorPos(35,10)
  235. mon.write(" Reactor/Laser ")
  236. mon.setCursorPos(35,11)
  237. mon.write("    On / Off   ")
  238. mon.setCursorPos(35,12)
  239. mon.write("               ")
  240. color = colors.red
  241. if B_production == 0 then
  242. color = colors.green
  243. end
  244. mon.setBackgroundColor(color)
  245. mon.setCursorPos(35,14)
  246. mon.write("               ")
  247. mon.setCursorPos(35,15)
  248. mon.write(" DT Fuel Produc")
  249. mon.setCursorPos(35,16)
  250. mon.write("    On / Off   ")
  251. mon.setCursorPos(35,17)
  252. mon.write("               ")
  253. color = colors.red
  254. if B_load == 0 then
  255. color = colors.green
  256. end
  257. mon.setBackgroundColor(color)
  258. mon.setCursorPos(35,19)
  259. mon.write("               ")
  260. mon.setCursorPos(35,20)
  261. mon.write("   Load Laser  ")
  262. mon.setCursorPos(35,21)
  263. mon.write("    On / Off   ")
  264. mon.setCursorPos(35,22)
  265. mon.write("               ")
  266. color = colors.yellow
  267. mon.setBackgroundColor(color)
  268. mon.setCursorPos(35,24)
  269. mon.write("               ")
  270. mon.setCursorPos(35,25)
  271. mon.write("   Refresh     ")
  272. mon.setCursorPos(35,26)
  273. mon.write("               ")
  274. mon.setBackgroundColor(colors.green)
  275. mon.setCursorPos(11,14)
  276. mon.write("               ")
  277. mon.setCursorPos(11,15)
  278. mon.write("   Automatic   ")
  279. mon.setCursorPos(11,16)
  280. mon.write("     Start     ")
  281. mon.setCursorPos(11,17)
  282. mon.write("               ")
  283. mon.setBackgroundColor(colors.red)
  284. mon.setCursorPos(11,19)
  285. mon.write("               ")
  286. mon.setCursorPos(11,20)
  287. mon.write("   Automatic   ")
  288. mon.setCursorPos(11,21)
  289. mon.write("     Stop      ")
  290. mon.setCursorPos(11,22)
  291. mon.write("               ")
  292. touch()
  293. end
  294.  
  295. function touch()
  296. local ix = true
  297. while ix == true do
  298. event, side, x, y = os.pullEvent()
  299. if event == "monitor_touch" then
  300. if x == 50 and y == 1 then
  301. ix = false
  302. shell.run("clear")
  303. end
  304. if x > 34 and x < 50 and y == 24 or y == 25 or y == 26 then
  305. ix = false
  306. draw_screen()
  307. end
  308. if x > 10 and x < 26 and y > 13 and y < 18 then
  309. ix = false
  310. B_load = 1
  311. set_cable()
  312. mon.setBackgroundColor(colors.white)
  313. mon.setCursorPos(11,24)
  314. mon.write("Load Laser")
  315. mon.setCursorPos(11,25)
  316. mon.write("Please wait..")
  317. sleep(3)
  318. B_production = 1
  319. set_cable()
  320. mon.setCursorPos(11,25)
  321. mon.write("Fuel production")
  322. for i=300,1,-1 do
  323. mon.setCursorPos(11,26)
  324. mon.write(tostring(i).." seconds left")
  325. sleep(1)
  326. end
  327. B_chest = 1
  328. set_cable()
  329. sleep(2)
  330. B_chest = 0
  331. B_reactor = 1
  332. set_cable()
  333. mon.setCursorPos(11,26)
  334. mon.write("Start Reactor")
  335. sleep(3)
  336. draw_screen()
  337. end
  338. if x > 10 and x < 26 and y > 18 and y < 23 then
  339. ix = false
  340. B_reactor = 0
  341. B_production = 0
  342. B_load = 0
  343. set_cable()
  344. draw_screen()
  345. end
  346. if x > 34 and x < 50 and y == 9 or y == 10 or y == 11 or y == 12 then
  347. ix = false
  348. if B_reactor == 0 then
  349. B_reactor = 1
  350. else
  351. B_reactor = 0
  352. end
  353. set_cable()
  354. draw_screen()
  355. end
  356. if x > 34 and x < 50 and y == 14 or y == 15 or y == 16 or y == 17 then
  357. ix = false
  358. if B_production == 0 then
  359. B_production = 1
  360. else
  361. B_production = 0
  362. end
  363. set_cable()
  364. draw_screen()
  365. end
  366. if x > 34 and x < 50 and y == 19 or y == 20 or y == 21 or y == 22 then
  367. ix = false
  368. if B_load == 0 then
  369. B_load = 1
  370. else
  371. B_load = 0
  372. end
  373. set_cable()
  374. draw_screen()
  375. end
  376. end
  377. end
  378. end
  379.  
  380. --start program
  381. set_monitor()
  382. input_cable_side()
  383. search()
  384. local found = fs.exists("backup.db")
  385. if found == true then
  386. print("load backup")
  387. file = fs.open("backup.db","r")
  388. local fileData = {}
  389. local line = file.readLine()
  390. repeat
  391. table.insert(fileData,line)
  392. line = file.readLine()
  393. until line == nil
  394. file.close()
  395. B_reactor = tonumber(fileData[1])
  396. B_production = tonumber(fileData[2])
  397. B_load = tonumber(fileData[3])
  398. if  B_reactor == 1 and  B_production == 1 and B_load == 1 then
  399. B_reactor = 0
  400. set_cable()
  401. mon.setTextColor(colors.white)
  402. mon.setBackgroundColor(colors.black)
  403. mon.clear()
  404. mon.setCursorPos(1,1)
  405. mon.setTextColor(colors.white)
  406. mon.write("Please wait, load Laser for Reactor reboot")
  407. for i=300,1,-1 do
  408. mon.setCursorPos(1,2)
  409. mon.write(tostring(i).." seconds left")
  410. sleep(1)
  411. end
  412. B_chest = 1
  413. set_cable()
  414. sleep(2)
  415. B_chest = 0
  416. B_reactor = 1
  417. set_cable()
  418. sleep(1)
  419. end
  420. set_cable()
  421. end
  422. draw_screen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement