BigBlow_

FusionReactorMonitorLejiww

Mar 22nd, 2025
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.10 KB | None | 0 0
  1. -- Configuration
  2. local reactor_name = "fusionReactorLogicAdapter_1" -- Name of the reactor peripheral
  3. local alarm_side = "top" -- Face to send redstone if reactor is off
  4. local alarm_side2 = "left" -- Additional face to send redstone when reactor is off
  5. local start_side = "back" -- Face to send pulse to start the reactor (changed to right by default)
  6. local redstone_pulse_time = 1 -- Duration of the pulse in seconds
  7.  
  8. -- Startup animation for console
  9. local function showStartupAnimation()
  10. term.clear()
  11. term.setCursorPos(1,1)
  12.  
  13. print(" Fusion Reactor Controler by Le_Jiww")
  14. print(" [Developed for my bro: BigBlow]")
  15. print("")
  16.  
  17. -- Loading animation
  18. io.write(" System initialization")
  19. for i = 1, 5 do
  20. io.write(".")
  21. sleep(0.2)
  22. end
  23. print("\n")
  24. sleep(0.5)
  25.  
  26. -- Display startup information
  27. print(" > Connecting to fusion reactor...")
  28. sleep(0.3)
  29. print(" > Initializing monitor...")
  30. sleep(0.3)
  31. print(" > Configuring redstone signals...")
  32. sleep(0.5)
  33. print("\n [SYSTEM READY]")
  34. print("\n Reactor monitoring in progress...\n")
  35. end
  36.  
  37. -- Execute startup animation
  38. showStartupAnimation()
  39.  
  40. -- Monitor initialization
  41. local monitor = peripheral.find("monitor")
  42. if not monitor then
  43. error("No monitor detected")
  44. end
  45.  
  46. -- Get screen dimensions
  47. local screen_width, screen_height = monitor.getSize()
  48.  
  49. -- Reactor initialization
  50. local reactor = peripheral.wrap(reactor_name)
  51. if not reactor then
  52. error("Reactor not detected: " .. reactor_name)
  53. end
  54. monitor.clear()
  55. monitor.setTextScale(1)
  56. monitor.setTextColor(colors.white)
  57.  
  58. -- Button coordinates (adjusted for better central position)
  59. local button_x1, button_y1 = 12, 12 -- Center position and lower down
  60. local button_x2, button_y2 = 28, 15
  61.  
  62. -- Tracking variables
  63. local last_ignited = nil
  64. local ignition_in_progress = false -- Prevents double sending the signal
  65. local animation_frame = 0
  66. local pulse_animation = 0 -- Pulsing animation for activity indicator
  67. local rotation_animation = 0 -- Rotation animation for activity indicator
  68.  
  69. -- Function to format numbers with spaces
  70. local function formatNumber(n)
  71. return tostring(n):reverse():gsub("(%d%d%d)", "%1 "):reverse():gsub("^ ", "")
  72. end
  73.  
  74. -- Function to format large numbers with K, M, G, etc.
  75. local function formatCompact(n)
  76. if n >= 1000000000 then
  77. return string.format("%.2fG", n / 1000000000)
  78. elseif n >= 1000000 then
  79. return string.format("%.2fM", n / 1000000)
  80. elseif n >= 1000 then
  81. return string.format("%.2fK", n / 1000)
  82. else
  83. return string.format("%.1f", n)
  84. end
  85. end
  86.  
  87. -- Characters for rotation animation
  88. local rotation_chars = {"|", "/", "-", "\\"}
  89.  
  90. -- Function to update only the values (without redrawing the frames)
  91. local function updateReactorValues()
  92. if not reactor.isIgnited() then return end
  93.  
  94. -- Get reactor data
  95. local production = reactor.getProductionRate()
  96. local productionRF = production / 2.5
  97.  
  98. -- Variables for additional data
  99. local plasmaTemp, caseTemp, injectionRate, efficiency, fuel = nil, nil, nil, nil, nil
  100.  
  101. -- Try to get plasma temperature
  102. local success, result = pcall(function() return reactor.getPlasmaTemperature() end)
  103. if success and result then plasmaTemp = result end
  104.  
  105. -- Try to get case temperature
  106. success, result = pcall(function() return reactor.getCaseTemperature() end)
  107. if success and result then caseTemp = result end
  108.  
  109. -- Try to get injection rate
  110. success, result = pcall(function() return reactor.getInjectionRate() end)
  111. if success and result then injectionRate = result end
  112.  
  113. -- Try to get efficiency
  114. success, result = pcall(function() return reactor.getEfficiency() end)
  115. if success and result then
  116. efficiency = result
  117. else
  118. efficiency = math.min(98.5, 50 + productionRF / 50000)
  119. end
  120.  
  121. -- Try to get fuel
  122. success, result = pcall(function() return reactor.getFuel() end)
  123. if success and result then fuel = result end
  124.  
  125. -- Update values only (not labels)
  126. monitor.setBackgroundColor(colors.black)
  127.  
  128. -- Update activity indicator (rotation animation)
  129. rotation_animation = (rotation_animation + 1) % 4
  130. local rotation_char = rotation_chars[rotation_animation + 1]
  131.  
  132. monitor.setCursorPos(screen_width - 4, 2)
  133. monitor.setTextColor(colors.lime)
  134. monitor.write(rotation_char)
  135.  
  136. -- 1. Energy production (update value only with slight variation for animation)
  137. local variation = math.random(-15, 15) / 10 -- Random variation of ±1.5%
  138. local displayedRF = productionRF * (1 + variation/100)
  139.  
  140. monitor.setCursorPos(20, 10)
  141. monitor.setTextColor(colors.yellow)
  142. monitor.write(formatCompact(displayedRF).." RF/t ")
  143.  
  144. -- 2. Efficiency (update value only with slight variation)
  145. local effVariation = math.random(-2, 2) / 10 -- Random variation of ±0.2%
  146. local displayedEff = efficiency + effVariation
  147.  
  148. monitor.setCursorPos(20, 11)
  149. monitor.setTextColor(colors.yellow)
  150. monitor.write(string.format("%.1f%% ", displayedEff))
  151.  
  152. -- Efficiency bar animation (pulsation)
  153. local bar_length = 18
  154. pulse_animation = (pulse_animation + 0.2) % 10
  155. local pulse_factor = 1 + math.sin(pulse_animation) * 0.05 -- Pulsing variation of ±5%
  156. local bar_progress = math.min(1, (productionRF * pulse_factor) / 1000000)
  157. local filled_length = math.floor(bar_progress * bar_length)
  158.  
  159. monitor.setCursorPos(13, 12)
  160. for i = 1, bar_length do
  161. if i <= filled_length then
  162. if i >= bar_length - 1 and pulse_animation > 5 then
  163. monitor.setBackgroundColor(colors.yellow) -- Flashing overload effect
  164. else
  165. monitor.setBackgroundColor(colors.lime)
  166. end
  167. monitor.write(" ")
  168. else
  169. monitor.setBackgroundColor(colors.gray)
  170. monitor.write(" ")
  171. end
  172. end
  173. monitor.setBackgroundColor(colors.black)
  174.  
  175. -- 3. Plasma temperature (if available, with animation)
  176. if plasmaTemp then
  177. local tempVariation = math.random(-50, 50) / 10 -- Random variation of ±5
  178. local displayedTemp = plasmaTemp / 1000000 + tempVariation/100
  179.  
  180. monitor.setCursorPos(20, 13)
  181. monitor.setTextColor(colors.orange)
  182. monitor.write(string.format("%.2f MK ", displayedTemp))
  183. end
  184.  
  185. -- 4. Injection rate (if available, with slight variation)
  186. if injectionRate then
  187. local injVariation = math.random(-5, 5) -- Random variation of ±5
  188. monitor.setCursorPos(20, 14)
  189. monitor.setTextColor(colors.yellow)
  190. monitor.write(string.format("%d mB/t ", injectionRate + injVariation))
  191. end
  192.  
  193. -- 5. Fuel (if available, with simulated consumption)
  194. if fuel then
  195. monitor.setCursorPos(20, 15)
  196. monitor.setTextColor(colors.yellow)
  197. monitor.write(string.format("%d mB ", fuel))
  198. end
  199.  
  200. -- Reset colors
  201. monitor.setBackgroundColor(colors.black)
  202. monitor.setTextColor(colors.white)
  203. end
  204.  
  205. -- Definition of characters for borders
  206. local h_line = "\140" -- Horizontal line
  207. local v_line = "\149" -- Vertical line
  208. local tl_corner = "\151" -- Top left corner
  209. local tr_corner = "\152" -- Top right corner
  210. local bl_corner = "\154" -- Bottom left corner
  211. local br_corner = "\153" -- Bottom right corner
  212.  
  213. -- Function to draw a box with border
  214. local function drawBox(x1, y1, x2, y2, bg_color, border_color)
  215. monitor.setBackgroundColor(bg_color or colors.black)
  216. monitor.setTextColor(border_color or colors.cyan)
  217.  
  218. -- Corners
  219. monitor.setCursorPos(x1, y1)
  220. monitor.write(tl_corner)
  221. monitor.setCursorPos(x2, y1)
  222. monitor.write(tr_corner)
  223. monitor.setCursorPos(x1, y2)
  224. monitor.write(bl_corner)
  225. monitor.setCursorPos(x2, y2)
  226. monitor.write(br_corner)
  227.  
  228. -- Horizontal lines
  229. for x = x1 + 1, x2 - 1 do
  230. monitor.setCursorPos(x, y1)
  231. monitor.write(h_line)
  232. monitor.setCursorPos(x, y2)
  233. monitor.write(h_line)
  234. end
  235.  
  236. -- Vertical lines
  237. for y = y1 + 1, y2 - 1 do
  238. monitor.setCursorPos(x1, y)
  239. monitor.write(v_line)
  240. monitor.setCursorPos(x2, y)
  241. monitor.write(v_line)
  242. end
  243.  
  244. -- Interior
  245. monitor.setBackgroundColor(bg_color or colors.black)
  246. for y = y1 + 1, y2 - 1 do
  247. monitor.setCursorPos(x1 + 1, y)
  248. for x = x1 + 1, x2 - 1 do
  249. monitor.write(" ")
  250. end
  251. end
  252. end
  253.  
  254. -- Function to draw a centered title in a box
  255. local function drawTitle(text, x1, x2, y, color)
  256. local width = x2 - x1 - 1
  257. local text_x = x1 + math.floor((width - #text) / 2) + 1
  258.  
  259. monitor.setTextColor(color or colors.yellow)
  260. monitor.setCursorPos(text_x, y)
  261. monitor.write(text)
  262. monitor.setTextColor(colors.white)
  263. end
  264.  
  265. -- Function to display information
  266. local function displayInfo()
  267. local ignited = reactor.isIgnited()
  268. local should_redraw = (last_ignited ~= ignited) or (not last_ignited)
  269.  
  270. -- Only animate the status icon, not the entire screen
  271. animation_frame = (animation_frame + 1) % 8
  272.  
  273. -- Avoid redrawing the entire screen each time
  274. if not should_redraw then
  275. -- Selective update for animated elements only
  276. if ignited then
  277. -- Update only the flashing status with a more visible animation
  278. monitor.setCursorPos(13, 5)
  279. if animation_frame < 4 then
  280. monitor.setTextColor(colors.lime)
  281. monitor.write("IGNITED ")
  282. monitor.setTextColor(colors.yellow)
  283. monitor.write("*")
  284. else
  285. monitor.setTextColor(colors.green)
  286. monitor.write("IGNITED ")
  287. monitor.setTextColor(colors.orange)
  288. monitor.write("+")
  289. end
  290.  
  291. -- Rotation animation in the upper right corner
  292. monitor.setCursorPos(screen_width - 4, 2)
  293. monitor.setTextColor(colors.lime)
  294. monitor.write(rotation_chars[(rotation_animation + 1) % 4 + 1])
  295.  
  296. -- Update data without clearing the entire screen
  297. updateReactorValues()
  298. return
  299. end
  300. end
  301.  
  302. -- Otherwise, redraw the entire screen
  303. monitor.clear()
  304.  
  305. -- Big frame surrounding the entire screen
  306. drawBox(1, 1, screen_width, screen_height, colors.black, colors.blue)
  307.  
  308. -- Title at the top with styling
  309. drawTitle("FUSION REACTOR CONTROL", 1, screen_width, 2, colors.yellow)
  310.  
  311. -- Rotation animation in the upper right corner (program activity indicator)
  312. monitor.setCursorPos(screen_width - 4, 2)
  313. monitor.setTextColor(colors.lime)
  314. monitor.write(rotation_chars[(animation_frame % 4) + 1])
  315.  
  316. -- Status box
  317. drawBox(3, 4, screen_width - 3, 6, colors.black, colors.cyan)
  318. drawTitle("REACTOR STATUS", 3, screen_width - 3, 4, colors.white)
  319.  
  320. monitor.setCursorPos(5, 5)
  321. monitor.write("Status:")
  322.  
  323. monitor.setCursorPos(13, 5)
  324. if ignited then
  325. -- Flashing animation for "IGNITED"
  326. if animation_frame < 4 then
  327. monitor.setTextColor(colors.lime)
  328. monitor.write("IGNITED ")
  329. monitor.setTextColor(colors.yellow)
  330. monitor.write("*")
  331. else
  332. monitor.setTextColor(colors.green)
  333. monitor.write("IGNITED ")
  334. monitor.setTextColor(colors.orange)
  335. monitor.write("+")
  336. end
  337. redstone.setOutput(alarm_side, false) -- Disable redstone on primary face
  338. redstone.setOutput(alarm_side2, false) -- Disable redstone on secondary face
  339. ignition_in_progress = false -- Reset state after ignition
  340. else
  341. monitor.setTextColor(colors.red)
  342. monitor.write("STOPPED")
  343. redstone.setOutput(alarm_side, true) -- Enable redstone on primary face
  344. redstone.setOutput(alarm_side2, true) -- Enable redstone on secondary face
  345. end
  346.  
  347. -- Reset color to white
  348. monitor.setTextColor(colors.white)
  349.  
  350. if ignited then
  351. -- Energy production box
  352. drawBox(3, 8, screen_width - 3, 16, colors.black, colors.cyan)
  353. monitor.setTextColor(colors.white)
  354. drawTitle("REACTOR TELEMETRY", 3, screen_width - 3, 8, colors.white)
  355.  
  356. -- Get reactor data
  357. local production = reactor.getProductionRate()
  358. local productionRF = production / 2.5 -- Convert J to RF
  359.  
  360. -- Let's try to get additional data (with error protection)
  361. local plasmaTemp, caseTemp, injectionRate, efficiency, fuel = nil, nil, nil, nil, nil
  362.  
  363. -- Try to get temperature (may not be available depending on version)
  364. local success, result = pcall(function() return reactor.getPlasmaTemperature() end)
  365. if success and result then plasmaTemp = result end
  366.  
  367. -- Try to get case temperature
  368. success, result = pcall(function() return reactor.getCaseTemperature() end)
  369. if success and result then caseTemp = result end
  370.  
  371. -- Try to get injection rate
  372. success, result = pcall(function() return reactor.getInjectionRate() end)
  373. if success and result then injectionRate = result end
  374.  
  375. -- Try to get efficiency
  376. success, result = pcall(function() return reactor.getEfficiency() end)
  377. if success and result then
  378. efficiency = result
  379. else
  380. -- Simulate an efficiency value based on production
  381. efficiency = math.min(98.5, 50 + productionRF / 50000)
  382. end
  383.  
  384. -- Try to get fuel
  385. success, result = pcall(function() return reactor.getFuel() end)
  386. if success and result then fuel = result end
  387.  
  388. -- Display data
  389. local line = 0
  390.  
  391. -- 1. Energy production (with slight variation for animation)
  392. line = 10
  393. monitor.setCursorPos(5, line)
  394. monitor.write("Generation:")
  395. monitor.setCursorPos(20, line)
  396. monitor.setTextColor(colors.yellow)
  397. -- Add a slight variation to give the impression of change
  398. local variation = math.random(-15, 15) / 10 -- Random variation of ±1.5%
  399. local displayedRF = productionRF * (1 + variation/100)
  400. monitor.write(formatCompact(displayedRF).." RF/t")
  401.  
  402. -- 2. Efficiency (with slight variation)
  403. line = 11
  404. monitor.setCursorPos(5, line)
  405. monitor.setTextColor(colors.white)
  406. monitor.write("Efficiency:")
  407. monitor.setCursorPos(20, line)
  408. monitor.setTextColor(colors.yellow)
  409. local effVariation = math.random(-2, 2) / 10 -- Random variation of ±0.2%
  410. monitor.write(string.format("%.1f%%", efficiency + effVariation))
  411.  
  412. -- Visual production bar (with pulsation effect)
  413. line = 12
  414. monitor.setCursorPos(5, line)
  415. monitor.setTextColor(colors.white)
  416. monitor.write("Output:")
  417.  
  418. local bar_length = 18
  419. pulse_animation = (pulse_animation + 0.2) % 10
  420. local pulse_factor = 1 + math.sin(pulse_animation) * 0.05 -- Pulsing variation of ±5%
  421. local bar_progress = math.min(1, (productionRF * pulse_factor) / 1000000) -- Scale to adjust
  422. local filled_length = math.floor(bar_progress * bar_length)
  423.  
  424. monitor.setCursorPos(13, line)
  425. for i = 1, bar_length do
  426. if i <= filled_length then
  427. if i >= bar_length - 1 and pulse_animation > 5 then
  428. monitor.setBackgroundColor(colors.yellow) -- Flashing overload effect
  429. else
  430. monitor.setBackgroundColor(colors.lime)
  431. end
  432. monitor.write(" ")
  433. else
  434. monitor.setBackgroundColor(colors.gray)
  435. monitor.write(" ")
  436. end
  437. end
  438. monitor.setBackgroundColor(colors.black)
  439.  
  440. -- 3. Plasma temperature (if available, with animation)
  441. if plasmaTemp then
  442. line = 13
  443. monitor.setCursorPos(5, line)
  444. monitor.setTextColor(colors.white)
  445. monitor.write("Plasma Temp:")
  446. monitor.setCursorPos(20, line)
  447. monitor.setTextColor(colors.orange)
  448. -- Add a variation to show that it changes
  449. local tempVariation = math.random(-50, 50) / 10 -- Random variation of ±5
  450. monitor.write(string.format("%.2f MK", plasmaTemp / 1000000 + tempVariation/100))
  451. end
  452.  
  453. -- 4. Injection rate (if available, with slight variation)
  454. if injectionRate then
  455. line = 14
  456. monitor.setCursorPos(5, line)
  457. monitor.setTextColor(colors.white)
  458. monitor.write("Inj. Rate:")
  459. monitor.setCursorPos(20, line)
  460. monitor.setTextColor(colors.yellow)
  461. local injVariation = math.random(-5, 5) -- Random variation of ±5
  462. monitor.write(string.format("%d mB/t", injectionRate + injVariation))
  463. end
  464.  
  465. -- 5. Fuel (if available, with simulated consumption)
  466. if fuel then
  467. line = 15
  468. monitor.setCursorPos(5, line)
  469. monitor.setTextColor(colors.white)
  470. monitor.write("Fuel:")
  471. monitor.setCursorPos(20, line)
  472. monitor.setTextColor(colors.yellow)
  473. monitor.write(string.format("%d mB", fuel))
  474. end
  475. else
  476. if ignition_in_progress then
  477. -- Information box during ignition with improved animation
  478. drawBox(3, 8, screen_width - 3, 15, colors.black, colors.cyan)
  479. drawTitle("IGNITION SEQUENCE", 3, screen_width - 3, 8, colors.white)
  480.  
  481. -- More elaborate "Loading" animation with progress bars
  482. local progress_chars = {"[= ]", "[== ]", "[=== ]", "[==== ]",
  483. "[===== ]", "[====== ]", "[=======]", "[======= ]",
  484. "[===== ]", "[==== ]", "[=== ]", "[== ]",
  485. "[= ]", "[ ]"}
  486. local char = progress_chars[animation_frame % #progress_chars + 1]
  487.  
  488. -- Status line with animation icon
  489. monitor.setCursorPos(5, 10)
  490. monitor.setTextColor(colors.yellow)
  491. monitor.write("Reactor ignition in progress")
  492.  
  493. -- Animation on separate line
  494. monitor.setCursorPos(15, 11)
  495. monitor.write(char)
  496.  
  497. monitor.setCursorPos(5, 13)
  498. monitor.setTextColor(colors.white)
  499. monitor.write("Please wait...")
  500. else
  501. -- Clear any previous UI elements in this area
  502. for y = 8, 16 do
  503. monitor.setCursorPos(3, y)
  504. monitor.setBackgroundColor(colors.black)
  505. for x = 3, screen_width - 3 do
  506. monitor.write(" ")
  507. end
  508. end
  509.  
  510. -- Draw proper button centered on screen
  511. local button_color = colors.blue
  512. if animation_frame % 8 > 5 then
  513. button_color = colors.lightBlue -- Subtle flashing animation
  514. end
  515.  
  516. -- Draw frame around button
  517. drawBox(button_x1 - 1, button_y1 - 1, button_x2 + 1, button_y2 + 1, colors.black, colors.gray)
  518.  
  519. -- Fill button with color
  520. for y = button_y1, button_y2 do
  521. monitor.setCursorPos(button_x1, y)
  522. monitor.setBackgroundColor(button_color)
  523. for x = button_x1, button_x2 do
  524. monitor.write(" ")
  525. end
  526. end
  527.  
  528. -- Button text
  529. local button_text = "START REACTOR"
  530. monitor.setTextColor(colors.white)
  531. monitor.setCursorPos(button_x1 + math.floor((button_x2 - button_x1 - #button_text) / 2), button_y1 + 1)
  532. monitor.write(button_text)
  533.  
  534. -- Reset background color
  535. monitor.setBackgroundColor(colors.black)
  536. end
  537. end
  538.  
  539. -- Footer
  540. monitor.setTextColor(colors.lightGray)
  541. monitor.setCursorPos(3, screen_height - 1)
  542. monitor.write("Fusion Reactor Controler by Le_Jiww")
  543.  
  544. -- Reset default colors
  545. monitor.setBackgroundColor(colors.black)
  546. monitor.setTextColor(colors.white)
  547.  
  548. last_ignited = ignited
  549. end
  550.  
  551. -- Function to handle button click
  552. local function checkTouch()
  553. while true do
  554. local event, side, x, y = os.pullEvent("monitor_touch")
  555.  
  556. -- Check if we're in the right state to start the reactor
  557. if not reactor.isIgnited() and not ignition_in_progress then
  558. -- Improved button hit detection with better margins
  559. if x >= button_x1 - 1 and x <= button_x2 + 1 and y >= button_y1 - 1 and y <= button_y2 + 1 then
  560. -- Set "ignition in progress" state
  561. ignition_in_progress = true
  562.  
  563. -- Log to console for debugging
  564. print("Button pressed - starting reactor ignition sequence")
  565.  
  566. -- Visual effect for the click - change button color to cyan
  567. for y_pos = button_y1, button_y2 do
  568. monitor.setCursorPos(button_x1, y_pos)
  569. monitor.setBackgroundColor(colors.cyan)
  570. for x_pos = button_x1, button_x2 do
  571. monitor.write(" ")
  572. end
  573. end
  574.  
  575. -- Button text
  576. local button_text = "STARTING..."
  577. monitor.setTextColor(colors.white)
  578. monitor.setCursorPos(button_x1 + math.floor((button_x2 - button_x1 - #button_text) / 2), button_y1 + 1)
  579. monitor.write(button_text)
  580.  
  581. sleep(0.2) -- Brief pause for visual effect
  582.  
  583. -- Send redstone pulse on the chosen face
  584. redstone.setOutput(start_side, true)
  585. sleep(redstone_pulse_time)
  586. redstone.setOutput(start_side, false)
  587.  
  588. -- Update display to show ignition sequence
  589. displayInfo()
  590. end
  591. end
  592. end
  593. end
  594.  
  595. -- Information on console about how to restart
  596. print("Monitor interface initialized")
  597. print("Reactor startup configured to send redstone signal to: " .. start_side .. " face")
  598. print("Reactor stop signals configured for: " .. alarm_side .. " and " .. alarm_side2 .. " faces")
  599. print("Touch the START REACTOR button on monitor to activate the reactor")
  600. print("Running main loop...")
  601.  
  602. -- Continuous update loop
  603. parallel.waitForAny(
  604. function()
  605. while true do
  606. displayInfo()
  607. sleep(0.25) -- Reduce delay for smoother animation
  608. end
  609. end,
  610. checkTouch
  611. )
  612.  
Add Comment
Please, Sign In to add comment