mrWhiskasss

testReactor

Aug 8th, 2025
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.06 KB | None | 0 0
  1. --[[opencomputers контроль реактора IC2(1.7.10) на конденсаторах
  2. pastebin.com/kxgfyM9 update 26.10.21
  3.  
  4. использовать только вместе с модом OpenPeripheral
  5. pastebin run YidCrWCG
  6. для проекта computercraft.ru
  7. https://computercraft.ru/topic/2604-programma-ochen-mnogo-elektrichestva
  8. авторы: Asior, serafim
  9.  
  10. требования:
  11. монитор и видеокарта 2-го уровня,
  12. адаптер, транспозер, контроллер красного камня.
  13.  
  14. пример сборки:
  15. https://i.imgur.com/eRb0iAx.png
  16. https://i.imgur.com/UqrFVkC.png
  17. https://i.imgur.com/y42OiO7.png
  18.  
  19. схема реактора:
  20. https://i.imgur.com/SXbeOu8.png
  21. https://i.imgur.com/OW27suK.png
  22.  
  23. использование:
  24. собрать установку, для плутония нагреть реактор до 8400 градусов,
  25. в сундук положить запасные конденсаторы и стержни,
  26. желательно обеспечить автокрафт перезарядки конденсаторов
  27. https://pastebin.com/WgcCKBFn
  28. ]]--
  29.  
  30. local offReac = 8500 --температура перегрева реактора до отключения
  31. local perDamage = 80 --процент износа конденсатора при котором он меняется
  32. local freshchestaddr = "080bc543-8f43-45e6-8e61-047435388f3c"
  33. local usedchestaddr = "6bf919cb-0585-4298-9870-ed5cded3c7c7"
  34.  
  35. local com = require("component")
  36. local computer = require("computer")
  37. local event = require("event")
  38. local gpu = com.gpu
  39. local w,h = gpu.getResolution()
  40. local per,noFuel,lowEu,toReac,run = 0,0,0,1,true
  41. local sideReac,sideInv,sideRed,OutputEUt,StartEUt
  42. local slotReac,Reflector = {},{}
  43.  
  44. function findSpecificChest(desiredAddress)
  45. -- Get list of all inventory components
  46. local invs = com.list("chest")
  47.  
  48. -- Check each one for address match
  49. for address, name in pairs(invs) do
  50. if address == desiredAddress then
  51. return com.proxy(address)
  52. end
  53. end
  54. return nil
  55. end
  56.  
  57. -- Example usage:
  58. local myChest = findSpecificChest(freshchestaddr)
  59. if myChest then
  60. print("Found our chest! Size: " .. myChest.getInventorySize())
  61. else
  62. print("Chest not found")
  63. end
  64.  
  65. if not findSpecificChest(freshchestaddr) then
  66. print("нет указанного сундака со свежими конденсаторами")
  67. os.exit()
  68. end
  69.  
  70. if not findSpecificChest(usedchestaddr) then
  71. print("нет указанного сундука для отработанных конденсаторов")
  72. os.exit()
  73. end
  74. --[[
  75. if not com.isAvailable("080bc543-8f43-45e6-8e61-047435388f3c") then
  76. print("нет сундука с свежими конденсаторами")
  77. print("использовать только вместе с модом OpenPeripheral")
  78. os.exit()
  79. end
  80. if not com.isAvailable("253fca85-88fa-4264-a865-94166d3521cc") then
  81. print("нет сундука для отработки")
  82. print("использовать только вместе с модом OpenPeripheral")
  83. os.exit()
  84. end
  85. ]]--
  86.  
  87.  
  88. --[[
  89. if not com.isAvailable("me_interface") then
  90. print("нет interface")
  91. print("использовать только вместе с модом OpenPeripheral")
  92. os.exit()
  93. end
  94. --]]
  95. local chest = findSpecificChest(freshchestaddr)
  96. local slotsInv = chest.getInventorySize()
  97.  
  98. local usedchest = findSpecificChest(usedchestaddr)
  99. local usedslotsInv = usedchest.getInventorySize()
  100.  
  101. --local interface = com.me_interface
  102.  
  103. if not com.isAvailable("redstone") then
  104. print("нет контроллера красного камня")
  105. os.exit()
  106. end
  107. local red = com.redstone
  108.  
  109. if not com.isAvailable("reactor_chamber") then
  110. print("камера реактора не найдена")
  111. os.exit()
  112. end
  113. local reactor = com.reactor_chamber
  114.  
  115. if reactor.producesEnergy() then
  116. print("\n".."остановите реактор !")
  117. for i = 0,5 do
  118. if red.getOutput(i) > 0 then
  119. red.setOutput(i, 0)
  120. end
  121. end
  122. os.exit()
  123. end
  124.  
  125. if reactor.getHeat() > offReac then
  126. print("\n".."перегрев реактора !")
  127. os.exit()
  128. end
  129.  
  130. os.execute("cls")
  131. print("сохранение конденсаторов")
  132. local data = reactor.getAllStacks(0)
  133. for i = 0,54 do
  134. if data[i] and data[i].name then
  135. if string.find(data[i].name,"ondensator") then
  136. local per = math.ceil(100*data[i].dmg/data[i].max_dmg)
  137. print("слот: "..(i).." износ: "..per.." %")
  138. if per >= perDamage then
  139. print("\n".."замените конденсатор в слоте: "..(i))
  140. os.exit()
  141. end
  142. table.insert(slotReac, i)
  143. end
  144. end
  145. end
  146. print("сохранение отражателей")
  147. for i = 0,54 do
  148. if data[i] and data[i].name then
  149. if string.find(data[i].name,"eflector") then
  150. print("слот: "..(i))
  151. table.insert(Reflector, i)
  152. end
  153. end
  154. end
  155.  
  156. print("пробный запуск")
  157. for k,n in pairs({3,2,4,5,0,1}) do
  158. red.setOutput(n, 15)
  159. os.sleep(1)
  160. if reactor.producesEnergy() then
  161. os.sleep(1)
  162. StartEUt = math.ceil(reactor.getReactorEUOutput())
  163. print("StartEUt = "..StartEUt)
  164. sideRed = n
  165. red.setOutput(n, 0)
  166. print("редстоун в стороне: "..sideRed)
  167. break
  168. else
  169. --os.sleep(1)
  170. red.setOutput(n, 0)
  171. end
  172. if k == 6 then
  173. print("\n".."реактор не запускается 6")
  174. os.exit()
  175. end
  176. end
  177.  
  178. print("настройка завершена".."\n".."старт...")
  179. os.sleep(2)
  180. -- ▀ ▄ █
  181. local function gui()
  182. gpu.setResolution(28,15)
  183. gpu.setBackground(0x696969)
  184. gpu.fill(1,1,28,15," ")
  185. gpu.setForeground(0x3C3C3C)
  186. gpu.set(1,1,"████████████████████████████")
  187. gpu.set(1,2,"█ █ █ █ █ █ █ █ █ █")
  188. gpu.setForeground(0x008000)
  189. gpu.set(2,2,"█")
  190. gpu.set(5,2,"█")
  191. gpu.set(8,2,"█")
  192. gpu.set(11,2,"█")
  193. gpu.set(14,2,"█")
  194. gpu.set(17,2,"█")
  195. gpu.set(20,2,"█")
  196. gpu.set(23,2,"█")
  197. gpu.set(26,2,"█")
  198. --
  199. gpu.setForeground(0x00ff00)
  200. gpu.set(3,2,"█")
  201. gpu.set(6,2,"█")
  202. gpu.set(9,2,"█")
  203. gpu.set(12,2,"█")
  204. gpu.set(15,2,"█")
  205. gpu.set(18,2,"█")
  206. gpu.set(21,2,"█")
  207. gpu.set(24,2,"█")
  208. gpu.set(27,2,"█")
  209. gpu.setForeground(0x3C3C3C)
  210. gpu.set(1,3,"████████████████████████████")
  211. gpu.set(1,4,"█ █ █ █ █ █ █ █ █ █")
  212. gpu.setForeground(0x008000)
  213. gpu.set(2,4,"█")
  214. gpu.set(5,4,"█")
  215. gpu.set(8,4,"█")
  216. gpu.set(11,4,"█")
  217. gpu.set(14,4,"█")
  218. gpu.set(17,4,"█")
  219. gpu.set(20,4,"█")
  220. gpu.set(23,4,"█")
  221. gpu.set(26,4,"█")
  222. --
  223. gpu.setForeground(0x00ff00)
  224. gpu.set(3,4,"█")
  225. gpu.set(6,4,"█")
  226. gpu.set(9,4,"█")
  227. gpu.set(12,4,"█")
  228. gpu.set(15,4,"█")
  229. gpu.set(18,4,"█")
  230. gpu.set(21,4,"█")
  231. gpu.set(24,4,"█")
  232. gpu.set(27,4,"█")
  233. gpu.setForeground(0x3C3C3C)
  234. gpu.set(1,5,"████████████████████████████")
  235. gpu.set(1,6,"█ █ █ █ █ █ █ █ █ █")
  236. gpu.setForeground(0x008000)
  237. gpu.set(2,6,"█")
  238. gpu.set(5,6,"█")
  239. gpu.set(8,6,"█")
  240. gpu.set(11,6,"█")
  241. gpu.set(14,6,"█")
  242. gpu.set(17,6,"█")
  243. gpu.set(20,6,"█")
  244. gpu.set(23,6,"█")
  245. gpu.set(26,6,"█")
  246. --
  247. gpu.setForeground(0x00ff00)
  248. gpu.set(3,6,"█")
  249. gpu.set(6,6,"█")
  250. gpu.set(9,6,"█")
  251. gpu.set(12,6,"█")
  252. gpu.set(15,6,"█")
  253. gpu.set(18,6,"█")
  254. gpu.set(21,6,"█")
  255. gpu.set(24,6,"█")
  256. gpu.set(27,6,"█")
  257. gpu.setForeground(0x3C3C3C)
  258. gpu.set(1,7,"████████████████████████████")
  259. gpu.set(1,8,"█ █ █ █ █ █ █ █ █ █")
  260. gpu.setForeground(0x008000)
  261. gpu.set(2,8,"█")
  262. gpu.set(5,8,"█")
  263. gpu.set(8,8,"█")
  264. gpu.set(11,8,"█")
  265. gpu.set(14,8,"█")
  266. gpu.set(17,8,"█")
  267. gpu.set(20,8,"█")
  268. gpu.set(23,8,"█")
  269. gpu.set(26,8,"█")
  270. --
  271. gpu.setForeground(0x00ff00)
  272. gpu.set(3,8,"█")
  273. gpu.set(6,8,"█")
  274. gpu.set(9,8,"█")
  275. gpu.set(12,8,"█")
  276. gpu.set(15,8,"█")
  277. gpu.set(18,8,"█")
  278. gpu.set(21,8,"█")
  279. gpu.set(24,8,"█")
  280. gpu.set(27,8,"█")
  281. gpu.setForeground(0x3C3C3C)
  282. gpu.set(1,9,"████████████████████████████")
  283. gpu.set(1,10,"█ █ █ █ █ █ █ █ █ █")
  284. gpu.setForeground(0x008000)
  285. gpu.set(2,10,"█")
  286. gpu.set(5,10,"█")
  287. gpu.set(8,10,"█")
  288. gpu.set(11,10,"█")
  289. gpu.set(14,10,"█")
  290. gpu.set(17,10,"█")
  291. gpu.set(20,10,"█")
  292. gpu.set(23,10,"█")
  293. gpu.set(26,10,"█")
  294. --
  295. gpu.setForeground(0x00ff00)
  296. gpu.set(3,10,"█")
  297. gpu.set(6,10,"█")
  298. gpu.set(9,10,"█")
  299. gpu.set(12,10,"█")
  300. gpu.set(15,10,"█")
  301. gpu.set(18,10,"█")
  302. gpu.set(21,10,"█")
  303. gpu.set(24,10,"█")
  304. gpu.set(27,10,"█")
  305. gpu.setForeground(0x3C3C3C)
  306. gpu.set(1,7,"████████████████████████████")
  307. gpu.set(1,8,"█ █ █ █ █ █ █ █ █ █")
  308. gpu.setForeground(0x008000)
  309. gpu.set(2,8,"█")
  310. gpu.set(5,8,"█")
  311. gpu.set(8,8,"█")
  312. gpu.set(11,8,"█")
  313. gpu.set(14,8,"█")
  314. gpu.set(17,8,"█")
  315. gpu.set(20,8,"█")
  316. gpu.set(23,8,"█")
  317. gpu.set(26,8,"█")
  318. --
  319. gpu.setForeground(0x00ff00)
  320. gpu.set(3,8,"█")
  321. gpu.set(6,8,"█")
  322. gpu.set(9,8,"█")
  323. gpu.set(12,8,"█")
  324. gpu.set(15,8,"█")
  325. gpu.set(18,8,"█")
  326. gpu.set(21,8,"█")
  327. gpu.set(24,8,"█")
  328. gpu.set(27,8,"█")
  329. gpu.setForeground(0x3C3C3C)
  330. gpu.set(1,9,"████████████████████████████")
  331. gpu.set(1,10,"█ █ █ █ █ █ █ █ █ █")
  332. gpu.setForeground(0x008000)
  333. gpu.set(2,10,"█")
  334. gpu.set(5,10,"█")
  335. gpu.set(8,10,"█")
  336. gpu.set(11,10,"█")
  337. gpu.set(14,10,"█")
  338. gpu.set(17,10,"█")
  339. gpu.set(20,10,"█")
  340. gpu.set(23,10,"█")
  341. gpu.set(26,10,"█")
  342. --
  343. gpu.setForeground(0x00ff00)
  344. gpu.set(3,10,"█")
  345. gpu.set(6,10,"█")
  346. gpu.set(9,10,"█")
  347. gpu.set(12,10,"█")
  348. gpu.set(15,10,"█")
  349. gpu.set(18,10,"█")
  350. gpu.set(21,10,"█")
  351. gpu.set(24,10,"█")
  352. gpu.set(27,10,"█")
  353. gpu.setForeground(0x3C3C3C)
  354. gpu.set(1,11,"████████████████████████████")
  355. gpu.set(1,12,"█ █ █ █ █ █ █ █ █ █")
  356. gpu.setForeground(0x008000)
  357. gpu.set(2,12,"█")
  358. gpu.set(5,12,"█")
  359. gpu.set(8,12,"█")
  360. gpu.set(11,12,"█")
  361. gpu.set(14,12,"█")
  362. gpu.set(17,12,"█")
  363. gpu.set(20,12,"█")
  364. gpu.set(23,12,"█")
  365. gpu.set(26,12,"█")
  366. --
  367. gpu.setForeground(0x00ff00)
  368. gpu.set(3,12,"█")
  369. gpu.set(6,12,"█")
  370. gpu.set(9,12,"█")
  371. gpu.set(12,12,"█")
  372. gpu.set(15,12,"█")
  373. gpu.set(18,12,"█")
  374. gpu.set(21,12,"█")
  375. gpu.set(24,12,"█")
  376. gpu.set(27,12,"█")
  377. gpu.setForeground(0x3C3C3C)
  378. gpu.set(1,13,"████████████████████████████")
  379. end
  380.  
  381. local xy = {
  382. {"2","2"},{"5","2"},{"8","2"},{"11","2"},{"14","2"},{"17","2"},{"20","2"},{"23","2"},{"26","2"},
  383. {"2","4"},{"5","4"},{"8","4"},{"11","4"},{"14","4"},{"17","4"},{"20","4"},{"23","4"},{"26","4"},
  384. {"2","6"},{"5","6"},{"8","6"},{"11","6"},{"14","6"},{"17","6"},{"20","6"},{"23","6"},{"26","6"},
  385. {"2","8"},{"5","8"},{"8","8"},{"11","8"},{"14","8"},{"17","8"},{"20","8"},{"23","8"},{"26","8"},
  386. {"2","10"},{"5","10"},{"8","10"},{"11","10"},{"14","10"},{"17","10"},{"20","10"},{"23","10"},{"26","10"},
  387. {"2","12"},{"5","12"},{"8","12"},{"11","12"},{"14","12"},{"17","12"},{"20","12"},{"23","12"},{"26","12"},
  388. }
  389.  
  390. local function stop(wait)
  391. gpu.setBackground(0x000000)
  392. local e = ({event.pull(wait,"key_down")})[4]
  393. if e == 18 or e == 20 then
  394. red.setOutput(sideRed, 0)
  395. gpu.setResolution(w, h)
  396. gpu.setBackground(0x000000)
  397. gpu.setForeground(0xFFFFFF)
  398. gpu.fill(1, 1, w, h, " ")
  399. print("программа завершена")
  400. os.sleep(1)
  401. if reactor.producesEnergy() then
  402. print("ВНИМАНИЕ реактор по прежнему активен !!!")
  403. else
  404. print("реактор остановлен")
  405. end
  406. run = false
  407. end
  408. gpu.setBackground(0x696969)
  409. end
  410.  
  411. local function alert(message)
  412. gpu.setBackground(0x000000)
  413. gpu.setForeground(0xFF9900)
  414. gpu.set(1,14," для завершения нажмите E ")
  415. gpu.setForeground(0xFF0000)
  416. gpu.set(1,15,message)
  417. computer.beep(500, 1)
  418. stop(3)
  419. gpu.setBackground(0x696969)
  420. end
  421.  
  422. local function ReactorControl()
  423. local function redstone(state)
  424. if state then
  425. red.setOutput(sideRed, 15)
  426. else
  427. while red.getOutput(sideRed) > 0 or reactor.getReactorEUOutput() > 0 do
  428. red.setOutput(sideRed, 0)
  429. os.sleep(0.2)
  430. end
  431. gpu.setBackground(0x000000)
  432. gpu.setForeground(0x00FF00)
  433. gpu.set(1,14," eu/t = 0 ")
  434. gpu.setBackground(0x696969)
  435. end
  436. end
  437. local data = reactor.getAllStacks(0)
  438. for i = 1,#slotReac do
  439. if data[slotReac[i]] then
  440. per = math.ceil(100*data[slotReac[i]].dmg/data[slotReac[i]].max_dmg)
  441. gpu.setForeground(0xFF9900)
  442. gpu.set(tonumber(xy[slotReac[i]][1]),tonumber(xy[slotReac[i]][2]),tostring(per))
  443. else
  444. per = 0
  445. end
  446. if per == 100 then
  447. gpu.setBackground(0x000000)
  448. redstone(false)
  449. alert(" снизте % замены конденсат. ")
  450. while run do
  451. computer.beep(500, 1)
  452. stop(3)
  453. gpu.setBackground(0x696969)
  454. end
  455. os.exit()
  456. end
  457. if per >= perDamage or per == 0 then
  458. gpu.setBackground(0x000000)
  459. gpu.setForeground(0xFF9900)
  460. gpu.set(1,15," замена конденсаторов ")
  461. gpu.setBackground(0x696969)
  462. redstone(false)
  463. usedchest.pullItem("DOWN",slotReac[i])
  464. gpu.setForeground(0xFF0000)
  465. gpu.set(tonumber(xy[slotReac[i]][1]),tonumber(xy[slotReac[i]][2]),"██")
  466. local data1 = chest.getAllStacks(0)
  467. for i1 = 1,slotsInv do
  468. if data1[i1] and data1[i1].name then
  469. local per = math.ceil(100*data1[i1].dmg/data1[i1].max_dmg)
  470. if string.find(data1[i1].name,"ondensator") and per < 90 then
  471. toReac = chest.pushItemIntoSlot("DOWN",i1,1,slotReac[i])
  472. if toReac then
  473. gpu.setForeground(0x696969)
  474. gpu.setBackground(0x696969)
  475. gpu.set(tonumber(xy[slotReac[i]][1]),tonumber(xy[slotReac[i]][2]),"██")
  476. end
  477. break
  478. else
  479. toReac = 0
  480. end
  481. end
  482. end
  483. end
  484. end
  485. local function circuitCheck()
  486.  
  487. local data = reactor.getAllStacks(0)
  488. local sh = 0
  489. for i = 1,#slotReac do
  490. if data[slotReac[i]] then
  491. sh = sh + 1
  492. end
  493. end
  494. if sh == #slotReac then
  495. return true
  496. else
  497. return false
  498. end
  499. end
  500. gpu.setBackground(0x000000)
  501. if reactor.getHeat() > offReac then
  502. redstone(false)
  503. alert(" перегрев реактора ! ")
  504. elseif not circuitCheck() then
  505. alert(" нет целых конденсаторов ! ")
  506. elseif toReac == 0 then
  507. alert(" в сундуке нет места ! ")
  508. elseif noFuel >= 5 then
  509. alert(" нет топлива ! ")
  510. else
  511. redstone(true)
  512. os.sleep(1)
  513. if not reactor.producesEnergy() then
  514. alert(" реактор не запускается ! ")
  515. else
  516. OutputEUt = math.ceil(reactor.getReactorEUOutput())
  517.  
  518. gpu.set(1,14," eu/t = "..OutputEUt.." ")
  519. gpu.set(1,15," реактор активен ")
  520. end
  521. end
  522. stop(0.7)
  523. gpu.setBackground(0x696969)
  524. if reactor.producesEnergy() and reactor.getReactorEUOutput() == 0 then
  525. noFuel = noFuel + 1
  526. else
  527. noFuel = 0
  528. if OutputEUt and OutputEUt < StartEUt then
  529. lowEu = lowEu + 1
  530. else
  531. lowEu = 0
  532. end
  533. end
  534. gpu.setBackground(0x000000)
  535. if noFuel == 3 or lowEu == 3 then
  536. local data2 = reactor.getAllStacks(0)
  537. local data3 = chest.getAllStacks(0)
  538. for i2 = 1,54 do
  539. if data2[i2] and data2[i2].name then
  540. if string.find(data2[i2].name,"Near-depleted Uranium Cell") or string.find(data2[i2].name,"Near-depleted Uranium Cell") then
  541. redstone(false)
  542. gpu.setForeground(0xFF9900)
  543. gpu.set(1,15," замена стержней ")
  544. usedchest.pullItem("DOWN",i2)
  545. for i3 = 0,slotsInv do
  546. if data3[i3] and data3[i3].name then
  547. if string.find(data3[i3].name,"Uranium Cell") or string.find(data3[i3].name,"Uranium Cell") then
  548. if not string.find(data3[i3].name,"depleted") then
  549. chest.pushItemIntoSlot("DOWN",i3,1,i2)
  550. break
  551. end
  552. end
  553. end
  554. end
  555. end
  556. end
  557. end
  558. StartEUt = 0
  559. lowEu = 0
  560. for i4 = 1,#Reflector do
  561. if not data2[Reflector[i4]] then
  562. for i5 = 0,slotsInv do
  563. if data3[i5] and data3[i5].name then
  564. if string.find(data3[i5].name,"eflector") then
  565. redstone(false)
  566. gpu.setForeground(0xFF9900)
  567. gpu.set(1,15," замена отражателя ")
  568. chest.pushItemIntoSlot("DOWN",i5,1,Reflector[i4])
  569. end
  570. end
  571. end
  572. end
  573. end
  574. end
  575. gpu.setBackground(0x696969)
  576. if OutputEUt and OutputEUt > StartEUt then
  577. StartEUt = math.ceil(reactor.getReactorEUOutput())
  578. end
  579. end
  580.  
  581. gui()
  582. gpu.setBackground(0x000000)
  583. gpu.setForeground(0xFF9900)
  584. gpu.set(1,14," для завершения нажмите E ")
  585. gpu.setBackground(0x696969)
  586. os.sleep(1)
  587. while run do
  588. local ok,err = pcall(ReactorControl)
  589. if not ok then
  590. red.setOutput(sideRed, 0)
  591. gpu.setResolution(w, h)
  592. gpu.setBackground(0x000000)
  593. gpu.setForeground(0xFFFFFF)
  594. os.execute("cls")
  595. print("программа аварийно завершена")
  596. if type(err) == "table" then
  597. io.stderr:write(table.unpack(err))
  598. else
  599. io.stderr:write(err)
  600. end
  601. run = false
  602. end
  603. end
Advertisement
Add Comment
Please, Sign In to add comment